agentic icon indicating copy to clipboard operation
agentic copied to clipboard

How to get the usage of "CompletionResponseUsage" returned by OpenAI API?

Open HttpStatusOK opened this issue 2 years ago • 1 comments

Describe the feature

like prompt_tokens、completion_tokens and total_tokens

At present, I can only get these parameters: { role: 'assistant', id: 'cmpl-6hu42pXvZhCYuEmifKobRHYrJfOu6', parentMessageId: '504ce20d-ac0f-4cf8-83dc-013cb4fb172f', conversationId: '6c868ac8-465c-42cc-96d7-deef6b4a54d5', text: 'hi!' }

HttpStatusOK avatar Feb 09 '23 05:02 HttpStatusOK

I think this is a good idea; we should add this extra metadata to a detail attribute on the returned json.

transitive-bullshit avatar Feb 09 '23 19:02 transitive-bullshit

@HttpStatusOK responses now include a detail property which includes the full OpenAI response, so you should have access to the usage info. Upgrade to latest to see the change.

transitive-bullshit avatar Feb 14 '23 07:02 transitive-bullshit

@HttpStatusOKresponses 现在包含一个detail包含完整 OpenAI 响应的属性,因此您应该可以访问使用信息。升级到最新版本以查看更改。

您好 ,我升级到5.0.10。还是没有发现 prompt_tokens、completion_tokens total_tokens 这三个参数.

我在非stream的模式下看到了这三个参数,但是我想在stream的时候也能得到这三个参数 请问我应该如何做

Huxiaoyou97 avatar Mar 13 '23 11:03 Huxiaoyou97

@MyJacking Does the detail property of the result object not contain this info for you in stream mode?

Can you include a code example of how you're calling sendMessage?

transitive-bullshit avatar Mar 13 '23 12:03 transitive-bullshit

@transitive-bullshit stream mode currently does not include prompt_tokens, completion_tokens, and total_tokens. Would it be possible to add these features?

GeorgeGalway avatar Mar 16 '23 08:03 GeorgeGalway