Tool Calling
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)Last updated