ms-agent
ms-agent copied to clipboard
添加了一个【自定义工具】,但是工具调用并不稳定,有时能成功调用,有时又产生幻觉,要怎么才能提高调用稳定性呢?
Initial Checks
- [X] I have searched GitHub for a duplicate issue and I'm sure this is something new
- [X] I have read and followed the docs & demos and still think this is a bug
- [X] I am confident that the issue is with modelscope-agent (not my code, or another library in the ecosystem)
What happened + What you expected to happen
正确调用的情况:
错误调用的情况:
Versions / Dependencies
Modelscope-agent: 0.7.0 python: 3.10 OS: centos8
Reproduction script
import os
import sys
import json
from typing import Dict, Optional, Union
sys.path.insert(0, "/data/workspace/modelscope-agent")
from modelscope_agent.agents import RolePlay
from modelscope_agent.tools.base import BaseTool
from modelscope_agent.tools import register_tool
@register_tool("UserDatabase")
class UserDatabase(BaseTool):
description = "企业员工数据库,包含员工的性别、生日、职位信息"
name = "UserDatabase"
parameters: list = [
{
"name": "name",
"type": "string",
"description": "员工名字,所属查阅信息的员工姓名,如`张三",
"required": True,
}
]
def __init__(self, cfg: Optional[Dict] = None):
super().__init__(cfg)
# 数据库存有员工基本信息
self.database = {
"李四": {"性别": "女", "生日": "10月3日", "职位": "画师"},
"张三": {"性别": "男", "生日": "5月5日", "职位": "业务员"},
"王五": {"性别": "男", "生日": "12月19日", "职位": "业务经理"},
}
def call(self, params: Union[str, dict], **kwargs) -> str:
params = self._verify_args(params)
name = params["name"]
# 输入姓名返回员工信息
return json.dumps(self.database.get(name, "查无此人"), ensure_ascii=False)
role_template = ""
llm_config = {
"model": "qwen2:7b-instruct",
"model_server": "ollama",
}
function_list = ["UserDatabase"]
bot = RolePlay(function_list=function_list, llm=llm_config, instruction=role_template)
response = bot.run(
"职工张三的生日是在今年10月份吗?现在是2月份,距离张三的生日还有几个月?",
remote=False,
print_info=True,
)
text = ""
for chunk in response:
text += chunk
print(text)
Issue Severity
None