-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
In the docs for parallel function calling (https://platform.openai.com/docs/guides/function-calling), the name is included along with the tool_call_id
, content
, and role
. All the other messages have a name.
... # rest of the example from https://platform.openai.com/docs/guides/function-calling
for tool_call in tool_calls:
function_name = tool_call.function.name
function_to_call = available_functions[function_name]
function_args = json.loads(tool_call.function.arguments)
function_response = function_to_call(
location=function_args.get("location"),
unit=function_args.get("unit"),
)
messages.append(
{
"tool_call_id": tool_call.id,
"role": "tool",
"name": function_name,
"content": function_response,
}
) # extend conversation with function response
second_response = client.chat.completions.create(
model="gpt-3.5-turbo-1106",
messages=messages,
) # get a new response from the model where it can see the function response
return second_response
Either the docs need an update or ChatCompletionToolMessageParam
needs name
(even if Optional
).
To Reproduce
Run the following script through mypy
from openai.types.chat import ChatCompletionToolMessageParam
def tool_result(tool_call_id: str, name: str, content: str) -> ChatCompletionToolMessageParam:
"""Create a tool result message.
Args:
tool_call_id: The ID of the tool call.
name: The name of the tool.
content: The content of the message.
Returns:
A dictionary representing a tool result message.
"""
return {
"role": "tool",
"content": content,
"name": name,
"tool_call_id": tool_call_id,
}
tool_result("tool_pretend_id", name="myfunc", content="4")
Code snippets
from openai.types.chat import ChatCompletionToolMessageParam
def tool_result(tool_call_id: str, name: str, content: str) -> ChatCompletionToolMessageParam:
"""Create a tool result message.
Args:
tool_call_id: The ID of the tool call.
name: The name of the tool.
content: The content of the message.
Returns:
A dictionary representing a tool result message.
"""
return {
"role": "tool",
"content": content,
"name": name,
"tool_call_id": tool_call_id,
}
tool_result("tool_pretend_id", name="myfunc", content="4")
OS
macOS
Python version
Python 3.12.1
Library version
openai v1.4.0
kumapo