Skip to content

Commit ab25e3f

Browse files
author
ochafik
committed
tool-call: allow empty message content when there's tool_calls in format_chat
1 parent d928ff4 commit ab25e3f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

examples/server/utils.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ inline std::string format_chat(const struct llama_model * model, const std::stri
7777
msg.content += "\n" + part["text"].get<std::string>();
7878
}
7979
}
80-
} else {
81-
throw std::runtime_error("Invalid 'content' type (ref: https://github.com/ggerganov/llama.cpp/issues/8367)");
80+
} else if (!(curr_msg.is_null() && curr_msg.contains("tool_calls"))) {
81+
throw std::runtime_error("Invalid 'content' type (ref: https://github.com/ggerganov/llama.cpp/issues/8367): " + curr_msg.dump());
8282
}
8383
} else {
8484
throw std::runtime_error("Missing 'content' (ref: https://github.com/ggerganov/llama.cpp/issues/8367)");
@@ -474,6 +474,7 @@ static json format_final_response_oaicompat(const json & request, const json & r
474474
auto tools = json_value(request, "tools", json::array());
475475
json tool_calls;
476476
json message_content;
477+
printf("# CONTENT: %s\n\n", content.c_str());
477478
if (json_value(request, "parse_tool_calls", false)
478479
&& !(parsed_tool_calls = parse_tool_calls(tools, chat_template, content)).tool_calls.empty()) {
479480
finish_reason = "tool";
@@ -513,6 +514,7 @@ static json format_final_response_oaicompat(const json & request, const json & r
513514
}},
514515
{"id", completion_id}
515516
};
517+
printf("# RES: %s\n\n", res.dump(2).c_str());
516518

517519
// extra fields for debugging purposes
518520
if (verbose) {

0 commit comments

Comments
 (0)