From f86826b7a04659d9c01277bcf3d77ed38d505e31 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Tue, 29 Oct 2024 10:08:08 +0800 Subject: [PATCH] refactor error message of qwen (#3074) ### What problem does this PR solve? #3055 ### Type of change - [x] Refactoring --- rag/app/qa.py | 5 +++-- rag/llm/chat_model.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rag/app/qa.py b/rag/app/qa.py index fba0300a0..1f2aa3056 100644 --- a/rag/app/qa.py +++ b/rag/app/qa.py @@ -315,6 +315,7 @@ def chunk(filename, binary=None, lang="Chinese", callback=None, **kwargs): for q, a in excel_parser(filename, binary, callback): res.append(beAdoc(deepcopy(doc), q, a, eng)) return res + elif re.search(r"\.(txt|csv)$", filename, re.IGNORECASE): callback(0.1, "Start to parse.") txt = get_text(filename, binary) @@ -348,16 +349,16 @@ def chunk(filename, binary=None, lang="Chinese", callback=None, **kwargs): f"{len(fails)} failure, line: %s..." % (",".join(fails[:3])) if fails else ""))) return res + elif re.search(r"\.pdf$", filename, re.IGNORECASE): callback(0.1, "Start to parse.") pdf_parser = Pdf() qai_list, tbls = pdf_parser(filename if not binary else binary, from_page=0, to_page=10000, callback=callback) - - for q, a, image, poss in qai_list: res.append(beAdocPdf(deepcopy(doc), q, a, eng, image, poss)) return res + elif re.search(r"\.(md|markdown)$", filename, re.IGNORECASE): callback(0.1, "Start to parse.") txt = get_text(filename, binary) diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index 8e9dd8924..b9b0fa812 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import re + from openai.lib.azure import AzureOpenAI from zhipuai import ZhipuAI from dashscope import Generation @@ -275,8 +277,7 @@ class QWenChat(Base): [ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?" yield ans else: - yield ans + "\n**ERROR**: " + resp.message if str(resp.message).find( - "Access") < 0 else "Out of credit. Please set the API key in **settings > Model providers.**" + yield ans + "\n**ERROR**: " + resp.message if not re.search(r" (key|quota)", str(resp.message).lower()) else "Out of credit. Please set the API key in **settings > Model providers.**" except Exception as e: yield ans + "\n**ERROR**: " + str(e)