quincyqiang commited on
Commit
96a6f43
1 Parent(s): 3f33566
cache/index.faiss ADDED
Binary file (53.3 kB). View file
 
cache/index.pkl ADDED
Binary file (5.43 kB). View file
 
clc/__pycache__/__init__.cpython-39.pyc ADDED
Binary file (308 Bytes). View file
 
clc/__pycache__/gpt_service.cpython-39.pyc ADDED
Binary file (1.95 kB). View file
 
clc/__pycache__/langchain_application.cpython-39.pyc ADDED
Binary file (2.26 kB). View file
 
clc/__pycache__/source_service.cpython-39.pyc ADDED
Binary file (1.91 kB). View file
 
clc/gpt_service.py CHANGED
@@ -53,15 +53,10 @@ class ChatGLMService(LLM):
53
  model_name_or_path,
54
  trust_remote_code=True
55
  )
56
- self.model = (
57
- AutoModel.from_pretrained(
58
- model_name_or_path,
59
- trust_remote_code=True)
60
- .half()
61
- .cuda()
62
- )
63
-
64
  # if __name__ == '__main__':
65
  # config=LangChainCFG()
66
  # chatLLM = ChatGLMService()
67
  # chatLLM.load_model(model_name_or_path=config.llm_model_name)
 
 
53
  model_name_or_path,
54
  trust_remote_code=True
55
  )
56
+ self.model = AutoModel.from_pretrained(model_name_or_path, trust_remote_code=True).half().cuda()
57
+ self.model=self.model.eval()
 
 
 
 
 
 
58
  # if __name__ == '__main__':
59
  # config=LangChainCFG()
60
  # chatLLM = ChatGLMService()
61
  # chatLLM.load_model(model_name_or_path=config.llm_model_name)
62
+
main.py CHANGED
@@ -1,15 +1,3 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 _*-
3
- """
4
- @author:quincy qiang
5
- @license: Apache Licence
6
- @file: main.py
7
- @time: 2023/04/17
8
- @contact: [email protected]
9
- @software: PyCharm
10
- @description: coding..
11
- """
12
-
13
  import os
14
  import shutil
15
 
@@ -17,11 +5,13 @@ import gradio as gr
17
 
18
  from clc.langchain_application import LangChainApplication
19
 
 
 
20
 
21
  # 修改成自己的配置!!!
22
  class LangChainCFG:
23
- llm_model_name = '../../pretrained_models/chatglm-6b' # 本地模型文件 or huggingface远程仓库
24
- embedding_model_name = '../../pretrained_models/text2vec-large-chinese' # 检索模型文件 or huggingface远程仓库
25
  vector_store_path = './cache'
26
  docs_path = './docs'
27
 
@@ -58,22 +48,23 @@ def predict(input,
58
  large_language_model,
59
  embedding_model,
60
  history=None):
61
- print(large_language_model, embedding_model)
 
62
  if history == None:
63
  history = []
64
  resp = application.get_knowledge_based_answer(
65
  query=input,
66
- history_len=5,
67
  temperature=0.1,
68
  top_p=0.9,
69
  chat_history=history
70
  )
71
- print(resp)
72
  history.append((input, resp['result']))
73
-
74
  search_text = ''
75
  for idx, source in enumerate(resp['source_documents'][:2]):
76
- search_text += f'【搜索结果{idx}:】{source.page_content}\n\n'
 
 
77
  return '', history, history, search_text
78
 
79
 
@@ -83,6 +74,8 @@ with block as demo:
83
  <center><font size=3>
84
  </center></font>
