client=OpenAI(api_key=os.environ.get("OPENAI_API_KEY"),)response=client.chat.completions.create(model="gpt-4",messages=messages,tools=functions,tool_choice="auto",)responseChatCompletion(id='chatcmpl-9qcEK7rbZMu5p5LNqJejAE1354S3j',choices=[Choice(finish_reason='tool_calls',index=0,logprob...
chat.completionsMessage(content='Hithere!Icanhelpwiththat.CanyoupleaseprovideyourorderID?',role='assistant',function_call=None,tool_calls=None) 在助手使用场景中,你通常会希望向用户展示这个回应,并让他们对其进行回复,在这种情况下,你将再次调用API(将助手的最新回应和用户的回应都追加到消息中)。 假设我们...
def submit_user_message(user_query,conversation_messages=[]): """Message handling function which loops through tool calls until it reaches one that requires a response. Once it receives respond=True it returns the conversation_messages to the user.""" # Initiate a respond object. This will be...
{"id":"run_abc123","object":"thread.run","assistant_id":"asst_abc123","thread_id":"thread_abc123","status":"requires_action","required_action": {"type":"submit_tool_outputs","submit_tool_outputs": {"tool_calls": [ {"id":"call_abc123","type":"function","function": {"name...
tool_calls = response_message.tool_calls # Step 2: check if the model wanted to call a function if tool_calls: # Step 3: call the function # Note: the JSON response may not always be valid; be sure to handle errors available_functions = { ...
response里的tool_calls,包含了我们描述的函数相关信息,以及所需要的参数。 调用自定义函数 从前面的response中提取参数,并调用get_weather(city, date): 代码语言:javascript 复制 iftool_calls:tool_call=tool_calls[0]function_args=json.loads(tool_call.function.arguments)function_response=get_weather(city=func...
tool_calls = response_message.tool_calls # 检查是否需要调用函数 if tool_calls: # 解析所有需要调用的函数及参数 messages.append(response_message) # 注意这里要将openai的回复也拼接到消息列表里 # 将所有函数调用的结果拼接到消息列表里 for tool_call in tool_calls: ...
●与并行函数调用不兼容:生成并行函数调用时,可能不符合提供的模式。开发者可以禁用并行函数调用,使用“parallel_tool_calls: false”设置。●不符合零数据保留(ZDR)资格:结构化输出与JSON模式不符合零数据保留(ZDR)资格。五、总结:OpenAI 推出的结构化输出功能,让大模型的应用更加灵活和高效。通过定义 JSON ...
AIMessage.tool_calls 在过去,当使用工具调用模型时,模型返回的工具调用可能会放在AIMessage.additional_...