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