黄腾 aopstudio commited on
Commit
4d11778
·
1 Parent(s): 4b207a6

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 <[email protected]>

Files changed (2) hide show
  1. api/apps/llm_app.py +1 -1
  2. 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["api_key"]
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["total_tokens"]
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(