From 411c6451346ec884cb8d56f384d8b5f43b20b400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=85=BE?= <101850389+hangters@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:18:08 +0800 Subject: [PATCH] Enhance the robustness of the code (#1879) ### What problem does this PR solve? Enhance the robustness of the code ### Type of change - [x] Refactoring --------- Co-authored-by: Zhedong Cen --- api/apps/llm_app.py | 2 +- rag/llm/chat_model.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/apps/llm_app.py b/api/apps/llm_app.py index c29a220cb..1d54550ff 100644 --- a/api/apps/llm_app.py +++ b/api/apps/llm_app.py @@ -132,7 +132,7 @@ def add_llm(): api_key = "xxxxxxxxxxxxxxx" elif factory == "OpenAI-API-Compatible": llm_name = req["llm_name"]+"___OpenAI-API" - api_key = req["api_key"] + api_key = req.get("api_key","xxxxxxxxxxxxxxx") else: llm_name = req["llm_name"] api_key = "xxxxxxxxxxxxxxx" diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index f59c4785f..04463e931 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -72,7 +72,7 @@ class Base(ABC): + num_tokens_from_string(resp.choices[0].delta.content) ) if not hasattr(resp, "usage") or not resp.usage - else resp.usage["total_tokens"] + else resp.usage.get("total_tokens",total_tokens) ) if resp.choices[0].finish_reason == "length": ans += "...\nFor the content length reason, it stopped, continue?" if is_english(