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

feat: Track costs for streaming with OpenAI #282

Merged
merged 3 commits into from
Jun 3, 2024
Merged

feat: Track costs for streaming with OpenAI #282

merged 3 commits into from
Jun 3, 2024

Conversation

tvj15
Copy link
Contributor

@tvj15 tvj15 commented May 25, 2024

Made changes as discussed on #214.

Now, the user when iterating through the stream can check if cost exists like this:

from mirascope.openai import OpenAICall

class BookRecommender(OpenAICall):
    prompt_template = "Please recommend a {genre} book."

    genre: str


stream = BookRecommender(genre="fantasy").stream()
for chunk in stream:
    print(chunk.content, end="")
    if chunk.cost:
        print(chunk.cost)

@willbakst willbakst requested a review from brenkao May 28, 2024 16:51
@brenkao
Copy link
Collaborator

brenkao commented May 28, 2024

Changes look good! can you update https://docs.mirascope.io/latest/concepts/tracking_costs_for_llm_providers/#cost-tracking-for-streaming to reflect your new updates?

@tvj15
Copy link
Contributor Author

tvj15 commented May 28, 2024

Changes look good! can you update https://docs.mirascope.io/latest/concepts/tracking_costs_for_llm_providers/#cost-tracking-for-streaming to reflect your new updates?

Sure!

@willbakst willbakst self-requested a review May 30, 2024 16:51
Copy link
Contributor

@willbakst willbakst left a comment

Choose a reason for hiding this comment

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

Great work! Thank you for contributing 🙏

@willbakst
Copy link
Contributor

willbakst commented May 31, 2024

@tvj15 can you please merge in current dev? I made a change to the GitHub action for codecov that will hopefully resolve the rate limit failures.

@willbakst
Copy link
Contributor

This closes #214

@tvj15 I tried merging dev into your branch, but I'm running into issues. Did you make sure to check the box for allowing maintainers to submit changes? Wondering if that was un-checked or if there's a separate issue happening.

@tvj15
Copy link
Contributor Author

tvj15 commented Jun 1, 2024

This closes #214

@tvj15 I tried merging dev into your branch, but I'm running into issues. Did you make sure to check the box for allowing maintainers to submit changes? Wondering if that was un-checked or if there's a separate issue happening.

Yes it is turned on. I am not sure of the issue. Shall I raise a new PR into dev?

image

@willbakst
Copy link
Contributor

Hmm, probably an issue on my end then.

For now, can you just merge dev into this PR so I can re-run the workflows?

@tvj15 tvj15 closed this Jun 2, 2024
@tvj15 tvj15 reopened this Jun 2, 2024
Copy link

codecov bot commented Jun 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (13e722d) to head (2ff3640).
Report is 12 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #282    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          138       138            
  Lines         6802      6927   +125     
==========================================
+ Hits          6802      6927   +125     
Flag Coverage Δ
tests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@willbakst willbakst merged commit a9a6d88 into Mirascope:dev Jun 3, 2024
8 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