Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/main/java/dev/ai4j/openai4j/chat/ChatCompletionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public final class ChatCompletionRequest {
@JsonProperty
private final Boolean parallelToolCalls;
@JsonProperty
private final Boolean store;
@JsonProperty
private final Map<String, String> metadata;
@JsonProperty
private final String serviceTier;
@JsonProperty
@Deprecated
private final List<Function> functions;
@JsonProperty
Expand All @@ -90,6 +96,9 @@ private ChatCompletionRequest(Builder builder) {
this.tools = builder.tools;
this.toolChoice = builder.toolChoice;
this.parallelToolCalls = builder.parallelToolCalls;
this.store = builder.store;
this.metadata = builder.metadata;
this.serviceTier = builder.serviceTier;
this.functions = builder.functions;
this.functionCall = builder.functionCall;
}
Expand Down Expand Up @@ -170,6 +179,18 @@ public Boolean parallelToolCalls() {
return parallelToolCalls;
}

public Boolean store() {
return store;
}

public Map<String, String> metadata() {
return metadata;
}

public String serviceTier() {
return serviceTier;
}

@Deprecated
public List<Function> functions() {
return functions;
Expand Down Expand Up @@ -207,6 +228,9 @@ private boolean equalTo(ChatCompletionRequest another) {
&& Objects.equals(tools, another.tools)
&& Objects.equals(toolChoice, another.toolChoice)
&& Objects.equals(parallelToolCalls, another.parallelToolCalls)
&& Objects.equals(store, another.store)
&& Objects.equals(metadata, another.metadata)
&& Objects.equals(serviceTier, another.serviceTier)
&& Objects.equals(functions, another.functions)
&& Objects.equals(functionCall, another.functionCall);
}
Expand All @@ -233,6 +257,9 @@ public int hashCode() {
h += (h << 5) + Objects.hashCode(tools);
h += (h << 5) + Objects.hashCode(toolChoice);
h += (h << 5) + Objects.hashCode(parallelToolCalls);
h += (h << 5) + Objects.hashCode(store);
h += (h << 5) + Objects.hashCode(metadata);
h += (h << 5) + Objects.hashCode(serviceTier);
h += (h << 5) + Objects.hashCode(functions);
h += (h << 5) + Objects.hashCode(functionCall);
return h;
Expand Down Expand Up @@ -260,6 +287,9 @@ public String toString() {
+ ", tools=" + tools
+ ", toolChoice=" + toolChoice
+ ", parallelToolCalls=" + parallelToolCalls
+ ", store=" + store
+ ", metadata=" + metadata
+ ", serviceTier=" + serviceTier
+ ", functions=" + functions
+ ", functionCall=" + functionCall
+ "}";
Expand Down Expand Up @@ -293,6 +323,9 @@ public static final class Builder {
private List<Tool> tools;
private Object toolChoice;
private Boolean parallelToolCalls;
private Boolean store;
private Map<String, String> metadata;
private String serviceTier;
@Deprecated
private List<Function> functions;
@Deprecated
Expand Down Expand Up @@ -321,6 +354,9 @@ public Builder from(ChatCompletionRequest instance) {
tools(instance.tools);
toolChoice(instance.toolChoice);
parallelToolCalls(instance.parallelToolCalls);
store(instance.store);
metadata(instance.metadata);
serviceTier(instance.serviceTier);
functions(instance.functions);
functionCall(instance.functionCall);
return this;
Expand Down Expand Up @@ -503,6 +539,23 @@ public Builder parallelToolCalls(Boolean parallelToolCalls) {
return this;
}

public Builder store(Boolean store) {
this.store = store;
return this;
}

public Builder metadata(Map<String, String> metadata) {
if (metadata != null) {
this.metadata = unmodifiableMap(metadata);
}
return this;
}

public Builder serviceTier(String serviceTier) {
this.serviceTier = serviceTier;
return this;
}

@Deprecated
public Builder functions(Function... functions) {
return functions(asList(functions));
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/dev/ai4j/openai4j/chat/ChatCompletionResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public final class ChatCompletionResponse {
private final Usage usage;
@JsonProperty
private final String systemFingerprint;
@JsonProperty
private final String serviceTier;

private ChatCompletionResponse(Builder builder) {
this.id = builder.id;
Expand All @@ -39,6 +41,7 @@ private ChatCompletionResponse(Builder builder) {
this.choices = builder.choices;
this.usage = builder.usage;
this.systemFingerprint = builder.systemFingerprint;
this.serviceTier = builder.serviceTier;
}

public String id() {
Expand All @@ -65,6 +68,10 @@ public String systemFingerprint() {
return systemFingerprint;
}

public String serviceTier() {
return serviceTier;
}

/**
* Convenience method to get the content of the message from the first choice.
*/
Expand All @@ -85,7 +92,8 @@ private boolean equalTo(ChatCompletionResponse another) {
&& Objects.equals(model, another.model)
&& Objects.equals(choices, another.choices)
&& Objects.equals(usage, another.usage)
&& Objects.equals(systemFingerprint, another.systemFingerprint);
&& Objects.equals(systemFingerprint, another.systemFingerprint)
&& Objects.equals(serviceTier, another.serviceTier);
}

@Override
Expand All @@ -97,6 +105,7 @@ public int hashCode() {
h += (h << 5) + Objects.hashCode(choices);
h += (h << 5) + Objects.hashCode(usage);
h += (h << 5) + Objects.hashCode(systemFingerprint);
h += (h << 5) + Objects.hashCode(serviceTier);
return h;
}

Expand All @@ -109,6 +118,7 @@ public String toString() {
+ ", choices=" + choices
+ ", usage=" + usage
+ ", systemFingerprint=" + systemFingerprint
+ ", serviceTier=" + serviceTier
+ "}";
}

Expand All @@ -127,6 +137,7 @@ public static final class Builder {
private List<ChatCompletionChoice> choices;
private Usage usage;
private String systemFingerprint;
private String serviceTier;

private Builder() {
}
Expand Down Expand Up @@ -163,6 +174,11 @@ public Builder systemFingerprint(String systemFingerprint) {
return this;
}

public Builder serviceTier(String serviceTier) {
this.serviceTier = serviceTier;
return this;
}

public ChatCompletionResponse build() {
return new ChatCompletionResponse(this);
}
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/dev/ai4j/openai4j/shared/PromptTokensDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package dev.ai4j.openai4j.shared;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import java.util.Objects;

@JsonDeserialize(builder = PromptTokensDetails.Builder.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public final class PromptTokensDetails {

@JsonProperty
private final Integer cachedTokens;

private PromptTokensDetails(Builder builder) {
this.cachedTokens = builder.cachedTokens;
}

public Integer cachedTokens() {
return cachedTokens;
}

@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof PromptTokensDetails
&& equalTo((PromptTokensDetails) another);
}

private boolean equalTo(PromptTokensDetails another) {
return Objects.equals(cachedTokens, another.cachedTokens);
}

@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(cachedTokens);
return h;
}

@Override
public String toString() {
return "PromptTokensDetails{"
+ "cachedTokens=" + cachedTokens
+ "}";
}

public static Builder builder() {
return new Builder();
}

@JsonPOJOBuilder(withPrefix = "")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static final class Builder {

private Integer cachedTokens;

private Builder() {
}

public Builder cachedTokens(Integer cachedTokens) {
this.cachedTokens = cachedTokens;
return this;
}

public PromptTokensDetails build() {
return new PromptTokensDetails(this);
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/dev/ai4j/openai4j/shared/Usage.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ public final class Usage {
@JsonProperty
private final Integer promptTokens;
@JsonProperty
private final PromptTokensDetails promptTokensDetails;
@JsonProperty
private final Integer completionTokens;
@JsonProperty
private final CompletionTokensDetails completionTokensDetails;

private Usage(Builder builder) {
this.totalTokens = builder.totalTokens;
this.promptTokens = builder.promptTokens;
this.promptTokensDetails = builder.promptTokensDetails;
this.completionTokens = builder.completionTokens;
this.completionTokensDetails = builder.completionTokensDetails;
}
Expand All @@ -39,6 +42,10 @@ public Integer promptTokens() {
return promptTokens;
}

public PromptTokensDetails promptTokensDetails() {
return promptTokensDetails;
}

public Integer completionTokens() {
return completionTokens;
}
Expand All @@ -57,6 +64,7 @@ public boolean equals(Object another) {
private boolean equalTo(Usage another) {
return Objects.equals(totalTokens, another.totalTokens)
&& Objects.equals(promptTokens, another.promptTokens)
&& Objects.equals(promptTokensDetails, another.promptTokensDetails)
&& Objects.equals(completionTokens, another.completionTokens)
&& Objects.equals(completionTokensDetails, another.completionTokensDetails);
}
Expand All @@ -66,6 +74,7 @@ public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(totalTokens);
h += (h << 5) + Objects.hashCode(promptTokens);
h += (h << 5) + Objects.hashCode(promptTokensDetails);
h += (h << 5) + Objects.hashCode(completionTokens);
h += (h << 5) + Objects.hashCode(completionTokensDetails);
return h;
Expand All @@ -76,6 +85,7 @@ public String toString() {
return "Usage{"
+ "totalTokens=" + totalTokens
+ ", promptTokens=" + promptTokens
+ ", promptTokensDetails=" + promptTokensDetails
+ ", completionTokens=" + completionTokens
+ ", completionTokensDetails=" + completionTokensDetails
+ "}";
Expand All @@ -92,6 +102,7 @@ public static final class Builder {

private Integer totalTokens;
private Integer promptTokens;
private PromptTokensDetails promptTokensDetails;
private Integer completionTokens;
private CompletionTokensDetails completionTokensDetails;

Expand All @@ -108,6 +119,11 @@ public Builder promptTokens(Integer promptTokens) {
return this;
}

public Builder promptTokensDetails(PromptTokensDetails promptTokensDetails) {
this.promptTokensDetails = promptTokensDetails;
return this;
}

public Builder completionTokens(Integer completionTokens) {
this.completionTokens = completionTokens;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@
"allDeclaredFields": true,
"allPublicFields": true
},
{
"name": "dev.ai4j.openai4j.shared.PromptTokensDetails",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true,
"allDeclaredFields": true,
"allPublicFields": true
},
{
"name": "dev.ai4j.openai4j.shared.StreamOptions",
"allDeclaredConstructors": true,
Expand Down
Loading
Loading