辅助功能.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # encoding: utf-8
  2. # @Time : 2023/4/19
  3. # @Author : Spike
  4. # @Descr :
  5. from toolbox import update_ui, get_conf, get_user
  6. from toolbox import CatchException
  7. from toolbox import default_user_name
  8. from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
  9. import shutil
  10. import os
  11. @CatchException
  12. def 猜你想问(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
  13. if txt:
  14. show_say = txt
  15. prompt = txt+'\n回答完问题后,再列出用户可能提出的三个问题。'
  16. else:
  17. prompt = history[-1]+"\n分析上述回答,再列出用户可能提出的三个问题。"
  18. show_say = '分析上述回答,再列出用户可能提出的三个问题。'
  19. gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
  20. inputs=prompt,
  21. inputs_show_user=show_say,
  22. llm_kwargs=llm_kwargs,
  23. chatbot=chatbot,
  24. history=history,
  25. sys_prompt=system_prompt
  26. )
  27. chatbot[-1] = (show_say, gpt_say)
  28. history.extend([show_say, gpt_say])
  29. yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
  30. @CatchException
  31. def 清除缓存(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
  32. chatbot.append(['清除本地缓存数据', '执行中. 删除数据'])
  33. yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
  34. def _get_log_folder(user=default_user_name):
  35. PATH_LOGGING = get_conf('PATH_LOGGING')
  36. _dir = os.path.join(PATH_LOGGING, user)
  37. if not os.path.exists(_dir): os.makedirs(_dir)
  38. return _dir
  39. def _get_upload_folder(user=default_user_name):
  40. PATH_PRIVATE_UPLOAD = get_conf('PATH_PRIVATE_UPLOAD')
  41. _dir = os.path.join(PATH_PRIVATE_UPLOAD, user)
  42. return _dir
  43. shutil.rmtree(_get_log_folder(get_user(chatbot)), ignore_errors=True)
  44. shutil.rmtree(_get_upload_folder(get_user(chatbot)), ignore_errors=True)
  45. chatbot.append(['清除本地缓存数据', '执行完成'])
  46. yield from update_ui(chatbot=chatbot, history=history) # 刷新界面