Add usage data to Completion and Embedding APIs (#39)

Also changed EditResult to use the new shared object
This commit is contained in:
Theo Kanning 2022-12-04 12:37:28 -06:00 committed by GitHub
parent 83df513ddc
commit 5e14d4f62b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 1 deletions

View File

@ -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;
}

View File

@ -1,5 +1,6 @@
package com.theokanning.openai.completion;
import com.theokanning.openai.Usage;
import lombok.Data;
import java.util.List;
@ -35,4 +36,9 @@ public class CompletionResult {
* A list of generated completions.
*/
List<CompletionChoice> choices;
/**
* The API usage for this request
*/
Usage usage;
}

View File

@ -1,5 +1,6 @@
package com.theokanning.openai.edit;
import com.theokanning.openai.Usage;
import lombok.Data;
import java.util.List;
@ -30,5 +31,5 @@ public class EditResult {
/**
* The API usage for this request
*/
public EditUsage usage;
public Usage usage;
}

View File

@ -5,9 +5,12 @@ import lombok.Data;
/**
* 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 {
/**

View File

@ -1,5 +1,6 @@
package com.theokanning.openai.embedding;
import com.theokanning.openai.Usage;
import lombok.Data;
import java.util.List;
@ -26,4 +27,9 @@ public class EmbeddingResult {
* A list of the calculated embeddings
*/
List<Embedding> data;
/**
* The API usage for this request
*/
Usage usage;
}