所以,你会发现,OpenAI只是首先提出了function call概念,至于怎么实现的,还是要各家自己来做。而MCP直接开放了协议,希望把这种各自为政的function call统一到一起,成为一个标准。我们来举个例子,function call好比家里的电器遥控器,每个遥控器都得单独编接口才能控制相应电器。比如想让AI查询天气,就得跟第三方...
Function call是OpenAI API中提供的一个功能,允许大型语言模型(LLM)在生成文本时调用外部函数或API。这一功能极大地扩展了LLM的应用场景,使其能够执行更复杂的任务,如数据检索、信息整合等。 2. 具体步骤 使用OpenAI接口进行function call的具体步骤通常包括以下几个部分: 定义函数规范:首先,需要定义你想要LLM调用的外...
function_call="auto" ) # 解析模型生成的函数调用 function_call = response['choices'][0]['message']['function_call'] function_name = function_call['name'] function_args = function_call['arguments'] # 调用外部函数 if function_name == "get_weather": weather_info = get_weather(**function...
arguments=json.loads(tool_call.function.arguments) city=arguments['city'] weather_info=check_weather(city) print(f"Weatherin{city}:{weather_info}") 每个数组中的函数调用都有一个唯一的ID。 在你的应用程序中执行了这些函数调用后,你可以通过为每个函数调用添加一条新消息来向模型提供结果,每条消息都包含...
本文通过一个具体的示例,解析如何利用 MCP(Multi-turn Conversation Protocol)和 OpenAI API 中的 Function Call 功能,实现一个完整的多轮对话流程。示例场景模拟用户预订机票的需求,从解析意图、查询航班、用户选择到最终预订确认,每一步都展示了如何将 Functio...
您可能还会注意到另一个名为 function_call 的参数,它被设置为 "auto"(自动)。这是为了让 OpenAI 决定使用哪个函数。在下一节讨论多个函数时,您将看到它的用途。 tools参数 functions参数是将要被弃用的一个参数,更加推荐使用tools参数 使用tools参数实现同样的功能: my_tools = [ {"type":"function", 'functi...
iftool_calls:tool_call=tool_calls[0]function_args=json.loads(tool_call.function.arguments)function_response=get_weather(city=function_args.get("city"),date=function_args.get("date"),)returnfunction_response 输出结果: 代码语言:javascript
function_call:模型决定需要调用一个函数。 content_filter:内容触发了拦截策略,忽略返回内容。 null:API 响应仍在执行。 其中,若返回 function_call 则表示模型需要调用函数。此时 message 参数会额外返回函数信息以及函数参数信息。 message.function_call
"function_call": { "name": "get_student_score", "arguments": "{\n\"name\": \"Lucy\"\n}" } } Lucy 拿着对应参数 name='Lucy',去执行相应函数 get_student_score 获得 json 结果,再次调用 chat 函数完成自然语言的回复 second_response = openai.ChatCompletion.create( ...
It would be great to have it before the end of the week.\\n\\nThanks,\\n[Your Name]\"\n}" } },"finish_reason": "function_call" } ],"usage": {"prompt_tokens": 86,"completion_tokens": 82,"total_tokens": 168 }}GPT模型会返回需要调用的函数名 send_email和对应的...