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

Include usage information in LengthFinishReasonError #1700

Closed
1 task done
dabure opened this issue Sep 10, 2024 · 1 comment · Fixed by #1701
Closed
1 task done

Include usage information in LengthFinishReasonError #1700

dabure opened this issue Sep 10, 2024 · 1 comment · Fixed by #1701
Labels
enhancement New feature or request

Comments

@dabure
Copy link

dabure commented Sep 10, 2024

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • This is a feature request for the Python library

Describe the feature or improvement you're requesting

Situation
When calling AsyncOpenAI(...).beta.chat.completions.parse(..., response_format=SomePydanticModel), the OpenAI library raises LengthFinishReasonError when finish_reason == "length" and raises ContentFilterFinishReasonError when finish_reason == "content_filter", without providing any information as to what the response contained.

Complication
Because there is no way to retrieve any information about the response, I cannot programmatically save information about the context. For example, I cannot access and track information from the usage object in the chat completion response.

Desired behavior
As a library user, I always want to know details about responses from LLM calls that costs tokens for me. More specifically, I want to inspect usage to know how many tokens I "wasted" calling the LLM, for instance when max_tokens was set to a too low value for the LLM to generate a complete structured output. This enables me to track and control costs.

I see two potential solutions:

  1. Stop raising exceptions for these scenarios and always return a chat completion object. I believe this is the behavior in the non-beta version of the chat completion call
  2. Return the response as an attribute in the exception object so that it can be used by the calling programmer

Version used

  • 1.44.1 (latest on PyPI at the time of writing)

Code location

Additional context

No response

@dabure dabure changed the title beta.chat.completion.parse call raises LengthFinishReasonError upon length error beta.chat.completion.parse(...) raises LengthFinishReasonError upon length error Sep 10, 2024
@dabure dabure changed the title beta.chat.completion.parse(...) raises LengthFinishReasonError upon length error When beta.chat.completion.parse(...) raises LengthFinishReasonError, context about the response should be included Sep 10, 2024
@dabure dabure changed the title When beta.chat.completion.parse(...) raises LengthFinishReasonError, context about the response should be included When beta.chat.completion.parse(...) raises LengthFinishReasonError, it would be useful to include context about the underlying response Sep 10, 2024
@RobertCraigie RobertCraigie changed the title When beta.chat.completion.parse(...) raises LengthFinishReasonError, it would be useful to include context about the underlying response Include usage information in LengthFinishReason Sep 10, 2024
@RobertCraigie RobertCraigie changed the title Include usage information in LengthFinishReason Include usage information in LengthFinishReasonError Sep 10, 2024
@RobertCraigie RobertCraigie added the enhancement New feature or request label Sep 10, 2024
@RobertCraigie
Copy link
Collaborator

This will be fixed in the next release! #1701

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants