langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.79k stars 15.12k forks source link

```get_openai_callback``` doesn't track the token usage for AzureOpenAIEmbeddings #25888

Open AsifMehmood97 opened 1 month ago

AsifMehmood97 commented 1 month ago

Checked other resources

Example Code

AzureOpenAIEmbeddings returns token usage:

{
    "object": "list",
    "data": [
        {
            "object": "embedding",
            "index": 0,
            "embedding": [...]
        }
    ],
    "model": "text-embedding-ada-002",
    "usage": {
        "prompt_tokens": 823,
        "total_tokens": 823
    }
}

However get_openai_callback is not tracking it:

Tokens Used: 0
Prompt Tokens: 0
Completion Tokens: 0
Successful Requests: 0
Total Cost (USD): $0.0

Error Message and Stack Trace (if applicable)

No response

Description

I am tracking the tokens and cost usage for my application in the database, I can track the usage of the token for AzureOpenAI using get_openai_callback however it is not tracking the token usage for Embeddings.

System Info

langchain_openai==0.1.17
langchain==0.2.9
langchain-community==0.2.7
ElhamBadri2411 commented 2 weeks ago

Hey, I was wondering if I could take a look at this issue