File tree Expand file tree Collapse file tree 5 files changed +71
-3
lines changed
main/java/com/theokanning/openai
service/src/test/java/com/theokanning/openai/service Expand file tree Collapse file tree 5 files changed +71
-3
lines changed Original file line number Diff line number Diff line change 1+ package com .theokanning .openai ;
2+
3+ import com .fasterxml .jackson .annotation .JsonProperty ;
4+ import lombok .Data ;
5+
6+ /**
7+ * Breakdown of tokens used in a completion.
8+ */
9+ @ Data
10+ public class CompletionTokensDetails {
11+
12+ @ JsonProperty ("reasoning_tokens" )
13+ long reasoningTokens ;
14+
15+ @ JsonProperty ("audio_tokens" )
16+ long audioTokens ;
17+
18+ @ JsonProperty ("accepted_prediction_tokens" )
19+ long acceptedPredictionTokens ;
20+
21+ @ JsonProperty ("rejected_prediction_tokens" )
22+ long rejectedPredictionTokens ;
23+ }
Original file line number Diff line number Diff line change 1+ package com .theokanning .openai ;
2+
3+ import com .fasterxml .jackson .annotation .JsonProperty ;
4+ import lombok .Data ;
5+
6+ /**
7+ * Breakdown of tokens used in the prompt.
8+ */
9+ @ Data
10+ public class PromptTokensDetails {
11+ /**
12+ * Cached tokens present in the prompt.
13+ */
14+ @ JsonProperty ("cached_tokens" )
15+ long cachedTokens ;
16+
17+ /**
18+ * Audio input tokens present in the prompt.
19+ */
20+ @ JsonProperty ("audio_tokens" )
21+ long audioTokens ;
22+ }
Original file line number Diff line number Diff line change @@ -25,4 +25,16 @@ public class Usage {
2525 */
2626 @ JsonProperty ("total_tokens" )
2727 long totalTokens ;
28+
29+ /**
30+ * Breakdown of tokens used in the prompt.
31+ */
32+ @ JsonProperty ("prompt_tokens_details" )
33+ PromptTokensDetails promptTokensDetails ;
34+
35+ /**
36+ * Breakdown of tokens used in a completion.
37+ */
38+ @ JsonProperty ("completion_tokens_details" )
39+ CompletionTokensDetails completionTokensDetails ;
2840}
Original file line number Diff line number Diff line change 315315 "usage" : {
316316 "prompt_tokens" : 9 ,
317317 "completion_tokens" : 12 ,
318- "total_tokens" : 21
318+ "total_tokens" : 21 ,
319+ "prompt_tokens_details" : {
320+ "cached_tokens" : 0
321+ },
322+ "completion_tokens_details" : {
323+ "reasoning_tokens" : 0 ,
324+ "accepted_prediction_tokens" : 0 ,
325+ "rejected_prediction_tokens" : 0
326+ }
319327 }
320328}
Original file line number Diff line number Diff line change @@ -43,8 +43,11 @@ void createChatCompletion() {
4343 .logitBias (new HashMap <>())
4444 .build ();
4545
46- List <ChatCompletionChoice > choices = service .createChatCompletion (chatCompletionRequest ).getChoices ();
47- assertEquals (5 , choices .size ());
46+ ChatCompletionResult chatCompletionResult = service .createChatCompletion (chatCompletionRequest );
47+ assertEquals (5 , chatCompletionResult .getChoices ().size ());
48+ assertNotNull (chatCompletionResult .getUsage ());
49+ assertNotNull (chatCompletionResult .getUsage ().getPromptTokensDetails ());
50+ assertNotNull (chatCompletionResult .getUsage ().getCompletionTokensDetails ());
4851 }
4952
5053 @ Test
You can’t perform that action at this time.
0 commit comments