Hey, was wondering how you would add your own tool calling messages (as if they were from the model itself) to the messages now that every tool call has an id?
Here is an example of what I mean using deprecated function calling instead:
from openai import OpenAI
client = OpenAI()
functions = [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
}
]
user_msg = {
"role": "user",
"content": "What is the weather like in Stockholm?",
}
assistant_msg = {
"role": "assistant",
"function_call": {
"arguments": """{"location": "Stockholm", "unit": "celsius"}""",
"name": "get_current_weather",
},
}
function_msg = {
"role": "function",
"name": "get_current_weather",
"content": """{"weather": "sunny", "temperature": 21, "unit": "celsius"}""",
}
assistant_msg2 = {
"role": "assistant",
"content": "It is sunny and 21 degrees celsius in Stockholm.",
}
user_msg2 = {
"role": "user",
"content": "What is the weather like in Oslo?",
}
messages = [user_msg, assistant_msg, function_msg, assistant_msg2, user_msg2]
response = client.chat.completions.create(
model="gpt-4-0613",
messages=messages,
functions=functions,
)
print(response.choices[0].message)
How would you achieve the same using tools instead?