Auto Tools Mode
Models
Model
Description
Function Calling Example
import json
import os
import requests
from openai import OpenAI
endpoint = "https://conductor.arcee.ai/v1"
api_key = os.getenv("ARCEE_KEY")
client = OpenAI(
base_url=endpoint,
api_key=api_key,
)
def get_weather(latitude, longitude):
response = requests.get(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m")
data = response.json()
return data['current']['temperature_2m']
tools = [{
"type": "function",
"name": "get_weather",
"description": "Get current temperature for provided coordinates in celsius.",
"parameters": {
"type": "object",
"properties": {
"latitude": {"type": "number"},
"longitude": {"type": "number"}
},
"required": ["latitude", "longitude"],
"additionalProperties": False
},
"strict": True
}]
user_prompt = "What's the weather like in Paris today?"
tool_response = client.chat.completions.create(
model="auto-tool",
messages=[{"role": "user", "content": user_prompt}],
tools=tools,
tool_choice="auto",
max_tokens=128,
)
tool_call = tool_response.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
tool_result = get_weather(args["latitude"], args["longitude"])
tool_result = f"The current temperature is {tool_result}°C."
messages=[
{
"role": "system",
"content": "You are a helpful and knowledgeable assistant giving sharp answers. Use a business-oriented tone."
},
{
"role": "user",
"content": f"""Answer the following question: {user_prompt} using the tool result: {tool_result}.
If the tool result is empty or not useful, say it is not useful and answer the question without using the information.
If the tool result is useful, you can complement it with your own knowledge as long as it's not contradictory.
"""
}
]
answer_response = client.chat.completions.create(
model="auto",
messages=messages,
)
print(answer_response.choices[0].message.content)Last updated

