Skip to content

Commit

Permalink
[feature] Model parameters are preferably configured using yaml files.
Browse files Browse the repository at this point in the history
**Phenomenon and reproduction steps**

**Root cause and solution**

**Impactions**

**Test method**

**Affected branch(es)**

* main

**Checklist**

- [ ] Dependencies update required
- [ ] Common bug (similar problem in other repo)
  • Loading branch information
congxi committed Apr 8, 2024
1 parent 54a3991 commit bc0b92c
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 17 deletions.
38 changes: 38 additions & 0 deletions deploy/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,41 @@ data:
host: mysql
port: 30130
database: deepflow_llm
ai:
enable: False # True,False
platforms:
-
enable: False
platform: "azure"
model: "gpt"
api_type: "azure"
api_key: ""
api_base: ""
api_version: ""
engine_name:
- ""
-
enable: False
platform: "aliyun"
model: "dashscope"
api_key: ""
engine_name:
- "qwen-turbo"
- "qwen-plus"
-
enable: False
platform: "baidu"
model: "qianfan"
api_key: ""
api_secre: ""
engine_name:
- "ERNIE-Bot"
- "ERNIE-Bot-turbo"
-
enable: False
platform: "zhipu"
model: "zhipuai"
api_key: ""
engine_name:
- "chatglm_turbo"
6 changes: 6 additions & 0 deletions df-llm-agent/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def __init__(self, _yml=None):
self.mysql_port = mysql.get('port', 20130)
self.mysql_database = mysql.get('database', 'deepflow_llm')

ai = yml.get('ai', {})
if ai:
enable = ai.get('enable', False)
if enable:
self.platforms = ai.get('platforms', [])

except Exception as e:
traceback.print_exc()
print("配置文件解析错误: %s" % e)
Expand Down
54 changes: 37 additions & 17 deletions df-llm-agent/llm_agent_app/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from utils.curl_tools import curl_tools
from utils.tools import generate_uuid

from config import config
from chat_record_app.chat_record import chat_record_worker

from langchain_openai import AzureChatOpenAI
Expand Down Expand Up @@ -209,26 +209,46 @@ async def assistant_base(cls, request, user_info, platform, engine_name, prompt_
data_info = {}
# data_info["user_id"] = user_id
data_info["platform"] = platform
try:
res_config = await db_models.LlmConfig.filter(**data_info).all()
except Exception as e:
raise BadRequestException("SQL_ERROR", const.SQL_ERROR, f"{e}")

engine_config = {}
# key = engine_name 时可能会存在多个配置,设置为当前使用值
for v in res_config:
v_dict = dict(v)
_key = v_dict["key"]
_value = v_dict["value"]

if _key == "engine_name":
if _value == engine_name:

if hasattr(config, "platforms"):
res_config = config.platforms
for _info in res_config:
if _info.get('platform', '') == platform and _info.get('enable', False):
_engine_name = _info.get('engine_name', [])
if engine_name in _engine_name:
_info['engine_name'] = f"{engine_name}"
else:
_info['engine_name'] = ''

engine_config = _info

if not engine_config.get("enable", False):
raise BadRequestException("INVALID_PARAMETERS", f"{const.INVALID_PARAMETERS}, 平台: {platform} 未启用")

else:
try:
res_config = await db_models.LlmConfig.filter(**data_info).all()
except Exception as e:
raise BadRequestException("SQL_ERROR", const.SQL_ERROR, f"{e}")

# key = engine_name 时可能会存在多个配置,设置为当前使用值
for v in res_config:
v_dict = dict(v)
_key = v_dict["key"]
_value = v_dict["value"]

if _key == "engine_name":
if _value == engine_name:
engine_config[_key] = _value
else:
engine_config[_key] = _value
else:
engine_config[_key] = _value

if engine_config.get("enable", "") != "1":
raise BadRequestException("INVALID_PARAMETERS", f"{const.INVALID_PARAMETERS}, 引用的引擎未开启: {engine_name}")
if engine_config.get("enable", "") != "1":
raise BadRequestException("INVALID_PARAMETERS", f"{const.INVALID_PARAMETERS}, 平台: {platform} 未启用")

# print(engine_config, engine_config.get("engine_name"), engine_name)

if engine_config.get("engine_name", "") != engine_name:
raise BadRequestException("INVALID_PARAMETERS", f"{const.INVALID_PARAMETERS}, 引用的引擎错误: {engine_name}")
Expand Down
37 changes: 37 additions & 0 deletions etc/df-llm-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,40 @@ mysql:
host: mysql
port: 30130
database: deepflow_llm
ai:
enable: False # True,False
platforms:
-
enable: False
platform: "azure"
model: "gpt"
api_type: "azure"
api_key: ""
api_base: ""
api_version: ""
engine_name:
- ""
-
enable: False
platform: "aliyun"
model: "dashscope"
api_key: ""
engine_name:
- "qwen-turbo"
- "qwen-plus"
-
enable: False
platform: "baidu"
model: "qianfan"
api_key: ""
api_secre: ""
engine_name:
- "ERNIE-Bot"
- "ERNIE-Bot-turbo"
-
enable: False
platform: "zhipu"
model: "zhipuai"
api_key: ""
engine_name:
- "chatglm_turbo"

0 comments on commit bc0b92c

Please sign in to comment.