convert a vector of completion_token_output to json
| 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) |
| 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 | |
| 334 | template <typename T> |
| 335 | static T json_value(const json &body, const std::string &key, const T &default_value) |
no test coverage detected