Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to grab total token usage from response #597

Open
2 tasks done
nchan1994 opened this issue Jul 9, 2023 · 0 comments
Open
2 tasks done

How to grab total token usage from response #597

nchan1994 opened this issue Jul 9, 2023 · 0 comments

Comments

@nchan1994
Copy link

Verify latest release

  • I verified that the issue exists in the latest chatgpt release

Verify webapp is working

  • I verify that the ChatGPT webapp is working properly for this account.

Environment details

Typescript, Visual Studio Code

Describe the Bug

Not a bug, but hoping to get some guidance.

Not very familiar with Typescript, but hoping to make a couple of changes to pre-existing code using this awesome ChatGPT API.

I want to grab and store the token usage for each prompt and response to and from openai. But idk how to grab the token response. The code snippet I have is below:

public async callOpenAI(prompt: string, messageId: string): Promise<any> {
    console.log('mid:' + messageId)

    if (messageId == '') {
      const res = await oraPromise(this.api.sendMessage(prompt), 
        {
        text: prompt,
      })
      return res
    } else {
      const res = await oraPromise(
        this.api.sendMessage(prompt, {
          parentMessageId: messageId
        }),
        {
          text: prompt,
        }
      )
      return res
    }
  }
}

Would be great if someone could tell me how I can edit/add to this so I can get the token usage. I read through some of the issues and someone recommended looking at 'details'? Where would I add this because I tried several ways doesn't seem to work.

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant