fix some bugs in linux
This commit is contained in:
parent
f60dc371db
commit
61b0e49fed
@ -18,17 +18,19 @@ def 知识库问答(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
|
|||||||
chatbot.append(("这是什么功能?", "[Local Message] 从一批文件(txt, md, tex)中读取数据构建知识库, 然后进行问答。"))
|
chatbot.append(("这是什么功能?", "[Local Message] 从一批文件(txt, md, tex)中读取数据构建知识库, 然后进行问答。"))
|
||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
|
|
||||||
|
# resolve deps
|
||||||
try:
|
try:
|
||||||
import zh_langchain
|
from zh_langchain import construct_vector_store
|
||||||
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
||||||
from .crazy_utils import knowledge_archive_interface
|
from .crazy_utils import knowledge_archive_interface
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
chatbot.append(
|
chatbot.append(
|
||||||
["依赖不足",
|
["依赖不足",
|
||||||
"导入依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade langchain zh_langchain```。"]
|
"导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..."]
|
||||||
)
|
)
|
||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
return
|
from .crazy_utils import try_install_deps
|
||||||
|
try_install_deps(['zh_langchain==0.1.9'])
|
||||||
|
|
||||||
# < --------------------读取参数--------------- >
|
# < --------------------读取参数--------------- >
|
||||||
if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg")
|
if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg")
|
||||||
@ -52,7 +54,7 @@ def 知识库问答(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
|
|||||||
print('Checking Text2vec ...')
|
print('Checking Text2vec ...')
|
||||||
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
||||||
with ProxyNetworkActivate(): # 临时地激活代理网络
|
with ProxyNetworkActivate(): # 临时地激活代理网络
|
||||||
HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese", model_kwargs={'device': 'cpu'})
|
HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese")
|
||||||
|
|
||||||
# < -------------------构建知识库--------------- >
|
# < -------------------构建知识库--------------- >
|
||||||
chatbot.append(['<br/>'.join(file_manifest), "正在构建知识库..."])
|
chatbot.append(['<br/>'.join(file_manifest), "正在构建知识库..."])
|
||||||
@ -86,6 +88,7 @@ def 读取知识库作答(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
|
|||||||
resp, prompt = kai.answer_with_archive_by_id(txt, kai_id)
|
resp, prompt = kai.answer_with_archive_by_id(txt, kai_id)
|
||||||
|
|
||||||
chatbot.append((txt, '[Local Message] ' + prompt))
|
chatbot.append((txt, '[Local Message] ' + prompt))
|
||||||
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
|
||||||
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
||||||
inputs=prompt, inputs_show_user=txt,
|
inputs=prompt, inputs_show_user=txt,
|
||||||
llm_kwargs=llm_kwargs, chatbot=chatbot, history=[],
|
llm_kwargs=llm_kwargs, chatbot=chatbot, history=[],
|
||||||
|
@ -638,7 +638,7 @@ class knowledge_archive_interface():
|
|||||||
print('Checking Text2vec ...')
|
print('Checking Text2vec ...')
|
||||||
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
||||||
with ProxyNetworkActivate(): # 临时地激活代理网络
|
with ProxyNetworkActivate(): # 临时地激活代理网络
|
||||||
self.text2vec_large_chinese = HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese", model_kwargs={'device': 'cpu'})
|
self.text2vec_large_chinese = HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese")
|
||||||
|
|
||||||
return self.text2vec_large_chinese
|
return self.text2vec_large_chinese
|
||||||
|
|
||||||
@ -694,3 +694,7 @@ class knowledge_archive_interface():
|
|||||||
self.threadLock.release()
|
self.threadLock.release()
|
||||||
return resp, prompt
|
return resp, prompt
|
||||||
|
|
||||||
|
def try_install_deps(deps):
|
||||||
|
for dep in deps:
|
||||||
|
import subprocess, sys
|
||||||
|
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', dep])
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
./docs/gradio-3.32.2-py3-none-any.whl
|
./docs/gradio-3.32.2-py3-none-any.whl
|
||||||
zh_langchain==0.1.6
|
|
||||||
tiktoken>=0.3.3
|
tiktoken>=0.3.3
|
||||||
requests[socks]
|
requests[socks]
|
||||||
transformers
|
transformers
|
||||||
|
@ -783,8 +783,9 @@ class ProxyNetworkActivate():
|
|||||||
from toolbox import get_conf
|
from toolbox import get_conf
|
||||||
proxies, = get_conf('proxies')
|
proxies, = get_conf('proxies')
|
||||||
if 'no_proxy' in os.environ: os.environ.pop('no_proxy')
|
if 'no_proxy' in os.environ: os.environ.pop('no_proxy')
|
||||||
os.environ['HTTP_PROXY'] = proxies['http']
|
if proxies is not None:
|
||||||
os.environ['HTTPS_PROXY'] = proxies['https']
|
if 'http' in proxies: os.environ['HTTP_PROXY'] = proxies['http']
|
||||||
|
if 'https' in proxies: os.environ['HTTPS_PROXY'] = proxies['https']
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user