Skip to content

Commit ea70649

Browse files
committed
don't process tool call if not enabled
1 parent 1330550 commit ea70649

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

common/chat.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
13641364
);
13651365
static const common_regex builtin_tool_call_regex("(?:browser|python)[\\s\\S]*<\\|message\\|>");
13661366

1367-
auto consume_until_start = [&]() {
1367+
auto consume_until_next = [&]() {
13681368
if (auto res = builder.try_find_regex(start_regex, std::string::npos, false)) {
13691369
auto begin = res->groups[0].begin;
13701370
builder.move_to(begin);
@@ -1382,27 +1382,31 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
13821382
builder.consume_rest();
13831383
LOG_ERR("builtin tool calls not implemented\n");
13841384
} else {
1385-
throw common_chat_msg_parse_exception("expected function call, got: " + consume_until_start());
1385+
throw common_chat_msg_parse_exception("expected function call, got: " + consume_until_next());
13861386
}
13871387
};
13881388

13891389
auto commentary = [&]() {
13901390
if (builder.try_consume_regex(to_regex)) {
1391-
tool_call();
1391+
if (builder.syntax().parse_tool_calls) {
1392+
tool_call();
1393+
} else {
1394+
consume_until_next();
1395+
}
13921396
} else if (builder.try_consume_regex(message_regex)) {
13931397
if (!builder.try_find_regex(end_regex)) {
13941398
builder.add_content(builder.consume_rest());
13951399
}
13961400
} else {
1397-
throw common_chat_msg_parse_exception("expected: \" to=\" or <|message|>, got: " + consume_until_start());
1401+
throw common_chat_msg_parse_exception("expected: \" to=\" or <|message|>, got: " + consume_until_next());
13981402
}
13991403
};
14001404

14011405
auto final = [&]() {
14021406
if (builder.try_consume_regex(message_regex)) {
14031407
builder.add_content(builder.consume_rest());
14041408
} else {
1405-
throw common_chat_msg_parse_exception("expected: <|message|>, got: " + consume_until_start());
1409+
throw common_chat_msg_parse_exception("expected: <|message|>, got: " + consume_until_next());
14061410
}
14071411
};
14081412

@@ -1416,7 +1420,7 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
14161420
builder.add_reasoning_content(builder.consume_rest());
14171421
}
14181422
} else {
1419-
throw common_chat_msg_parse_exception("expected: <|message|>, got: " + consume_until_start());
1423+
throw common_chat_msg_parse_exception("expected: <|message|>, got: " + consume_until_next());
14201424
}
14211425
};
14221426

@@ -1433,15 +1437,15 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
14331437
}
14341438
}
14351439
} else {
1436-
throw common_chat_msg_parse_exception("expected: <|channel|>, got: " + consume_until_start());
1440+
throw common_chat_msg_parse_exception("expected: <|channel|>, got: " + consume_until_next());
14371441
}
14381442
};
14391443

14401444
auto start = [&]() {
14411445
if (builder.try_consume_regex(assistant_regex)) {
14421446
channel();
14431447
} else {
1444-
throw common_chat_msg_parse_exception("expected: <|assistant|>, got: " + consume_until_start());
1448+
throw common_chat_msg_parse_exception("expected: <|assistant|>, got: " + consume_until_next());
14451449
}
14461450
};
14471451

0 commit comments

Comments
 (0)