Enhance the robustness of the code (#1879)
Browse files### What problem does this PR solve?
Enhance the robustness of the code
### Type of change
- [x] Refactoring
---------
Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
- api/apps/llm_app.py +1 -1
- rag/llm/chat_model.py +1 -1
api/apps/llm_app.py
CHANGED
|
@@ -132,7 +132,7 @@ def add_llm():
|
|
| 132 |
api_key = "xxxxxxxxxxxxxxx"
|
| 133 |
elif factory == "OpenAI-API-Compatible":
|
| 134 |
llm_name = req["llm_name"]+"___OpenAI-API"
|
| 135 |
-
api_key = req
|
| 136 |
else:
|
| 137 |
llm_name = req["llm_name"]
|
| 138 |
api_key = "xxxxxxxxxxxxxxx"
|
|
|
|
| 132 |
api_key = "xxxxxxxxxxxxxxx"
|
| 133 |
elif factory == "OpenAI-API-Compatible":
|
| 134 |
llm_name = req["llm_name"]+"___OpenAI-API"
|
| 135 |
+
api_key = req.get("api_key","xxxxxxxxxxxxxxx")
|
| 136 |
else:
|
| 137 |
llm_name = req["llm_name"]
|
| 138 |
api_key = "xxxxxxxxxxxxxxx"
|
rag/llm/chat_model.py
CHANGED
|
@@ -72,7 +72,7 @@ class Base(ABC):
|
|
| 72 |
+ num_tokens_from_string(resp.choices[0].delta.content)
|
| 73 |
)
|
| 74 |
if not hasattr(resp, "usage") or not resp.usage
|
| 75 |
-
else resp.usage
|
| 76 |
)
|
| 77 |
if resp.choices[0].finish_reason == "length":
|
| 78 |
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|
|
|
|
| 72 |
+ num_tokens_from_string(resp.choices[0].delta.content)
|
| 73 |
)
|
| 74 |
if not hasattr(resp, "usage") or not resp.usage
|
| 75 |
+
else resp.usage.get("total_tokens",total_tokens)
|
| 76 |
)
|
| 77 |
if resp.choices[0].finish_reason == "length":
|
| 78 |
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|