Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit 5e14d4f

Browse files
authored
Add usage data to Completion and Embedding APIs (#39)
Also changed EditResult to use the new shared object
1 parent 83df513 commit 5e14d4f

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.theokanning.openai;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* The OpenAI resources used by a request
7+
*/
8+
@Data
9+
public class Usage {
10+
/**
11+
* The number of prompt tokens used.
12+
*/
13+
long promptTokens;
14+
15+
/**
16+
* The number of completion tokens used.
17+
*/
18+
long completionTokens;
19+
20+
/**
21+
* The number of total tokens used
22+
*/
23+
long totalTokens;
24+
}

api/src/main/java/com/theokanning/openai/completion/CompletionResult.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.completion;
22

3+
import com.theokanning.openai.Usage;
34
import lombok.Data;
45

56
import java.util.List;
@@ -35,4 +36,9 @@ public class CompletionResult {
3536
* A list of generated completions.
3637
*/
3738
List<CompletionChoice> choices;
39+
40+
/**
41+
* The API usage for this request
42+
*/
43+
Usage usage;
3844
}

api/src/main/java/com/theokanning/openai/edit/EditResult.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.edit;
22

3+
import com.theokanning.openai.Usage;
34
import lombok.Data;
45

56
import java.util.List;
@@ -30,5 +31,5 @@ public class EditResult {
3031
/**
3132
* The API usage for this request
3233
*/
33-
public EditUsage usage;
34+
public Usage usage;
3435
}

api/src/main/java/com/theokanning/openai/edit/EditUsage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
/**
66
* An object containing the API usage for an edit request
77
*
8+
* Deprecated, use {@link com.theokanning.openai.Usage} instead
9+
*
810
* https://beta.openai.com/docs/api-reference/edits/create
911
*/
1012
@Data
13+
@Deprecated
1114
public class EditUsage {
1215

1316
/**

api/src/main/java/com/theokanning/openai/embedding/EmbeddingResult.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.embedding;
22

3+
import com.theokanning.openai.Usage;
34
import lombok.Data;
45

56
import java.util.List;
@@ -26,4 +27,9 @@ public class EmbeddingResult {
2627
* A list of the calculated embeddings
2728
*/
2829
List<Embedding> data;
30+
31+
/**
32+
* The API usage for this request
33+
*/
34+
Usage usage;
2935
}

0 commit comments

Comments
 (0)