Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加了一个【自定义工具】,但是工具调用并不稳定,有时能成功调用,有时又产生幻觉,要怎么才能提高调用稳定性呢? #563

Open
3 tasks done
332123342 opened this issue Aug 6, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@332123342
Copy link

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have read and followed the docs & demos and still think this is a bug
  • 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

正确调用的情况:
image

错误调用的情况:
image

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

@332123342 332123342 added the bug Something isn't working label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants