Nexevo.aiNexevo.ai
← All examples
Streaming & Tool Calling

Function calling / tool call

Let the model tune your code (check DB, weather, anything).

Python
python
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["NEXEVO_API_KEY"],
    base_url="https://api.nexevo.ai/v1",
)

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
    tools=tools,
)

# The model returns a tool call; you execute it and feed the result back:
tool_call = response.choices[0].message.tool_calls[0]
print(tool_call.function.name, tool_call.function.arguments)
Function calling / tool call — Nexevo Cookbook | Nexevo.ai