1- from toolbox import CatchException , update_ui , ProxyNetworkActivate
1+ from toolbox import CatchException , update_ui , ProxyNetworkActivate , update_ui_lastest_msg
22from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive , get_files_from_everything
33
44
@@ -15,7 +15,12 @@ def 知识库问答(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
1515 web_port 当前软件运行的端口号
1616 """
1717 history = [] # 清空历史,以免输入溢出
18- chatbot .append (("这是什么功能?" , "[Local Message] 从一批文件(txt, md, tex)中读取数据构建知识库, 然后进行问答。" ))
18+
19+ # < --------------------读取参数--------------- >
20+ if ("advanced_arg" in plugin_kwargs ) and (plugin_kwargs ["advanced_arg" ] == "" ): plugin_kwargs .pop ("advanced_arg" )
21+ kai_id = plugin_kwargs .get ("advanced_arg" , 'default' )
22+
23+ chatbot .append ((f"向`{ kai_id } `知识库中添加文件。" , "[Local Message] 从一批文件(txt, md, tex)中读取数据构建知识库, 然后进行问答。" ))
1924 yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面
2025
2126 # resolve deps
@@ -24,17 +29,12 @@ def 知识库问答(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
2429 from langchain .embeddings .huggingface import HuggingFaceEmbeddings
2530 from .crazy_utils import knowledge_archive_interface
2631 except Exception as e :
27- chatbot .append (
28- ["依赖不足" ,
29- "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..." ]
30- )
32+ chatbot .append (["依赖不足" , "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..." ])
3133 yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面
3234 from .crazy_utils import try_install_deps
33- try_install_deps (['zh_langchain==0.2.1' , 'pypinyin' ])
34-
35- # < --------------------读取参数--------------- >
36- if ("advanced_arg" in plugin_kwargs ) and (plugin_kwargs ["advanced_arg" ] == "" ): plugin_kwargs .pop ("advanced_arg" )
37- kai_id = plugin_kwargs .get ("advanced_arg" , 'default' )
35+ try_install_deps (['zh_langchain==0.2.1' , 'pypinyin' ], reload_m = ['pypinyin' , 'zh_langchain' ])
36+ yield from update_ui_lastest_msg ("安装完成,您可以再次重试。" , chatbot , history )
37+ return
3838
3939 # < --------------------读取文件--------------- >
4040 file_manifest = []
@@ -84,19 +84,18 @@ def 读取知识库作答(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
8484 chatbot .append (["依赖不足" , "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..." ])
8585 yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面
8686 from .crazy_utils import try_install_deps
87- try_install_deps (['zh_langchain==0.2.1' ])
87+ try_install_deps (['zh_langchain==0.2.1' , 'pypinyin' ], reload_m = ['pypinyin' , 'zh_langchain' ])
88+ yield from update_ui_lastest_msg ("安装完成,您可以再次重试。" , chatbot , history )
89+ return
8890
8991 # < ------------------- --------------- >
9092 kai = knowledge_archive_interface ()
9193
92- if 'langchain_plugin_embedding' in chatbot ._cookies :
93- resp , prompt = kai .answer_with_archive_by_id (txt , chatbot ._cookies ['langchain_plugin_embedding' ])
94- else :
95- if ("advanced_arg" in plugin_kwargs ) and (plugin_kwargs ["advanced_arg" ] == "" ): plugin_kwargs .pop ("advanced_arg" )
96- kai_id = plugin_kwargs .get ("advanced_arg" , 'default' )
97- resp , prompt = kai .answer_with_archive_by_id (txt , kai_id )
94+ if ("advanced_arg" in plugin_kwargs ) and (plugin_kwargs ["advanced_arg" ] == "" ): plugin_kwargs .pop ("advanced_arg" )
95+ kai_id = plugin_kwargs .get ("advanced_arg" , 'default' )
96+ resp , prompt = kai .answer_with_archive_by_id (txt , kai_id )
9897
99- chatbot .append ((txt , '[Local Message ] ' + prompt ))
98+ chatbot .append ((txt , f'[知识库 { kai_id } ] ' + prompt ))
10099 yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
101100 gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive (
102101 inputs = prompt , inputs_show_user = txt ,
0 commit comments