Function Calling
Define tools so AI can decide when to call external functions.
1
2
3
4
5
6
7
from openai import OpenAI
client = OpenAI(api_key="KEY", base_url="https://api.aipilotads.com/v1")
tools = [{"type":"function","function":{"name":"get_weather","description":"Get weather","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]
response = client.chat.completions.create(model="gpt-5.5", messages=[{"role":"user","content":"What's the weather in Cairo?"}], tools=tools)
print(response.choices[0].message.tool_calls)