Skip to content

Commit

Permalink
重新封装chatGLM自定义模型,更新政务问答的gradio界面
Browse files Browse the repository at this point in the history
  • Loading branch information
suyunsen committed Oct 31, 2023
1 parent 750c2fe commit c914268
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Custom/ChatGLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _call(
elif stop is None:
stop = []
# print(prompt)
print('------------------------------')
print('------------ChatGLM------------------')
response, history = self.exemodel.chat(self.extokenizer, prompt, history=self.history,temperature=self.temperature)
self.history = []
return response
27 changes: 18 additions & 9 deletions QAtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@

def chatGLM():
q = '广东省的企业职工基本养老金网上如何申请。'
# q = "请问给出的内容有几个网办流程"

# q = "怎么办理沙坑社区城镇非职工居民独生子女保健费发放"
# q = "怎么办理沙坑社区城镇非职工居民独生子女保健费发放问题"
# q = "怎么办理沙坑社区申领居住证"
# templet_prompt = """
# 假如你是一名问答专家,你需要根据一下给出的内容找出问题的正确答案。
# 答案只存在给出的内容中,你知道就回答,不要自己编造答案。
# 这是给出的内容:{context}
# 问题是:{question}
# 因为你是问答专家你需要仔细分析问题和给出的内容,不要给出多余的答案。
# 按给出的内容作答,你不需要自己总结。
# """
templet_prompt = """
假如你是一名语文专家,你需要根据一下给出的内容找出问题的正确答案。
答案只存在给出的内容中,你知道就回答,不要自己编造答案。
这是给出的内容:{context}
问题是:{question}
因为你是语文专家你需要仔细分析问题和给出的内容,不要给出多余的答案。
按给出的内容作答,你不需要自己总结。
"""
假如你是一名问答专家,你需要根据一下给出的内容找出问题的正确答案。
答案只存在给出的内容中,你知道就回答,不要自己编造答案。
因为你是问答专家你需要仔细分析问题和给出的内容,不要给出错误答案,不要给出多余的答案。
记住你只需要按给出的内容作答,不需要自己总结。
这是给出的内容:{context}
问题是:{question}
"""
govermentQa = GoQa(templet_prompt=templet_prompt)
qs = []
qs.append(q)
Expand Down
10 changes: 6 additions & 4 deletions WEBQA.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
his = {}

templet_prompt = """
假如你是一名语文专家,你需要根据一下给出的内容找出问题的正确答案。
假如你是一名问答专家,你需要根据一下给出的内容找出问题的正确答案。
答案只存在给出的内容中,你知道就回答,不要自己编造答案。
因为你是语文专家你需要仔细分析问题和给出的内容,不要给出错误答案。
因为你是问答专家你需要仔细分析问题和给出的内容,不要给出错误答案,不要给出多余的答案。
记住你只需要按给出的内容作答,不需要自己总结。
如果你认为给出的问题和给出的内容相关性不大,你需要回复:请详细说明您咨询问题的地址和办理的事项,如...。
这是给出的内容:{context}
问题是:{question}
"""
"""
govermentQa = GoQa(templet_prompt=templet_prompt)

@app.route('/')
Expand All @@ -42,4 +44,4 @@ def index():

if __name__ == '__main__':
history = []
app.run(host='0.0.0.0',port=8080)
app.run(host='0.0.0.0',port=7580)
19 changes: 10 additions & 9 deletions Web_UI/goverment_UI/gradio_webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
cmd_opts = parser.parse_args()

templet_prompt = """
假如你是一名语文专家,你需要根据一下给出的内容找出问题的正确答案。
答案只存在给出的内容中,你知道就回答,不要自己编造答案。
这是给出的内容:{context}
问题是:{question}
因为你是语文专家你需要仔细分析问题和给出的内容,不要给出多余的答案。
按给出的内容作答,你不需要自己总结。
"""
假如你是一名问答专家,你需要根据一下给出的内容找出问题的正确答案。
答案只存在给出的内容中,你知道就回答,不要自己编造答案。
因为你是问答专家你需要仔细分析问题和给出的内容,不要给出错误答案,不要给出多余的答案。
记住你只需要按给出的内容作答,不需要自己总结。
记住如果你认为问题和给出的内容相关性不大,你需要回复:请详细说明您咨询问题的地址和办理的事项。
以下是给出的内容:{context}
问题是:{question}
"""
llm = ChatGlm26b()
sparkllm:Optional[Spark] = None
qa_chain = GoQa(llm=llm,templet_prompt=templet_prompt)
Expand Down Expand Up @@ -92,8 +93,8 @@ def predict(query, max_length, top_p, temperature):


def save_history():
if not os.path.exists("outputs"):
os.mkdir("outputs")
if not os.path.exists("./outputs"):
os.mkdir("./outputs")

s = [{"q": i[0], "o": i[1]} for i in history]
filename = f"save-{int(time.time())}.json"
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h1>政务问答机器人:+___+</h1>
chatBox.appendChild(userMessageElement);

// 使用fetch发送GET请求到后端
fetch(`http://localhost:8080/process_chat?chat=${encodeURIComponent(messageText)}`)
fetch(`http://10.130.71.10:30892/process_chat?chat=${encodeURIComponent(messageText)}`)
.then(response => response.text())
.then(data => {
// 显示后端返回的响应消息(使用Markdown转换为HTML)
Expand Down

0 comments on commit c914268

Please sign in to comment.