1
- from toolbox import CatchException , update_ui , ProxyNetworkActivate
1
+ from toolbox import CatchException , update_ui , ProxyNetworkActivate , update_ui_lastest_msg
2
2
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive , get_files_from_everything
3
3
4
4
@@ -15,7 +15,12 @@ def 知识库问答(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
15
15
web_port 当前软件运行的端口号
16
16
"""
17
17
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)中读取数据构建知识库, 然后进行问答。" ))
19
24
yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面
20
25
21
26
# resolve deps
@@ -24,17 +29,12 @@ def 知识库问答(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
24
29
from langchain .embeddings .huggingface import HuggingFaceEmbeddings
25
30
from .crazy_utils import knowledge_archive_interface
26
31
except Exception as e :
27
- chatbot .append (
28
- ["依赖不足" ,
29
- "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..." ]
30
- )
32
+ chatbot .append (["依赖不足" , "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..." ])
31
33
yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面
32
34
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
38
38
39
39
# < --------------------读取文件--------------- >
40
40
file_manifest = []
@@ -84,19 +84,18 @@ def 读取知识库作答(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
84
84
chatbot .append (["依赖不足" , "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..." ])
85
85
yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面
86
86
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
88
90
89
91
# < ------------------- --------------- >
90
92
kai = knowledge_archive_interface ()
91
93
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 )
98
97
99
- chatbot .append ((txt , '[Local Message ] ' + prompt ))
98
+ chatbot .append ((txt , f'[知识库 { kai_id } ] ' + prompt ))
100
99
yield from update_ui (chatbot = chatbot , history = history ) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
101
100
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive (
102
101
inputs = prompt , inputs_show_user = txt ,
0 commit comments