Skip to content

Commit 3340927

Browse files
committed
use try_consume_json_with_dumped_args()
1 parent 08bb798 commit 3340927

File tree

2 files changed

+5
-93
lines changed

2 files changed

+5
-93
lines changed

common/chat.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,11 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
13871387
auto tool_call = [&]() {
13881388
if (auto res = builder.try_consume_regex(user_tool_call_regex)) {
13891389
auto name = builder.str(res->groups[1]);
1390-
auto args = builder.consume_rest();
1391-
builder.add_tool_call(name, "", args);
1390+
if (auto args = builder.try_consume_json_with_dumped_args({{}})) {
1391+
if (!builder.add_tool_call(name, "", args->value) || args->is_partial) {
1392+
throw common_chat_msg_partial_exception("incomplete tool call");
1393+
}
1394+
}
13921395
} else if (builder.try_consume_regex(builtin_tool_call_regex)) {
13931396
builder.consume_rest();
13941397
LOG_ERR("builtin tool calls not implemented\n");

tests/test-chat.cpp

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,87 +1606,6 @@ static void test_template_output_parsers() {
16061606
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
16071607
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
16081608
}));
1609-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking"),
1610-
common_chat_parse(
1611-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1612-
"<|start|>assistant<|channel|>commentary to=",
1613-
/* is_partial= */ true,
1614-
{
1615-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1616-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1617-
}));
1618-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking"),
1619-
common_chat_parse(
1620-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1621-
"<|start|>assistant<|channel|>commentary to=func",
1622-
/* is_partial= */ true,
1623-
{
1624-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1625-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1626-
}));
1627-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking"),
1628-
common_chat_parse(
1629-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1630-
"<|start|>assistant<|channel|>commentary to=functions.",
1631-
/* is_partial= */ true,
1632-
{
1633-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1634-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1635-
}));
1636-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking"),
1637-
common_chat_parse(
1638-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1639-
"<|start|>assistant<|channel|>commentary to=functions.special_",
1640-
/* is_partial= */ true,
1641-
{
1642-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1643-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1644-
}));
1645-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking"),
1646-
common_chat_parse(
1647-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1648-
"<|start|>assistant<|channel|>commentary to=functions.special_function",
1649-
/* is_partial= */ true,
1650-
{
1651-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1652-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1653-
}));
1654-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking"),
1655-
common_chat_parse(
1656-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1657-
"<|start|>assistant<|channel|>commentary to=functions.special_function <|constrain|>",
1658-
/* is_partial= */ true,
1659-
{
1660-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1661-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1662-
}));
1663-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking"),
1664-
common_chat_parse(
1665-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1666-
"<|start|>assistant<|channel|>commentary to=functions.special_function <|constrain|>json",
1667-
/* is_partial= */ true,
1668-
{
1669-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1670-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1671-
}));
1672-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking", "special_function", ""),
1673-
common_chat_parse(
1674-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1675-
"<|start|>assistant<|channel|>commentary to=functions.special_function <|constrain|>json<|message|>",
1676-
/* is_partial= */ true,
1677-
{
1678-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1679-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1680-
}));
1681-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking", "special_function", ""),
1682-
common_chat_parse(
1683-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1684-
"<|start|>assistant<|channel|>commentary to=functions.special_function <|message|>",
1685-
/* is_partial= */ true,
1686-
{
1687-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1688-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1689-
}));
16901609
assert_msg_equals(simple_assist_msg("", "I'm\nthinking", "special_function", "{\"arg1"),
16911610
common_chat_parse(
16921611
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
@@ -1705,15 +1624,6 @@ static void test_template_output_parsers() {
17051624
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
17061625
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
17071626
}));
1708-
assert_msg_equals(simple_assist_msg("", "I'm\nthinking", "special_function", "{\"arg1\": 1}"),
1709-
common_chat_parse(
1710-
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
1711-
"<|start|>assistant<|channel|>commentary to=functions.special_function <|constrain|>json<|message|>{\"arg1\": 1}",
1712-
/* is_partial= */ true,
1713-
{
1714-
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
1715-
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
1716-
}));
17171627
assert_msg_equals(simple_assist_msg("", "I'm\nthinking", "special_function", "{\"arg1\": 1}"),
17181628
common_chat_parse(
17191629
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"
@@ -1723,7 +1633,6 @@ static void test_template_output_parsers() {
17231633
/* .format = */ COMMON_CHAT_FORMAT_GPT_OSS,
17241634
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
17251635
}));
1726-
17271636
assert_msg_equals(simple_assist_msg("Hello, world!\nWhat's up?", "I'm\nthinking"),
17281637
common_chat_parse(
17291638
"<|channel|>analysis<|message|>I'm\nthinking<|end|>"

0 commit comments

Comments
 (0)