Skip to content

Capture usage tokens coming from provider (openai) when streaming #940

Description

@Castorche

OpenAI offers the option, when streaming, to get a last chunk with the token usage for the entire request: https://developers.openai.com/api/reference/resources/chat#(resource)%20chat.completions%20%3E%20(model)%20chat_completion_chunk%20%3E%20(schema)%20%3E%20(property)%20usage .

It would be nice to use this when available, with a fallback to the current implementation (estimating the number of tokens used).
I will propose a PR to address this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions