Created
March 7, 2026 00:35
-
-
Save sayap/33550a28a18f29081dcc0b832f675c48 to your computer and use it in GitHub Desktop.
Test script for Q3C / Q3CN / Qwen3.5 tool calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from openai import OpenAI | |
| import json | |
| client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="dummy") | |
| tools = [ | |
| { | |
| "type": "function", | |
| "function": { | |
| "name": "get_time", | |
| "description": "Get the current local time", | |
| "parameters": { | |
| "type": "object", | |
| "properties": {}, | |
| "required": [], | |
| }, | |
| }, | |
| }, | |
| { | |
| "type": "function", | |
| "function": { | |
| "name": "get_weather", | |
| "description": "Get the current weather in a given city and state", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "city": {"type": "string", "description": "City, e.g. San Francisco"}, | |
| "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, | |
| "state": {"type": "string", "description": "State, e.g. CA"}, | |
| }, | |
| "required": ["city"], | |
| }, | |
| }, | |
| }, | |
| ] | |
| response = client.chat.completions.create( | |
| model='dummy', | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": "What's the weather like in San Francisco, CA, New York, NY, and Toronto, ON? Is it below 70 degree in any of the 3 cities? What's the time now btw?", | |
| }, | |
| ], | |
| tools=tools, | |
| tool_choice="auto", | |
| logprobs=True, | |
| top_logprobs=3, | |
| stream=False, | |
| ) | |
| choice = response.choices[0] | |
| message = choice.message | |
| logprobs = choice.logprobs.content | |
| print('reasoning_content:') | |
| print(message.reasoning_content) | |
| print() | |
| print('content:') | |
| print(message.content) | |
| print() | |
| print('tool_calls:') | |
| for tool_call in message.tool_calls: | |
| print(tool_call.function) | |
| print() | |
| tool_call_started = False | |
| worst_logprob = 0.0 | |
| for logprob in logprobs: | |
| if not tool_call_started and logprob.token == '<tool_call>': | |
| tool_call_started = True | |
| if not tool_call_started: | |
| continue | |
| if logprob.logprob < worst_logprob: | |
| worst_logprob = logprob.logprob | |
| print(f'worst logprobs in tool_calls: {worst_logprob:.9f}') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bad output when parallel tool calls are not allowed (pre ikawrakow/ik_llama.cpp#1300):
We can change the argument order in the tool definition to be city, state, unit, to bypass the strict ordering issue:
The very bad logprob happened when the model wanted to continue with the 2nd tool call, but the grammar didn't allow it.