Skip to content

Total token count of openai callback does not count embedding usage #945

@tmbo

Description

@tmbo

When using embeddings, the total_tokens count of a callback is wrong, e.g. the following example currently returns 0 even though it shouldn't:

from langchain.callbacks import get_openai_callback

with get_openai_callback() as cb:
    embeddings = OpenAIEmbeddings()
    embeddings.embed_query("helo")
    print(cb.total_tokens)

IMO this is confusing (and there is no way to get the cost from the embeddings class at the moment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions