openai-java icon indicating copy to clipboard operation
openai-java copied to clipboard

about tokens

Open Crow9527 opened this issue 3 years ago • 5 comments

May I ask if it is possible to add the number of tokens returned by chatGPT, which can facilitate the counting of the number of tokens I have already used and avoid exceeding the token length and causing errors

Crow9527 avatar Apr 06 '23 14:04 Crow9527

(CompletionResult) completion.getUsage() .getPromptTokens() or .getCompletionTokens() or .getTotalTokens()

cryptoapebot avatar Apr 06 '23 15:04 cryptoapebot

I am using OpenAiService. streamChatCompletion(), which returns ChatCompletionChunk without statistics on tokens

Crow9527 avatar Apr 06 '23 15:04 Crow9527

Understood. Maybe clarify issue name as a feature request? Thx.

cryptoapebot avatar Apr 06 '23 15:04 cryptoapebot

@Crow9527

Currently the streaming OpenAi API does not return any statistics on tokens.

n3bul4 avatar Apr 22 '23 13:04 n3bul4

(CompletionResult) completion.getUsage().getTotalTokens()

lucklilili avatar May 08 '23 04:05 lucklilili