import json
from together import Together
client = Together()
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
},
},
},
},
},
{
"type": "function",
"function": {
"name": "get_current_stock_price",
"description": "Get the current stock price for a given stock symbol",
"parameters": {
"type": "object",
"properties": {
"symbol": {
"type": "string",
"description": "The stock symbol, e.g. AAPL, GOOGL, TSLA",
},
"exchange": {
"type": "string",
"description": "The stock exchange (optional)",
"enum": ["NYSE", "NASDAQ", "LSE", "TSX"],
},
},
"required": ["symbol"],
},
},
},
]
response = client.chat.completions.create(
model="Qwen/Qwen2.5-7B-Instruct-Turbo",
messages=[
{
"role": "user",
"content": "What's the current price of Apple and Google stock? What is the weather in New York, San Francisco and Chicago?",
},
],
tools=tools,
)
print(
json.dumps(
response.choices[0].message.model_dump()["tool_calls"],
indent=2,
)
)