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

Track costs for streaming with Cohere #218

Open
brenkao opened this issue May 7, 2024 · 5 comments
Open

Track costs for streaming with Cohere #218

brenkao opened this issue May 7, 2024 · 5 comments
Assignees
Labels
Feature Request New feature or request good first issue Good for newcomers

Comments

@brenkao
Copy link
Collaborator

brenkao commented May 7, 2024

Is your feature request related to a problem? Please describe.
Many providers are starting to add usage to streaming. This makes it much easier for Mirascope to calculate cost.

Describe the solution you'd like
Add a total_cost property to CohereCallResponseChunk. Read the "event_type": "stream-end" sent by Cohere API and calculate cost using

"token_count": {
    "prompt_tokens": ...,
    "response_tokens": ...,
    "total_tokens": ...,
    "billed_tokens": ...,
}

Update https://github.com/Mirascope/mirascope/blob/dev/mirascope/cohere/utils.py as necessary.

@brenkao brenkao added Feature Request New feature or request good first issue Good for newcomers labels May 7, 2024
@willbakst willbakst changed the title Cost tracking for streaming Cohere Feature Request: Track costs for streaming with Cohere May 8, 2024
@willbakst
Copy link
Contributor

willbakst commented May 8, 2024

See #214 since these are related.

Namely: #214 (comment)

@willbakst willbakst changed the title Feature Request: Track costs for streaming with Cohere [FEATURE REQUEST] Track costs for streaming with Cohere May 8, 2024
@willbakst willbakst changed the title [FEATURE REQUEST] Track costs for streaming with Cohere Track costs for streaming with Cohere May 10, 2024
@tvj15
Copy link
Contributor

tvj15 commented May 31, 2024

Is your feature request related to a problem? Please describe. Many providers are starting to add usage to streaming. This makes it much easier for Mirascope to calculate cost.

Describe the solution you'd like Add a total_cost property to CohereCallResponseChunk. Read the "event_type": "stream-end" sent by Cohere API and calculate cost using

"token_count": {
    "prompt_tokens": ...,
    "response_tokens": ...,
    "total_tokens": ...,
    "billed_tokens": ...,
}

Update https://github.com/Mirascope/mirascope/blob/dev/mirascope/cohere/utils.py as necessary.

I am working on this but the problem I am facing is that event returned by co.chat_stream() is of type StreamedChatResponse and it's response property is of type NonStreamedChatResponse which does not have token_count property in it. I am not sure how do I access the token_count here.

@willbakst
Copy link
Contributor

Doesn't the NonStreamedChatResponse type have response.meta.billed_units, which return ApiMetaBilledUnits from which we should be able to grab the same usage statistics that we do for the normal response? We can likely massage that data into the form we need to calculate cost, right?

@willbakst willbakst added this to the v0.16 milestone Jun 1, 2024
@tvj15
Copy link
Contributor

tvj15 commented Jun 1, 2024

Doesn't the NonStreamedChatResponse type have response.meta.billed_units, which return ApiMetaBilledUnits from which we should be able to grab the same usage statistics that we do for the normal response? We can likely massage that data into the form we need to calculate cost, right?

Yes, it does, but according to the API docs, the streamed response has no meta.billed_units property. I does have token_count though. I can look again at what is happening on the API side and update here.

@brenkao
Copy link
Collaborator Author

brenkao commented Jun 7, 2024

This is partially implemented with #307 where Cohere chunks will contain input_tokens and output_tokens which can be used to calculate cost. The only thing remaining that will need to be done is to pass cost into CohereCallResponseChunk.

@willbakst willbakst removed this from the v0.17 milestone Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants