Skip to content

How do OpenAI callback handler work ? #7432

Answered by mspronesti
mspronesti asked this question in Q&A
Discussion options

You must be logged in to vote

The correct answer can be found in the "EDIT" part of my question.
More in detail:

  • get_openai_callback sets the value of a context var called openai_context_var to an object of type OpenAICallBackHandler which tracks the token usage and the cost
  • the llms derived from BaseOpenAI create a list of callbacks from the configure method of the CallbackManager object
  • the on_llm_end method of the OpenAICallBackHandler is applied on the generated tokens once the generation is finished to update its the attributes

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mspronesti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant