Skip to content

Instantly share code, notes, and snippets.

@zainhas
Created August 19, 2025 18:59
Show Gist options
  • Save zainhas/9d0e5b1ef26879ebc3a4dc28111929e9 to your computer and use it in GitHub Desktop.
Save zainhas/9d0e5b1ef26879ebc3a4dc28111929e9 to your computer and use it in GitHub Desktop.
forced function calling using tool_choice for GLM-4.5 Air
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="zai-org/GLM-4.5-Air-FP8",
messages=[
{"role": "user", "content": "What's the current price of Apple's stock?"},
],
tools=tools,
tool_choice={"type": "function", "function": {"name": "get_current_stock_price"}}
)
print(json.dumps(response.choices[0].message.model_dump()['tool_calls'], indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment