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

Function probs_vector_to_json

examples/server/server.cpp:310–332  ·  view source on GitHub ↗

convert a vector of completion_token_output to json

Source from the content-addressed store, hash-verified

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)
311{
312 json out = json::array();
313 for (const auto &prob : probs)
314 {
315 json probs_for_token = json::array();
316 for (const auto &p : prob.probs)
317 {
318 std::string tok_str = tokens_to_output_formatted_string(ctx, p.tok);
319 probs_for_token.push_back(json
320 {
321 {"tok_str", tok_str},
322 {"prob", p.prob},
323 });
324 }
325 std::string tok_str = tokens_to_output_formatted_string(ctx, prob.tok);
326 out.push_back(json{
327 {"content", tok_str},
328 {"probs", probs_for_token},
329 });
330 }
331 return out;
332}
333
334template <typename T>
335static T json_value(const json &body, const std::string &key, const T &default_value)

Callers 9

to_json_non_oaicompatMethod · 0.85
to_json_oaicompatMethod · 0.85
to_json_non_oaicompatMethod · 0.85
to_json_oaicompatMethod · 0.85
send_partial_responseMethod · 0.85
send_final_responseMethod · 0.85
format_partial_responseFunction · 0.85

Calls 2

push_backMethod · 0.45

Tested by

no test coverage detected