| 27 | } |
| 28 | |
| 29 | static std::string string_diff(const std::string & last, const std::string & current) { |
| 30 | if (last.empty()) { |
| 31 | return current; |
| 32 | } |
| 33 | if (!string_starts_with(current, last)) { |
| 34 | if (string_starts_with(last, current)) { |
| 35 | // This happens if the last generation ended on a partial stop word (not erased), |
| 36 | // and the current ended on a stop word (erased). |
| 37 | return ""; |
| 38 | } |
| 39 | throw std::runtime_error("Invalid diff: '" + last + "' not found at start of '" + current + "'"); |
| 40 | } |
| 41 | return current.substr(last.size()); |
| 42 | } |
| 43 | |
| 44 | static bool has_content_or_tool_calls(const common_chat_msg & msg) { |
| 45 | return !msg.content.empty() || !msg.tool_calls.empty(); |
no test coverage detected