Send data to an SSE client fd with a short (1s) timeout to avoid stalling the inference worker. Returns false if the send fails or times out.
| 945 | if (arguments.is_string()) { |
| 946 | try { |
| 947 | return json::parse(arguments.get<std::string>()); |
| 948 | } catch (const std::exception &) { |
| 949 | return json::object(); |
| 950 | } |
| 951 | } |
| 952 | return json::object(); |
| 953 | } |
| 954 | |
| 955 | std::string render_tool_call_xml(const std::string & name, const json & arguments) { |
| 956 | std::string out = "<function=" + name + ">\n"; |
| 957 | if (arguments.is_object()) { |
| 958 | for (const auto & [key, value] : arguments.items()) { |
| 959 | out += "<parameter=" + key + ">\n"; |
| 960 | out += value.is_string() ? value.get<std::string>() : value.dump(); |
| 961 | out += "\n</parameter>\n"; |
| 962 | } |
| 963 | } |
| 964 | out += "</function>\n"; |
| 965 | return out; |
| 966 | } |
| 967 | |
| 968 | std::vector<ChatMessage> normalize_chat_messages( |
| 969 | const json & messages, |
| 970 | ApiFormat format, |
| 971 | ToolMemory & tool_memory) { |
| 972 | std::vector<ChatMessage> chat_msgs; |
| 973 | std::vector<std::string> system_parts; |
| 974 | std::vector<std::string> response_call_ids; |
| 975 | std::string response_call_fallback; |
no test coverage detected