Skip to content

Commit 70d24a2

Browse files
committed
don't use tools when response_format is included (they're mutually exclusive)
1 parent e0e32c5 commit 70d24a2

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"model": "moonshotai/kimi-k2-instruct",
3+
"messages": [
4+
{
5+
"role": "user",
6+
"content": [
7+
{
8+
"type": "text",
9+
"text": "Return the list of capital cities for the following countries: France, Germany, Italy, Spain, Portugal, Japan, Australia."
10+
}
11+
]
12+
}
13+
],
14+
"response_format": {
15+
"type": "json_schema",
16+
"json_schema": {
17+
"name": "country_capitals",
18+
"strict": true,
19+
"schema": {
20+
"type": "object",
21+
"properties": {
22+
"capitals": {
23+
"type": "array",
24+
"items": {
25+
"type": "object",
26+
"properties": {
27+
"country": {
28+
"type": "string"
29+
},
30+
"capital": {
31+
"type": "string"
32+
}
33+
},
34+
"required": [
35+
"country",
36+
"capital"
37+
],
38+
"additionalProperties": false
39+
}
40+
}
41+
},
42+
"required": [
43+
"capitals"
44+
],
45+
"additionalProperties": false
46+
}
47+
}
48+
}
49+
}

llms/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,9 @@ async def g_chat_completion(chat, context=None):
19841984
raise e
19851985

19861986

1987-
async def cli_chat(chat, tools=None, image=None, audio=None, file=None, args=None, raw=False, nohistory=False, nostore=False):
1987+
async def cli_chat(
1988+
chat, tools=None, image=None, audio=None, file=None, args=None, raw=False, nohistory=False, nostore=False
1989+
):
19881990
if g_default_model:
19891991
chat["model"] = g_default_model
19901992

@@ -3075,6 +3077,9 @@ def exit(self, exit_code: int = 0):
30753077
def create_chat_with_tools(self, chat: Dict[str, Any], use_tools: str = "all") -> Dict[str, Any]:
30763078
# Inject global tools if present
30773079
current_chat = chat.copy()
3080+
# Don't inject tools when response_format is set (structured output)
3081+
if "response_format" in current_chat:
3082+
return current_chat
30783083
tools = current_chat.get("tools")
30793084
if tools is None:
30803085
tools = current_chat["tools"] = []

0 commit comments

Comments
 (0)