From c914268340835bc3d9c078c451d28e72d927e789 Mon Sep 17 00:00:00 2001 From: suyunsen Date: Tue, 31 Oct 2023 19:17:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=B0=81=E8=A3=85chatGLM?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1=E5=9E=8B=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=94=BF=E5=8A=A1=E9=97=AE=E7=AD=94=E7=9A=84gradio?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Custom/ChatGLM.py | 2 +- QAtest.py | 27 ++++++++++++++++++--------- WEBQA.py | 10 ++++++---- Web_UI/goverment_UI/gradio_webui.py | 19 ++++++++++--------- templates/index.html | 2 +- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Custom/ChatGLM.py b/Custom/ChatGLM.py index a75f2d5..4ba905b 100644 --- a/Custom/ChatGLM.py +++ b/Custom/ChatGLM.py @@ -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 diff --git a/QAtest.py b/QAtest.py index 85e5120..a96eb22 100644 --- a/QAtest.py +++ b/QAtest.py @@ -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) diff --git a/WEBQA.py b/WEBQA.py index f82bd4b..a36511b 100644 --- a/WEBQA.py +++ b/WEBQA.py @@ -15,12 +15,14 @@ his = {} templet_prompt = """ - 假如你是一名语文专家,你需要根据一下给出的内容找出问题的正确答案。 + 假如你是一名问答专家,你需要根据一下给出的内容找出问题的正确答案。 答案只存在给出的内容中,你知道就回答,不要自己编造答案。 - 因为你是语文专家你需要仔细分析问题和给出的内容,不要给出错误答案。 + 因为你是问答专家你需要仔细分析问题和给出的内容,不要给出错误答案,不要给出多余的答案。 + 记住你只需要按给出的内容作答,不需要自己总结。 + 如果你认为给出的问题和给出的内容相关性不大,你需要回复:请详细说明您咨询问题的地址和办理的事项,如...。 这是给出的内容:{context} 问题是:{question} - """ + """ govermentQa = GoQa(templet_prompt=templet_prompt) @app.route('/') @@ -42,4 +44,4 @@ def index(): if __name__ == '__main__': history = [] - app.run(host='0.0.0.0',port=8080) \ No newline at end of file + app.run(host='0.0.0.0',port=7580) \ No newline at end of file diff --git a/Web_UI/goverment_UI/gradio_webui.py b/Web_UI/goverment_UI/gradio_webui.py index 30533c5..e2b0123 100644 --- a/Web_UI/goverment_UI/gradio_webui.py +++ b/Web_UI/goverment_UI/gradio_webui.py @@ -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) @@ -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" diff --git a/templates/index.html b/templates/index.html index 50b3ba1..25773df 100644 --- a/templates/index.html +++ b/templates/index.html @@ -89,7 +89,7 @@

政务问答机器人:+___+

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)