langchainjs icon indicating copy to clipboard operation
langchainjs copied to clipboard

TokenUsage missing from LLMResult when modelName is defined

Open miekassu opened this issue 2 years ago • 1 comments

When I define gpt-3.5-turbo as the model for OpenAI construct, llmOutput is missing tokenUsage object.

Using the same construct, but not defining the model returns token usage as part of llmOutput on the callback.

Not working:

  const model = new OpenAI({
    openAIApiKey: openAISecret,
    modelName: 'gpt-3.5-turbo',
    callbacks: [
      {
        handleLLMEnd: async (output: LLMResult) => {
          logger.info('output', { output })
          logger.info('tokenUsage', { tokenUsage: output.llmOutput })
          // tokenUsage: UNDEFINED
        },
      },
    ],
  })

Working:

  const model = new OpenAI({
    openAIApiKey: openAISecret,
    callbacks: [
      {
        handleLLMEnd: async (output: LLMResult) => {
          logger.info('output', { output })
          logger.info('tokenUsage', { tokenUsage: output.llmOutput })
          // tokenUsage: found
        },
      },
    ],
  })

Maybe relates to #965

miekassu avatar Apr 28 '23 08:04 miekassu

Yep, relates to #965

theTechGoose avatar Apr 29 '23 17:04 theTechGoose

Hi, @miekassu! I'm here to help the LangChain team manage their backlog, and I wanted to let you know that we are marking this issue as stale.

From what I understand, you opened this issue regarding the missing tokenUsage object in the llmOutput when defining the gpt-3.5-turbo model for the OpenAI construct. It seems that theTechGoose also commented on the issue, confirming that it is related to issue #965.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the LangChain project!

dosubot[bot] avatar Aug 18 '23 16:08 dosubot[bot]