from openai import OpenAI
import json
import os
client = OpenAI(
api_key=os.environ["OXEN_API_KEY"],
base_url="https://hub.oxen.ai/api/ai",
)
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
},
"required": ["city"],
},
},
},
]
messages = [{"role": "user", "content": "What is the weather in Paris?"}]
def get_weather(city: str) -> str:
# Your real implementation would call a weather API.
return json.dumps({"temperature_c": 18, "conditions": "Partly cloudy"})
while True:
response = client.chat.completions.create(
model="gpt-5-4-2026-03-05",
messages=messages,
tools=tools
)
choice = response.choices[0]
msg = choice.message
if not msg.tool_calls:
print(msg.content)
break
messages.append(msg)
for call in msg.tool_calls:
name = call.function.name
args = json.loads(call.function.arguments or "{}")
if name == "get_weather":
output = get_weather(args["city"])
else:
output = json.dumps({"error": f"unknown tool: {name}"})
messages.append(
{
"role": "tool",
"tool_call_id": call.id,
"content": output,
}
)