| 682 | } |
| 683 | |
| 684 | json completion_token_output::probs_vector_to_json(const std::vector<completion_token_output> & probs, bool post_sampling_probs) { |
| 685 | json out = json::array(); |
| 686 | for (const auto & p : probs) { |
| 687 | std::string txt(p.text_to_send); |
| 688 | txt.resize(validate_utf8(txt)); |
| 689 | out.push_back(json { |
| 690 | {"id", p.tok}, |
| 691 | {"token", txt}, |
| 692 | {"bytes", str_to_bytes(p.text_to_send)}, |
| 693 | { |
| 694 | post_sampling_probs ? "prob" : "logprob", |
| 695 | post_sampling_probs ? p.prob : logarithm(p.prob) |
| 696 | }, |
| 697 | { |
| 698 | post_sampling_probs ? "top_probs" : "top_logprobs", |
| 699 | p.to_json(post_sampling_probs) |
| 700 | }, |
| 701 | }); |
| 702 | } |
| 703 | return out; |
| 704 | } |
| 705 | |
| 706 | float completion_token_output::logarithm(float x) { |
| 707 | // nlohmann::json converts -inf to null, so we need to prevent that |
nothing calls this directly
no test coverage detected