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

[python] fix last token fetch logic #2423

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions engines/python/setup/djl_python/output_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from djl_python.request_io import TextGenerationOutput
from djl_python.utils import wait_till_generation_finished

ERR_MSG = "Inference error occurred. Check CloudWatch metrics or model server logs for more details."


def output_formatter(function):
"""
Expand Down Expand Up @@ -122,7 +120,7 @@ def _json_output_formatter(request_output: TextGenerationOutput):
# partial generation response that may exist
result = {
"generated_text": None,
"error": final_token.error_msg if final_token else ERR_MSG,
"error": final_token.error_msg,
"code": 400,
"details": details,
}
Expand Down
2 changes: 1 addition & 1 deletion engines/python/setup/djl_python/request_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def get_next_token(self) -> (Token, bool, bool):
return None, False, False

def get_last_token(self) -> Optional[Token]:
if self._last_token_index:
if self._last_token_index is not None:
return self.tokens[self._last_token_index]
return None

Expand Down
Loading