OpenAI compatible API Tool Call
#1
by
subhagato
- opened
curl http://localhost:1234/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-coder-30b-a3b-instruct-mlx@4bit",
"messages": [{"role": "user", "content": "What dell products do you have under $50 in electronics?"}],
"tools": [
{
"type": "function",
"function": {
"name": "search_products",
"description": "Search the product catalog by various criteria. Use this whenever a customer asks about product availability, pricing, or specifications.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search terms or product name"
},
"category": {
"type": "string",
"description": "Product category to filter by",
"enum": ["electronics", "clothing", "home", "outdoor"]
},
"max_price": {
"type": "number",
"description": "Maximum price in dollars"
}
},
"required": ["query"],
"additionalProperties": false
}
}
}
]
}'
Response:
{
"id": "chatcmpl-bba5dnu05g206j7fnsii2",
"object": "chat.completion",
"created": 1754360150,
"model": "qwen3-coder-30b-a3b-instruct-mlx@6bit",
"choices": [
{
"index": 0,
"logprobs": null,
"finish_reason": "tool_calls",
"message": {
"role": "assistant",
"tool_calls": [
{
"id": "732918706",
"type": "function",
"function": {
"name": "search_products",
"arguments": "<parameter=query>dell</parameter><parameter=category>electronics</parameter><parameter=max_price>50</parameter>"
}
}
]
}
}
],
"usage": {
"prompt_tokens": 396,
"completion_tokens": 42,
"total_tokens": 438
},
"stats": {},
"system_fingerprint": "qwen3-coder-30b-a3b-instruct-mlx@6bit"
}
The tool call result is not compatible with openai specs. The expected parameter syntax is
"arguments": "{"query":"dell","category":"electronics","max_price":50}"
but we are getting:
"arguments": "<parameter=query>dell<parameter=category>electronics<parameter=max_price>50"
How can we fix this issue?