询问多个大语言模型.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from toolbox import CatchException, update_ui, get_conf
  2. from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
  3. import datetime
  4. @CatchException
  5. def 同时问询(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
  6. """
  7. txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径
  8. llm_kwargs gpt模型参数,如温度和top_p等,一般原样传递下去就行
  9. plugin_kwargs 插件模型的参数,用于灵活调整复杂功能的各种参数
  10. chatbot 聊天显示框的句柄,用于显示给用户
  11. history 聊天历史,前情提要
  12. system_prompt 给gpt的静默提醒
  13. web_port 当前软件运行的端口号
  14. """
  15. history = [] # 清空历史,以免输入溢出
  16. MULTI_QUERY_LLM_MODELS = get_conf('MULTI_QUERY_LLM_MODELS')
  17. chatbot.append((txt, "正在同时咨询" + MULTI_QUERY_LLM_MODELS))
  18. yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
  19. # llm_kwargs['llm_model'] = 'chatglm&gpt-3.5-turbo&api2d-gpt-3.5-turbo' # 支持任意数量的llm接口,用&符号分隔
  20. llm_kwargs['llm_model'] = MULTI_QUERY_LLM_MODELS # 支持任意数量的llm接口,用&符号分隔
  21. gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
  22. inputs=txt, inputs_show_user=txt,
  23. llm_kwargs=llm_kwargs, chatbot=chatbot, history=history,
  24. sys_prompt=system_prompt,
  25. retry_times_at_unknown_error=0
  26. )
  27. history.append(txt)
  28. history.append(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. """
  33. txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径
  34. llm_kwargs gpt模型参数,如温度和top_p等,一般原样传递下去就行
  35. plugin_kwargs 插件模型的参数,用于灵活调整复杂功能的各种参数
  36. chatbot 聊天显示框的句柄,用于显示给用户
  37. history 聊天历史,前情提要
  38. system_prompt 给gpt的静默提醒
  39. web_port 当前软件运行的端口号
  40. """
  41. history = [] # 清空历史,以免输入溢出
  42. if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg")
  43. # llm_kwargs['llm_model'] = 'chatglm&gpt-3.5-turbo&api2d-gpt-3.5-turbo' # 支持任意数量的llm接口,用&符号分隔
  44. llm_kwargs['llm_model'] = plugin_kwargs.get("advanced_arg", 'chatglm&gpt-3.5-turbo') # 'chatglm&gpt-3.5-turbo' # 支持任意数量的llm接口,用&符号分隔
  45. chatbot.append((txt, f"正在同时咨询{llm_kwargs['llm_model']}"))
  46. yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
  47. gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
  48. inputs=txt, inputs_show_user=txt,
  49. llm_kwargs=llm_kwargs, chatbot=chatbot, history=history,
  50. sys_prompt=system_prompt,
  51. retry_times_at_unknown_error=0
  52. )
  53. history.append(txt)
  54. history.append(gpt_say)
  55. yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新