Tool Calling
Tool calls (sometimes also called function calls) allow a language model to suggest the use of external tools. The model doesn't execute them directly, instead, it outputs a structured request indicating which tool to call and with what parameters. It's then up to the application or user to execute the tool and return the result back to the model, which incorporates it into a final, coherent response.
We provide a standardized tool calling interface across supported models and providers, making it easier to integrate tool use consistently across different backends.
For a more advanced example of tool use, see these OpenAI docs.
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI(
base_url="https://cortecs.ai/api/v1/models/serverless",
api_key="<API_KEY>",
)
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given city",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. San Francisco, CA"
}
},
"required": ["location"]
}
}
}
]
completion = client.chat.completions.create(
model="<MODEL_NAME>",
messages=[
{"role": "user", "content": "What’s the weather like in Paris?"}
],
tools=tools,
tool_choice="auto"
)
tool_call = completion.choices[0].message.tool_calls[0]
print("Tool name:", tool_call.function.name)
print("Arguments:", tool_call.function.arguments)
Last updated