Skip to content

Commit

Permalink
feat: support oai completion response usage
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh committed Oct 1, 2024
1 parent ed22d15 commit 59a92c5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ public class OpenAIChatCompletionResponse implements CompletionResponse {

private final String id;
private final List<OpenAIChatCompletionResponseChoice> choices;
private final OpenAIChatCompletionResponseUsage usage;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public OpenAIChatCompletionResponse(
@JsonProperty("id") String id,
@JsonProperty("choices") List<OpenAIChatCompletionResponseChoice> choices) {
@JsonProperty("choices") List<OpenAIChatCompletionResponseChoice> choices,
@JsonProperty("usage") OpenAIChatCompletionResponseUsage usage) {
this.id = id;
this.choices = choices;
this.usage = usage;
}

public String getId() {
Expand All @@ -27,4 +30,8 @@ public String getId() {
public List<OpenAIChatCompletionResponseChoice> getChoices() {
return choices;
}

public OpenAIChatCompletionResponseUsage getUsage() {
return usage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ee.carlrobert.llm.client.openai.completion.response;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public class OpenAIChatCompletionResponseUsage {

private final int promptTokens;
private final int completionTokens;
private final int totalTokens;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public OpenAIChatCompletionResponseUsage(
@JsonProperty("prompt_tokens") int promptTokens,
@JsonProperty("completion_tokens") int completionTokens,
@JsonProperty("total_tokens") int totalTokens) {
this.promptTokens = promptTokens;
this.completionTokens = completionTokens;
this.totalTokens = totalTokens;
}

public int getPromptTokens() {
return promptTokens;
}

public int getCompletionTokens() {
return completionTokens;
}

public int getTotalTokens() {
return totalTokens;
}
}

0 comments on commit 59a92c5

Please sign in to comment.