How to wrap AzureOpenAIEmbeddings to emit custom events with number of input_tokens? #28477
ai-learner-00
started this conversation in
General
Replies: 1 comment
-
To achieve this, you can create a wrapper class around AzureOpenAIEmbeddings. The wrapper will calculate token usage using tiktoken, emit custom events like llm_start and llm_end before and after calling the embedding method, and delegate the actual embedding process to the original class. Since AzureOpenAIEmbeddings doesn’t have a callbacks parameter, you need to handle the event dispatching manually by emitting events using adispatch_custom_event within the wrapper. This approach allows you to track metrics (like token counts) and integrate with LangChain’s callback system without modifying the base class. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Since there are no callbacks for embeddings Total token count of openai callback does not count embedding usage, I am trying to emit a custom event that will include
input_tokens: int
calculated by tiktoken.How should I approach wrapping the AzureOpenAIEmbeddings class to emit events similar to llm_start and llm_end? I realized it doesn't even have a
callbacks
parameter.Beta Was this translation helpful? Give feedback.
All reactions