import osimport jsonfrom openai import OpenAIclient = OpenAI( api_key=os.environ["API_KEY"], base_url="https://api.siflow.cn/model-api",)tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a city", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "City name", } }, "required": ["city"], }, }, }]def get_weather(city: str) -> dict: # Replace with a real API call. return {"city": city, "temp_c": 21, "condition": "Sunny"}messages = [ {"role": "user", "content": "What's the weather like in Paris today?"}]# 1. First call: the model decides whether to use the tool.resp = client.chat.completions.create( model="Qwen/Qwen3.6-27B", messages=messages, tools=tools, tool_choice="auto", max_completion_tokens=1024,)msg = resp.choices[0].messageif msg.tool_calls: messages.append(msg) for call in msg.tool_calls: args = json.loads(call.function.arguments) result = get_weather(**args) # 2. Return the tool result, linked by tool_call_id. messages.append( { "role": "tool", "tool_call_id": call.id, "content": json.dumps(result), } ) # 3. Second call: the model writes the final answer. final = client.chat.completions.create( model="Qwen/Qwen3.6-27B", messages=messages, max_completion_tokens=1024, ) print(final.choices[0].message.content)else: print(msg.content)