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

工具调用没反应 #627

Open
1 of 2 tasks
sy960923 opened this issue Oct 31, 2024 · 7 comments
Open
1 of 2 tasks

工具调用没反应 #627

sy960923 opened this issue Oct 31, 2024 · 7 comments
Assignees

Comments

@sy960923
Copy link

System Info / 系統信息

Xinference: v0.12.3版本部署得glm-4-9b-chat

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

  • The official example scripts / 官方的示例脚本
  • My own modified scripts / 我自己修改的脚本和任务

Reproduction / 复现过程

messages = [
{
"role": "user", "content": "你能帮我查一下2024年1月1日从北京南站到上海的火车票吗?"
},

]
tools = [
{
"type": "function",
"function": {
"name": "weather_check",
"description": "天气查询",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称",
}
},
"required": ["city"],
},
}
}
response = client.chat.completions.create(
model="custom-glm4",
messages=messages,
tools=tools,
stream=use_stream,
max_tokens=5000,
temperature=0.9,
presence_penalty=1.2,
top_p=0.1,
tool_choice="auto"
)
得到回复是:
ChatCompletion(id='chat4064d01e-9766-11ef-8743-c4cbe1a0b4a0', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='很抱歉,作为一个AI,我无法直接查询实时的火车票信息或进行在线购票。但是,我可以提供一些指导,帮助您查询2024年1月1日从北京南站到上海的火车票。\n\n您可以通过以下几种方式查询和购买火车票:\n\n1. 12306官方网站:这是中国铁路官方的在线购票平台,您可以访问12306.cn进行查询和购票。\n\n2. 手机应用程序:您可以在手机上下载并使用12306官方应用程序,它提供了与网站相同的功能。\n\n3. 火车站售票窗口:您可以直接前往北京南站或上海的火车站售票窗口购买车票。\n\n4. 旅行社:您也可以联系旅行社帮助您预订火车票。\n\n在查询时,您需要提供以下信息:\n- 出发站:北京南站\n- 目的地:上海\n- 出发日期:2024年1月1日\n- 乘车人信息(如需)\n\n请注意,火车票的预订情况可能会受到节假日、天气等因素的影响,建议您提前查询并预留足够的时间进行购票。', refusal=None, role='assistant', function_call=None, tool_calls=None))], created=1730365089, model='custom-glm4', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=-1, prompt_tokens=-1, total_tokens=-1))

Expected behavior / 期待表现

{

#     "role": "assistant",
#         "content": None,
#         "function_call": None,
#         "tool_calls": [
#             {
#                 "id": "call_1717912616815",
#                 "function": {
#                     "name": "weather_check",
#                     "arguments": "{\"city\": \"武汉\"}"
#                 },
#                 "type": "function"
#             }
#         ]
# },
# {
#     "tool_call_id": "call_1717912616815",
#     "role": "tool",
#     "name": "weather_check",
#     "content": "武汉今天的天气是晴,温度为22摄氏度。",
# }应该得到类似回答才对
@sy960923
Copy link
Author

sy960923 commented Oct 31, 2024

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR self-assigned this Nov 1, 2024
@zRzRzRzRzRzRzR
Copy link
Member

zRzRzRzRzRzRzR commented Nov 1, 2024

emm,可是你的问题是

你能帮我查一下2024年1月1日从北京南站到上海的火车票吗?

这怎么会调用天气工具呢

@sy960923
Copy link
Author

sy960923 commented Nov 1, 2024

emm,可是你的问题是

你能帮我查一下2024年1月1日从北京南站到上海的火车票吗?

这怎么会调用天气工具呢

tools = [
{
    "type": "function",
    "function": {
        "name": "weather_check",
        "description": "天气查询",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {
                    "type": "string",
                    "description": "城市名称",
                }
            },
            "required": ["city"],
        },
    }
}

]
messages = [
{"role": "user", "content": "武汉天气"}
]

response = client.chat.completions.create(
    model="custom-glm4",
    messages=messages,
    stream=use_stream,
    tools=tools,
    max_tokens=5000,
    temperature=0.7,
    presence_penalty=1.2,
    top_p=0.1,
    tool_choice="auto",
)我是这样写的,结果得到的是ChatCompletion(id='chatcmpl-dca18f60-7c14-4f59-b370-280cc0b5413f', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='很抱歉,我无法提供实时的天气信息。要获取武汉的实时天气情况,您可以查看天气预报网站、使用天气应用程序或通过天气预报服务来获取最新信息。', refusal=None, role='assistant', function_call=None, tool_calls=[]))], created=1730455101, model='custom-glm4', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=-1, prompt_tokens=-1, total_tokens=-1))

@sy960923
Copy link
Author

sy960923 commented Nov 1, 2024

用langchain框架的Agent调用就可以。直接openAI 接口方式调用就不行

@sy960923
Copy link
Author

sy960923 commented Nov 1, 2024

image
image

@zRzRzRzRzRzRzR
Copy link
Member

这个应该是因为没有流式输出?我看到了一个相关的PR,你试试那个PR

@sy960923
Copy link
Author

sy960923 commented Nov 4, 2024

这个应该是因为没有流式输出?我看到了一个相关的PR,你试试那个PR

是不是没有传递prompt的原因,但是
response = client.chat.completions.create(
model="custom-glm4",
messages=messages,
tools=tools,
stream=use_stream,
max_tokens=256,
temperature=0.9,
presence_penalty=1.2,
top_p=0.1,
tool_choice="auto"
) 这个没有传递这个参数的地方。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants