Function Call实践(一)——调用国内大模型测试 #52
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
function call 实践1,换另一个国内的大模型测试。本来以为只是换一个API key的小实验,结果好像不同大模型对于message的输入在加入functiona call等外接以后有一个验证,需要调整使用方式。
总结一下最开始的尝试是用通义千问的API,然后根据模板修改一下运行,遇到了invalid parameter的报错。然后发现有message的规范和验证,最后照千问自己的模式改动程序成功。
下面从头开始,因为这个是本地运行,所以环境变量设置取消,需要安装dashscope
首先做查找天气的工具, 然后写相应的描述, 找了一个限时免费的qwen2.5-3b-instruct模型,初始化,测试
让模型提取关键词来调用工具
重写messages,因为遇到报错:BadRequestError: Error code: 400 - {'error': {'code': 'invalid_parameter_error', 'param': None, 'message': '<400> InternalError.Algo.InvalidParameter: messages with role "tool" must be a response to a preceeding message with "tool_calls".', 'type': 'invalid_request_error'}, 'id': 'chatcmpl-da56e9ef-e1db-9dbb-a1e0-abe410241c48', 'request_id': 'da56e9ef-e1db-9dbb-a1e0-abe410241c48'}。 说需要加入相对应的assistant role才可以。
但是加入以后继续报错:
此时的message是
[{'role': 'user', 'content': 'What is the weather like in Beijing?'}, {'role': 'assistant', 'function_call': {'name': 'get_weather', 'arguments': '{"location": "Beijing"}'}}, {'role': 'tool', 'content': '"{\"coord\": {\"lon\": 116.3972, \"lat\": 39.9075}, \"weather\": [{\"id\": 800, \"main\": \"Clear\", \"description\": \"\\u6674\", \"icon\": \"01n\"}], \"base\": \"stations\", \"main\": {\"temp\": -7.06, \"feels_like\": -7.06, \"temp_min\": -7.06, \"temp_max\": -7.06, \"pressure\": 1029, \"humidity\": 17, \"sea_level\": 1029, \"grnd_level\": 1024}, \"visibility\": 10000, \"wind\": {\"speed\": 0.87, \"deg\": 262, \"gust\": 1.41}, \"clouds\": {\"all\": 0}, \"dt\": 1733669329, \"sys\": {\"type\": 1, \"id\": 9609, \"country\": \"CN\", \"sunrise\": 1733613810, \"sunset\": 1733647766}, \"timezone\": 28800, \"id\": 1816670, \"name\": \"Beijing\", \"cod\": 200}"', 'tool_call_id': 'call_13489c83979a4849b46419'}]
我的想法是千问的设定是需要前一次的id和后一次的一样,所以这样分段式的message有问题,于是按照千问提供的function调用模板创造一个智能体来解决这个问题。
我觉得通过2次不同的提问,其中第二次不要当作用过tools,而是通过提示词来把已知信息注入应该也是可以的。