-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
[Request] tool_calls改为role=tool #999
Comments
我调研过,目前看没有太大必要,OpenAI 现在这个能力有点鸡肋的。#551 (comment) |
这个避免重复调用的原理是什么样的? 用 role=function 应该一样能达到这个效果吧?
这个是需要升级的,但涉及到已有数据的迁移升级,准备找一个更合适的时间做个统一的升级。 |
官方案例中function_call和tool_calls的最大区别是,tool_calls会把调用信息当做一条message放入上下文中,相比于function_call会多一条调用参数的信息。 [
{"role": "user", "content": "http://www.example.com里有什么内容"},
{"role": "function", "name": "web_crawler", "content": ""},
{"role": "function", "name": "web_crawler", "content": ""},
{"role": "function", "name": "web_crawler", "content": ""},
{"role": "function", "name": "web_crawler", "content": ""},
] tool_calls的messages是 [
{"role": "user", "content": "http://www.example.com里有什么内容"},
{"role": "assistant", "content": null, "tool_calls": [{"id": "xxx", "type": "function", "function": {"name": "web_crawler", "arguments": "{\n "url": "http://www.example.com"\n }"}},]},
{"role": "tool", "tool_call_id": "xxx", "name": "web_crawler", "content": ""},
{"role": "assistant", "content": null, "tool_calls": [{"id": "yyy", "type": "function", "function": {"name": "web_crawler", "arguments": "{\n "url": "http://www.example.com"\n }"}},]},
{"role": "tool", "tool_call_id": "yyy", "name": "web_crawler", "content": ""},
{"role": "assistant", "content": null, "tool_calls": [{"id": "zzz", "type": "function", "function": {"name": "web_crawler", "arguments": "{\n "url": "http://www.example.com"\n }"}},]},
{"role": "tool", "tool_call_id": "zzz", "name": "web_crawler", "content": ""}, tool_calls比function_call多了url的信息,在做下一步决策时会更可靠。本质上是降低模型的单次思考的猜测程度,猜的越少,智能程度就越高。 更合理的结果应该是tool_calls拿到content=""时,因为知道自己已经调用过了web_crawler(" http://www.example.com "),会更可能直接输出该网页是空内容,而function_call只知道content="",认为自己并没有解决问题,会反复调用web_crawler |
你这么说我倒是明白了,之前我在研究接入 function call 的时候就发现如果消息编排是下面这样的:
只要第二次发送的消息里带有这种结构,接口就报错,导致无法重复请求。 所以我最后的折中方案就是把函数调用这一条消息去掉,换成
但相应的问题就是会丢失执行过函数调用的这一条记录。 这么看来 openai 是意识到了这个问题,然后在 |
🥰 需求描述
目前的tool_calls机制仅在调用工具的时候使用了tools参数,拿到工具返回后仍使用role=function继续调用。看代码似乎没有实现当tool_calls数组有多个时分别调用多个function。
🧐 解决方案
应参考OpenAI的官方案例,在遇到tool_calls的assistant消息时,将该消息插入在历史messages中,并将tool_calls数组中的每个tool进行调用,得到结果后同样插入历史messages中。
原工具调用链
调用时:
调用工具后:
调整后的工具调用链:
📝 补充信息
No response
The text was updated successfully, but these errors were encountered: