import json
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.naga.ac/v1", api_key=os.environ["NAGAAI_API_KEY"])
tools = [{
"type": "function",
"name": "get_weather",
"description": "Current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}]
def get_weather(city):
return {"city": city, "temperature_c": 18, "sky": "cloudy"}
items = [{"role": "user", "content": "What is the weather in Prague?"}]
while True:
response = client.responses.create(model="deepseek-v4.1-flash", input=items, tools=tools)
items += [item.model_dump(exclude_none=True) for item in response.output]
calls = [item for item in response.output if item.type == "function_call"]
if not calls:
break
for call in calls:
result = get_weather(**json.loads(call.arguments))
items.append({"type": "function_call_output", "call_id": call.call_id, "output": json.dumps(result)})
print(response.output_text)