MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / common_chat_parse_command_r7b

Function common_chat_parse_command_r7b

smallthinker/common/chat.cpp:1001–1032  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

999}
1000
1001static void common_chat_parse_command_r7b(common_chat_msg_parser & builder) {
1002 builder.try_parse_reasoning("<|START_THINKING|>", "<|END_THINKING|>");
1003
1004 static const common_regex start_action_regex("<\\|START_ACTION\\|>");
1005 static const common_regex end_action_regex("<\\|END_ACTION\\|>");
1006 static const common_regex start_response_regex("<\\|START_RESPONSE\\|>");
1007 static const common_regex end_response_regex("<\\|END_RESPONSE\\|>");
1008
1009 if (auto res = builder.try_find_regex(start_action_regex)) {
1010 // If we didn't extract thoughts, prelude includes them.
1011 auto tool_calls = builder.consume_json_with_dumped_args({{"parameters"}});
1012 for (const auto & tool_call : tool_calls.value) {
1013 std::string name = tool_call.contains("tool_name") ? tool_call.at("tool_name") : "";
1014 std::string id = tool_call.contains("tool_call_id") ? tool_call.at("tool_call_id") : "";
1015 std::string arguments = tool_call.contains("parameters") ? tool_call.at("parameters") : "";
1016 if (!builder.add_tool_call(name, id, arguments) || tool_calls.is_partial) {
1017 throw common_chat_msg_partial_exception("incomplete tool call");
1018 }
1019 }
1020 if (tool_calls.is_partial) {
1021 throw common_chat_msg_partial_exception("incomplete tool call");
1022 }
1023 builder.consume_regex(end_action_regex);
1024 } else if (auto res = builder.try_find_regex(start_response_regex)) {
1025 if (!builder.try_find_regex(end_response_regex)) {
1026 builder.add_content(builder.consume_rest());
1027 throw common_chat_msg_partial_exception(end_response_regex.str());
1028 }
1029 } else {
1030 builder.add_content(builder.consume_rest());
1031 }
1032}
1033
1034static void expect_tool_parameters(const std::string & name, const json & parameters, const std::vector<std::string> & expected_properties) {
1035 if (!parameters.is_object() || !parameters.contains("type") || parameters.at("type") != "object" || !parameters.contains("properties") || !parameters.contains("required")) {

Callers 1

common_chat_parseFunction · 0.85

Calls 9

try_parse_reasoningMethod · 0.80
try_find_regexMethod · 0.80
add_tool_callMethod · 0.80
consume_regexMethod · 0.80
add_contentMethod · 0.80
consume_restMethod · 0.80
strMethod · 0.45

Tested by

no test coverage detected