import json
from edgee import Edgee
edgee = Edgee("your-api-key")
# Define the weather function
async def get_weather(location: str, unit: str = "celsius"):
# Simulate API call
return {
"location": location,
"temperature": 15,
"unit": unit,
"condition": "sunny"
}
# Step 1: Initial request with tools
response1 = edgee.send(
model="gpt-4o",
input={
"messages": [
{"role": "user", "content": "What is the weather in Paris and Tokyo?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city name"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}
)
# Step 2: Execute all tool calls
messages = [
{"role": "user", "content": "What is the weather in Paris and Tokyo?"},
response1.message # Include assistant's message
]
if response1.tool_calls:
for tool_call in response1.tool_calls:
args = json.loads(tool_call["function"]["arguments"])
result = await get_weather(args["location"], args.get("unit"))
messages.append({
"role": "tool",
"tool_call_id": tool_call["id"],
"content": json.dumps(result)
})
# Step 3: Send results back
response2 = edgee.send(
model="gpt-4o",
input={
"messages": messages,
"tools": [
# Keep tools available for follow-up
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "The city name"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}
]
}
)
print(response2.text)