format incomplete utf-8 multibyte character for output
| 292 | |
| 293 | // format incomplete utf-8 multibyte character for output |
| 294 | static std::string tokens_to_output_formatted_string(const llama_context *ctx, const llama_token token) |
| 295 | { |
| 296 | std::string out = token == -1 ? "" : llama_token_to_piece(ctx, token); |
| 297 | // if the size is 1 and first bit is 1, meaning it's a partial character |
| 298 | // (size > 1 meaning it's already a known token) |
| 299 | if (out.size() == 1 && (out[0] & 0x80) == 0x80) |
| 300 | { |
| 301 | std::stringstream ss; |
| 302 | ss << std::hex << (out[0] & 0xff); |
| 303 | std::string res(ss.str()); |
| 304 | out = "byte: \\x" + res; |
| 305 | } |
| 306 | return out; |
| 307 | } |
| 308 | |
| 309 | // convert a vector of completion_token_output to json |
| 310 | static json probs_vector_to_json(const llama_context *ctx, const std::vector<completion_token_output> &probs) |
no test coverage detected