from openai import OpenAI
import os, json
client = OpenAI(api_key=os.environ.get("TOGETHER_API_KEY"),
base_url="https://api.together.xyz/v1",)
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
}
},
"required": [
"location"
],
"additionalProperties": False
},
"strict": True
}
}]
completion = client.chat.completions.create(
model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
messages=[{"role": "user", "content": "What is the weather like in Paris today?"}],
tools=tools,
tool_choice="auto"
)
print(json.dumps(completion.choices[0].message.model_dump()['tool_calls'], indent=2))