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

Commit

Permalink
Add usage data to Completion and Embedding APIs (#39)
Browse files Browse the repository at this point in the history
Also changed EditResult to use the new shared object
  • Loading branch information
TheoKanning authored Dec 4, 2022
1 parent 83df513 commit 5e14d4f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
24 changes: 24 additions & 0 deletions api/src/main/java/com/theokanning/openai/Usage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.theokanning.openai;

import lombok.Data;

/**
* The OpenAI resources used by a request
*/
@Data
public class Usage {
/**
* The number of prompt tokens used.
*/
long promptTokens;

/**
* The number of completion tokens used.
*/
long completionTokens;

/**
* The number of total tokens used
*/
long totalTokens;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.completion;

import com.theokanning.openai.Usage;
import lombok.Data;

import java.util.List;
Expand Down Expand Up @@ -35,4 +36,9 @@ public class CompletionResult {
* A list of generated completions.
*/
List<CompletionChoice> choices;

/**
* The API usage for this request
*/
Usage usage;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.edit;

import com.theokanning.openai.Usage;
import lombok.Data;

import java.util.List;
Expand Down Expand Up @@ -30,5 +31,5 @@ public class EditResult {
/**
* The API usage for this request
*/
public EditUsage usage;
public Usage usage;
}
3 changes: 3 additions & 0 deletions api/src/main/java/com/theokanning/openai/edit/EditUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
/**
* An object containing the API usage for an edit request
*
* Deprecated, use {@link com.theokanning.openai.Usage} instead
*
* https://beta.openai.com/docs/api-reference/edits/create
*/
@Data
@Deprecated
public class EditUsage {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.embedding;

import com.theokanning.openai.Usage;
import lombok.Data;

import java.util.List;
Expand All @@ -26,4 +27,9 @@ public class EmbeddingResult {
* A list of the calculated embeddings
*/
List<Embedding> data;

/**
* The API usage for this request
*/
Usage usage;
}

0 comments on commit 5e14d4f

Please sign in to comment.