Skip to content

Commit fd4cf34

Browse files
committed
"top_probs" with "post_sampling_probs"
1 parent 8734df7 commit fd4cf34

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

examples/server/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,12 @@ These words will not be included in the completion, so make sure to add them to
497497
```
498498
Please note that if `post_sampling_probs` is set to `true`:
499499
- `logprob` will be replace with `prob`, with the value between 0.0 and 1.0
500-
- Returned number of probabilities may be less than `n_probs`
500+
- `top_logprobs` will be replace with `top_probs`. Each element inside contains:
501+
- `id`: token ID
502+
- `token`: token in string
503+
- `bytes`: token in bytes
504+
- `prob`: token probability, with the value between 0.0 and 1.0
505+
- Number of elements in `top_probs` may be less than `n_probs`
501506

502507
- `content`: Completion result as a string (excluding `stopping_word` if any). In case of streaming mode, will contain the next token as a string.
503508
- `tokens`: Same as `content` but represented as raw token ids. Only populated if `"return_tokens": true` or `"stream": true` in the request.

examples/server/server.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,10 @@ struct completion_token_output {
475475
{"id", it.tok},
476476
{"token", tok_str},
477477
{"bytes", str_to_bytes(it.text_to_send)},
478-
{"top_logprobs", it.to_json(post_sampling_probs)},
478+
{
479+
post_sampling_probs ? "top_probs" : "top_logprobs",
480+
it.to_json(post_sampling_probs)
481+
},
479482
{
480483
post_sampling_probs ? "prob" : "logprob",
481484
post_sampling_probs ? it.prob : logarithm(it.prob)

examples/server/tests/unit/test_completion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ def test_n_probs_post_sampling():
327327
assert "token" in tok and type(tok["token"]) == str
328328
assert "prob" in tok and 0.0 <= tok["prob"] <= 1.0
329329
assert "bytes" in tok and type(tok["bytes"]) == list
330-
assert len(tok["top_logprobs"]) == 10
331-
for prob in tok["top_logprobs"]:
330+
assert len(tok["top_probs"]) == 10
331+
for prob in tok["top_probs"]:
332332
assert "id" in prob and prob["id"] > 0
333333
assert "token" in prob and type(prob["token"]) == str
334334
assert "prob" in prob and 0.0 <= prob["prob"] <= 1.0

0 commit comments

Comments
 (0)