85
  """)
 
 
86
  with gr.Row():
87
  with gr.Column(scale=1):
88
  embedding_model = gr.Dropdown([
@@ -112,7 +105,6 @@ with block as demo:
112
  inputs=file,
113
  outputs=selectFile)
114
  with gr.Column(scale=4):
115
- state = gr.State()
116
  with gr.Row():
117
  with gr.Column(scale=4):
118
  chatbot = gr.Chatbot(label='Chinese-LangChain').style(height=400)
@@ -122,26 +114,27 @@ with block as demo:
122
  send = gr.Button("🚀 发送")
123
  with gr.Column(scale=2):
124
  search = gr.Textbox(label='搜索结果')
125
- # 发送按钮 提交
126
- send.click(predict,
127
- inputs=[
128
- message, large_language_model,
129
- embedding_model, state
130
- ],
131
- outputs=[message, chatbot, state, search])
132
-
133
- # 清空历史对话按钮 提交
134
- clear_history.click(fn=clear_session,
135
- inputs=[],
136
- outputs=[chatbot, state],
137
- queue=False)
138
-
139
- # 输入框 回车
140
- message.submit(predict,
141
- inputs=[
142
- message, large_language_model,
143
- embedding_model, state
144
- ],
145
- outputs=[message, chatbot, state, search])
146
-
147
- demo.queue().launch(server_name='0.0.0.0', server_port=8008, share=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import shutil
3
 
 
5
 
6
  from clc.langchain_application import LangChainApplication
7
 
8
+ os.environ["CUDA_VISIBLE_DEVICES"] = '0'
9
+
10
 
11
  # 修改成自己的配置!!!
12
  class LangChainCFG:
13
+ llm_model_name = 'THUDM/chatglm-6b-int4-qe' # 本地模型文件 or huggingface远程仓库
14
+ embedding_model_name = 'GanymedeNil/text2vec-large-chinese' # 检索模型文件 or huggingface远程仓库
15
  vector_store_path = './cache'
16
  docs_path = './docs'
17
 
 
48
  large_language_model,
49
  embedding_model,
50
  history=None):
51
+ # print(large_language_model, embedding_model)
52
+ print(input)
53
  if history == None:
54
  history = []
55
  resp = application.get_knowledge_based_answer(
56
  query=input,
57
+ history_len=1,
58
  temperature=0.1,
59
  top_p=0.9,
60
  chat_history=history
61
  )
 
62
  history.append((input, resp['result']))
 
63
  search_text = ''
64
  for idx, source in enumerate(resp['source_documents'][:2]):
65
+ sep = f'----------【搜索结果{idx}:】---------------\n'
66
+ search_text += f'{sep}\n{source.page_content}\n\n'
67
+ print(search_text)
68
  return '', history, history, search_text
69
 
70
 
 
74
  <center><font size=3>
75
  </center></font>
76
  """)
77
+ state = gr.State()
78
+
79
  with gr.Row():
80
  with gr.Column(scale=1):
81
  embedding_model = gr.Dropdown([
 
105
  inputs=file,
106
  outputs=selectFile)
107
  with gr.Column(scale=4):
 
108
  with gr.Row():
109
  with gr.Column(scale=4):
110
  chatbot = gr.Chatbot(label='Chinese-LangChain').style(height=400)
 
114
  send = gr.Button("🚀 发送")
115
  with gr.Column(scale=2):
116
  search = gr.Textbox(label='搜索结果')
117
+
118
+ # 发送按钮 提交
119
+ send.click(predict,
120
+ inputs=[
121
+ message, large_language_model,
122
+ embedding_model, state
123
+ ],
124
+ outputs=[message, chatbot, state, search])
125
+
126
+ # 清空历史对话按钮 提交
127
+ clear_history.click(fn=clear_session,
128
+ inputs=[],
129
+ outputs=[chatbot, state],
130
+ queue=False)
131
+
132
+ # 输入框 回车
133
+ message.submit(predict,
134
+ inputs=[
135
+ message, large_language_model,
136
+ embedding_model, state
137
+ ],
138
+ outputs=[message, chatbot, state, search])
139
+
140
+ demo.queue(concurrency_count=2).launch(server_name='0.0.0.0', server_port=8888, share=False,show_error=True, enable_queue=True)
tests/test_duckduckgo_search.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from duckduckgo_search import ddg
2
+ from duckduckgo_search.utils import SESSION
3
+
4
+
5
+ SESSION.proxies = {
6
+ "http": f"socks5h://localhost:7890",
7
+ "https": f"socks5h://localhost:7890"
8
+ }
9
+ r = ddg("马保国")
10
+ print(r)
tests/test_duckpy.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from duckpy import Client
2
+
3
+ client = Client()
4
+
5
+ results = client.search("Python Wikipedia")
6
+
7
+ # Prints first result title
8
+ print(results[0].title)
9
+
10
+ # Prints first result URL
11
+ print(results[0].url)
12
+
13
+ # Prints first result description
14
+ print(results[0].description)
15
+ # https://github.com/AmanoTeam/duckpy
tests/test_gradio_slient.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+
3
+ import gradio as gra
4
+
5
+
6
+ def user_greeting(name):
7
+ time.sleep(10)
8
+ return "Hi! " + name + " Welcome to your first Gradio application!😎"
9
+
10
+
11
+ # define gradio interface and other parameters
12
+ app = gra.Interface(
13
+ fn=user_greeting,
14
+ inputs="text",
15
+ outputs="text",
16
+ )
17
+ app.launch(
18
+ server_name='0.0.0.0', server_port=8888, share=False,show_error=True, enable_queue=True
19
+ )