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

fix: handle optional usage field in OpenAI API #47

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

drewrip
Copy link
Contributor

@drewrip drewrip commented Jun 7, 2024

The usage field that is returned in the completion object is optional and will cause errors in runtimes that do not include it. In particular I noticed this in the runtime that instructlab uses.

OpenAI API docs for the completion object

@drewrip drewrip changed the title OpenAI API: handle optional usage field fix: handle optional usage field in OpenAI API Jun 7, 2024
# total tokens before the timeout will be equal to the total tokens in the response.
if not result.output_tokens_before_timeout:
result.output_tokens_before_timeout = result.output_tokens
result.stop_reason = message["choices"][0]["finish_reason"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might wanna do the same (.get) for choices

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

@dagrayvid dagrayvid merged commit 8d64d85 into openshift-psap:main Jun 26, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants