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://api.cortecs.ai/v1",
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)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.cortecs.ai/v1",
apiKey: "<API_KEY>",
});
const 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"],
},
},
},
];
const completion = await client.chat.completions.create({
model: "<MODEL_NAME>",
messages: [
{ role: "user", content: "What’s the weather like in Paris?" }
],
tools: tools,
tool_choice: "auto",
});
const toolCall = completion.choices[0].message.tool_calls[0];
console.log("Tool name:", toolCall.function.name);
console.log("Arguments:", toolCall.function.arguments);curl https://api.cortecs.ai/v1/chat/completions \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "<MODEL_NAME>",
"messages": [
{
"role": "user",
"content": "What’s the weather like in Paris?"
}
],
"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"]
}
}
}
],
"tool_choice": "auto"
}'
Last updated