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 openai usage info for non-streaming response #399

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

aniketmaurya
Copy link
Collaborator

@aniketmaurya aniketmaurya commented Dec 18, 2024

What does this PR do?

Aggregate the usage_info for all the generations properly in case of non-streaming response.

In current main branch, UsageInfo for the following code will return completion tokens=1 which is incorrect and it should aggregate all the usage infos. This PR fixes that.

class OpenAIWithUsagePerToken(ls.LitAPI):
    def setup(self, device):
        self.model = None

    def predict(self, x):
        for i in range(1, 6):
            yield {
                "role": "assistant",
                "content": f"{i}",
                "prompt_tokens": 0,
                "completion_tokens": 1,
                "total_tokens": 1,
            }
Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 92%. Comparing base (636c9fd) to head (af39d42).
Report is 1 commits behind head on main.

Additional details and impacted files
@@         Coverage Diff         @@
##           main   #399   +/-   ##
===================================
  Coverage    91%    92%           
===================================
  Files        25     25           
  Lines      1782   1783    +1     
===================================
+ Hits       1627   1632    +5     
+ Misses      155    151    -4     

@aniketmaurya aniketmaurya enabled auto-merge (squash) December 18, 2024 12:55
@aniketmaurya aniketmaurya merged commit f28c816 into main Dec 18, 2024
19 of 20 checks passed
@aniketmaurya aniketmaurya deleted the aniket/fix-oai-usageinfo branch December 18, 2024 12:57
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.

2 participants