MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / tokens_to_output_formatted_string

Function tokens_to_output_formatted_string

examples/server/server.cpp:294–307  ·  view source on GitHub ↗

format incomplete utf-8 multibyte character for output

Source from the content-addressed store, hash-verified

292
293// format incomplete utf-8 multibyte character for output
294static 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
310static json probs_vector_to_json(const llama_context *ctx, const std::vector<completion_token_output> &probs)

Callers 2

probs_vector_to_jsonFunction · 0.70
process_tokenMethod · 0.70

Calls 3

llama_token_to_pieceFunction · 0.50
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected