| 52 | } |
| 53 | |
| 54 | static std::string string_diff(const std::string & last, const std::string & current) { |
| 55 | if (last.empty()) { |
| 56 | return current; |
| 57 | } |
| 58 | if (!string_starts_with(current, last)) { |
| 59 | if (string_starts_with(last, current)) { |
| 60 | // This happens if the last generation ended on a partial stop word (not erased), |
| 61 | // and the current ended on a stop word (erased). |
| 62 | return ""; |
| 63 | } |
| 64 | throw std::runtime_error("Invalid diff: '" + last + "' not found at start of '" + current + "'"); |
| 65 | } |
| 66 | return current.substr(last.size()); |
| 67 | } |
| 68 | |
| 69 | static bool has_content_or_tool_calls(const common_chat_msg & msg) { |
| 70 | return !msg.content.empty() || !msg.tool_calls.empty(); |
no test coverage detected