Skip to content

Commit

Permalink
forgotten addDeltas
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesDuboisSAP committed Aug 23, 2024
1 parent 42ae946 commit e6e009a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class OpenAiChatCompletionOutput extends OpenAiCompletionOutput
* @param delta the delta to add.
*/
public void addDelta(OpenAiDeltaChatCompletion delta) {
super.addDelta(delta);

if (delta.getSystemFingerprint() != null) {
systemFingerprint = delta.getSystemFingerprint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,25 @@ public class OpenAiCompletionOutput {
@JsonProperty("prompt_filter_results")
@Getter(onMethod_ = @Nullable)
private List<OpenAiPromptFilterResult> promptFilterResults;

void addDelta(OpenAiDeltaChatCompletion delta) {
created = delta.getCreated();
id = delta.getId();
model = delta.getModel();
object = delta.getObject();

if (delta.getUsage() != null) {
if (usage == null) {
usage = new OpenAiUsage();
}
usage.addDelta(delta.getUsage());
}

if (delta.getPromptFilterResults() != null) {
if (promptFilterResults == null) {
promptFilterResults = delta.getPromptFilterResults();
}
// prompt_filter_results is only present once in the first delta
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public class OpenAiUsage {
@JsonProperty("total_tokens")
@Getter(onMethod_ = @Nonnull)
private Integer totalTokens;

void addDelta(OpenAiUsage delta) {
if (delta.getCompletionTokens() != null) {
completionTokens = delta.getCompletionTokens();
}
promptTokens = delta.getPromptTokens();
totalTokens = delta.getTotalTokens();
}
}

0 comments on commit e6e009a

Please sign in to comment.