Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] modify the code for output formatter schema #2614

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions serving/docs/lmi/user_guides/output_formatter_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ It's crucial to understand how your custom output formatter will be called befor
## Example
Here is an example of a custom output formatter:
```python
from djl_python.output_formatter import TextGenerationOutput, output_formatter
from djl_python.request_io import TextGenerationOutput
from djl_python.output_formatter import output_formatter
import json

@output_formatter
Expand All @@ -102,7 +103,9 @@ def custom_output_formatter(request_output: TextGenerationOutput) -> str:
"""
best_sequence = request_output.sequences[request_output.best_sequence_index]
next_token, is_first_token, is_last_token = best_sequence.get_next_token()
result = {"token_id": next_token.id, "token_text": next_token.text, "token_log_prob": next_token.log_prob}
result = {}
if next_token:
result = {"token_id": next_token.id, "token_text": next_token.text, "token_log_prob": next_token.log_prob}
if is_last_token:
result["finish_reason"] = best_sequence.finish_reason
return json.dumps(result) + "\n"
Expand Down