Skip to content

Commit

Permalink
[feature] Add verification to configuration parameters
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 Jun 4, 2024
1 parent 8c7ee17 commit a285724
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
35 changes: 6 additions & 29 deletions df-llm-agent/llm_agent_app/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from utils import logger
from database import db_models
import datetime

import copy
from utils.curl_tools import curl_tools
from utils.tools import generate_uuid
from config import config
Expand Down Expand Up @@ -230,44 +230,21 @@ async def assistant_base(
res_config = config.platforms
for _info in res_config:
if _info.get("platform", "") == platform and _info.get("enable", False):

engine_config = copy.deepcopy(_info)

_engine_name = _info.get("engine_name", [])
if engine_name in _engine_name:
_info["engine_name"] = f"{engine_name}"
engine_config["engine_name"] = f"{engine_name}"
else:
_info["engine_name"] = ""

engine_config = _info
engine_config["engine_name"] = ""

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

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:
Expand Down
11 changes: 10 additions & 1 deletion df-llm-agent/llm_agent_app/llm_agent_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ async def llm_agent_config_list(cls, user_info, platform=""):

if platform and platform != _platform:
continue

_enable = _info.get('enable', False)

__info['enable'] = "1" if _enable else "0"

__info['model'] = _info.get('model', '')
__info['engine_name'] = _info.get('engine_name', [])

engine_name = _info.get('engine_name', [])

if not isinstance(engine_name, list):
raise BadRequestException("INVALID_PARAMETERS", f"{const.INVALID_PARAMETERS}, 配置项 engine_name 的值格式错误,engine_name:{engine_name}")

__info['engine_name'] = engine_name

res[f"{_platform}"] = __info

Expand Down

0 comments on commit a285724

Please sign in to comment.