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

[Feature] Return token usage #188

Open
kieranx opened this issue Jul 31, 2024 · 5 comments
Open

[Feature] Return token usage #188

kieranx opened this issue Jul 31, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@kieranx
Copy link

kieranx commented Jul 31, 2024

In the official OpenAI API, token usage is returned, e.g. "total_tokens": 1340

There seems to be no way to get this same info in LLPhant -- this is very basic stuff and I feel like it should be able to be accessed, given OpenAI do return that info? We can't figure out a way to do that in LLPhant currently however.

Edit: to be clear, this is for the questionanswering class, I know we can get it for the general chat class.

@f-lombardo
Copy link
Contributor

What about

public function getTotalTokens(): int
? Does it fit your needs?

@Vardan9898
Copy link

Is there a way to retrieve the total number of tokens used with Question Answering?

$qa = new QuestionAnswering(
$memoryVectorStore,
$embeddingGenerator,
new OpenAIChat()
);

$answer = $qa->answerQuestion('What is the secret of Alice?');

If not, is it possible to use OpenAIChat with vector-stored embeddings?

@f-lombardo
Copy link
Contributor

f-lombardo commented Aug 1, 2024

Maybe you can try this:

    $chat = new OpenAIChat(new OpenAIConfig());
    $qa = new QuestionAnswering(
        $filesVectorStore,
        $embeddingGenerator,
        $chat
    );

    $response = $qa->answerQuestion('What is the secret of Alice?');

    echo('Total tokens: ' .$chat->getTotalTokens());

@MaximeThoonsen
Copy link
Collaborator

You want the total of token for the question embeddings + all generations?

@MaximeThoonsen MaximeThoonsen added the enhancement New feature or request label Aug 1, 2024
@MaximeThoonsen
Copy link
Collaborator

I started a small PR here.
We need to add the count of embeddings to make it correct

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

No branches or pull requests

4 participants