Tool calling
Let the model call your functions, in the OpenAI tools format.
Describe your functions in tools. When the model wants one, the reply has finish_reason: "tool_calls" and the call in message.tool_calls. Run it, send the result back as a tool message, and ask again.
Python:
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
r = client.chat.completions.create(
model="ghost-x2",
messages=[{"role": "user", "content": "What is the weather in Paris?"}],
tools=tools,
)
call = r.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments) # get_weather {"city": "Paris"}