命令行助手.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. from toolbox import CatchException, update_ui, gen_time_str
  2. from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
  3. from .crazy_utils import input_clipping
  4. import copy, json
  5. @CatchException
  6. def 命令行助手(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
  7. """
  8. txt 输入栏用户输入的文本, 例如需要翻译的一段话, 再例如一个包含了待处理文件的路径
  9. llm_kwargs gpt模型参数, 如温度和top_p等, 一般原样传递下去就行
  10. plugin_kwargs 插件模型的参数, 暂时没有用武之地
  11. chatbot 聊天显示框的句柄, 用于显示给用户
  12. history 聊天历史, 前情提要
  13. system_prompt 给gpt的静默提醒
  14. web_port 当前软件运行的端口号
  15. """
  16. # 清空历史, 以免输入溢出
  17. history = []
  18. # 输入
  19. i_say = "请写bash命令实现以下功能:" + txt
  20. # 开始
  21. gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
  22. inputs=i_say, inputs_show_user=txt,
  23. llm_kwargs=llm_kwargs, chatbot=chatbot, history=[],
  24. sys_prompt="你是一个Linux大师级用户。注意,当我要求你写bash命令时,尽可能地仅用一行命令解决我的要求。"
  25. )
  26. yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新