Skip to content

Commit 6e59ef3

Browse files
committed
fix(llm_api_default.py, config.py): fix a bug that prevented the use of certain models and modified the naming of config parameters.
1 parent 09ea1bb commit 6e59ef3

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ logs
33
app/mrmax.py
44
db
55
/venv/
6+
.idea
7+
.venv
8+
*.iml
9+
*.pyc

config/config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
# api 接口封装类
99
llm_api_impl = "llm_api.llm_api_default.LLMApiDefault"
1010

11-
# api 配置默使用认UnionLLM,参考:https://github.com/EvalsOne/UnionLLM/tree/main/docs
11+
# api 配置方式参考 docs/llm_api.md
12+
# 默认使用认UnionLLM,参考:https://github.com/EvalsOne/UnionLLM/tree/main/docs
1213
# UnionLLM兼容LiteLLM,参考LiteLLM文档:https://docs.litellm.ai/docs
1314
api_config = {
14-
"OPENAI_API_KEY": "your openai key",
15-
"OPENAI_API_BASE": "https://api.openai.com/v1",
16-
"MODEL_NAME": model_gpt_4o,
17-
"PROVIDER": "openai",
15+
"api_key": "your openai key",
16+
"api_base": "https://api.openai.com/v1",
17+
"model": model_gpt_4o,
18+
"provider": "openai",
1819
}
1920

2021
# 2. 提示词

llm_api/llm_api_default.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@
1111
class LLMApiDefault(LLMApiInterface):
1212

1313
def __init__(self):
14-
self.model_name = None
14+
self.params = {}
1515
self.response = None
16-
self.provider = None
1716

1817
def set_config(self, api_config: dict) -> bool:
1918
if api_config is None:
2019
raise ValueError("api_config is None")
2120
for key in api_config:
22-
if key == "MODEL_NAME":
23-
self.model_name = api_config[key]
24-
if key == "PROVIDER":
25-
self.provider = api_config[key]
26-
os.environ[key] = api_config[key]
21+
self.params[key] = api_config[key]
22+
# 如果为大写,则写入环境变量
23+
if key.isupper():
24+
os.environ[key] = api_config[key]
2725
return True
2826

2927
def generate_text(self, messages: list) -> bool:
3028
try:
31-
self.response = unionchat(provider=self.provider, model=self.model_name, messages=messages)
29+
self.response = unionchat(messages=messages, **self.params)
3230
except Exception as e:
3331
raise e
3432
return True

0 commit comments

Comments
 (0)