From 653c759d8d4e1c410a78a5380f28afefcf34dfab Mon Sep 17 00:00:00 2001 From: KevinHuSh Date: Tue, 9 Apr 2024 16:16:10 +0800 Subject: [PATCH] resolve issure to call ZH?IPUAI (#277) ### What problem does this PR solve? Issue link:#265 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/conversation_app.py | 5 ++++- rag/llm/chat_model.py | 1 + rag/nlp/query.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/apps/conversation_app.py b/api/apps/conversation_app.py index 6ece253c..2379d30b 100644 --- a/api/apps/conversation_app.py +++ b/api/apps/conversation_app.py @@ -360,7 +360,10 @@ def use_sql(question, field_map, tenant_id, chat_mdl): "|" for r in tbl["rows"]] if not docid_idx or not docnm_idx: chat_logger.warning("SQL missing field: " + sql) - return "\n".join([clmns, line, "\n".join(rows)]), [] + return { + "answer": "\n".join([clmns, line, rows]), + "reference": {"chunks": [], "doc_aggs": []} + } rows = "\n".join([r + f" ##{ii}$$ |" for ii, r in enumerate(rows)]) rows = re.sub(r"T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+Z)?\|", "|", rows) diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index 98f6ce64..498595de 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -117,6 +117,7 @@ class ZhipuChat(Base): history.insert(0, {"role": "system", "content": system}) try: if "presence_penalty" in gen_conf: del gen_conf["presence_penalty"] + if "frequency_penalty" in gen_conf: del gen_conf["frequency_penalty"] response = self.client.chat.completions.create( model=self.model_name, messages=history, diff --git a/rag/nlp/query.py b/rag/nlp/query.py index 26753d72..e62fb9fb 100644 --- a/rag/nlp/query.py +++ b/rag/nlp/query.py @@ -35,7 +35,7 @@ class EsQueryer: @staticmethod def rmWWW(txt): patts = [ - (r"是*(什么样的|哪家|那家|啥样|咋样了|什么时候|何时|何地|何人|是否|是不是|多少|哪里|怎么|哪儿|怎么样|如何|哪些|是啥|啥是|啊|吗|呢|吧|咋|什么|有没有|呀)是*", ""), + (r"是*(什么样的|哪家|一下|那家|啥样|咋样了|什么时候|何时|何地|何人|是否|是不是|多少|哪里|怎么|哪儿|怎么样|如何|哪些|是啥|啥是|啊|吗|呢|吧|咋|什么|有没有|呀)是*", ""), (r"(^| )(what|who|how|which|where|why)('re|'s)? ", " "), (r"(^| )('s|'re|is|are|were|was|do|does|did|don't|doesn't|didn't|has|have|be|there|you|me|your|my|mine|just|please|may|i|should|would|wouldn't|will|won't|done|go|for|with|so|the|a|an|by|i'm|it's|he's|she's|they|they're|you're|as|by|on|in|at|up|out|down)", " ") ]