diff --git a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiConnector.java b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiConnector.java index edec4cd6..ec76b97e 100644 --- a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiConnector.java +++ b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiConnector.java @@ -65,6 +65,8 @@ public Uni complete(CompletionQuery query) throws ConnectorEx results.setCreated(response.getCreated()); results.setChoices(response.getChoices()); results.setUsage(response.getUsage()); + results.setObject(response.getObject()); + results.setSystemFingerprint(response.getSystemFingerprint()); return results; }); } diff --git a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionBody.java b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionBody.java index dbc7ad7b..a66be014 100644 --- a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionBody.java +++ b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionBody.java @@ -2,16 +2,16 @@ import java.util.List; -import com.fasterxml.jackson.annotation.JsonFormat; +import io.quarkus.runtime.annotations.RegisterForReflection; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import io.quarkus.runtime.annotations.RegisterForReflection; - import de.l3s.interweb.core.completion.CompletionQuery; import de.l3s.interweb.core.completion.ResponseFormat; @RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) public final class CompletionBody { private List messages; @@ -30,17 +30,22 @@ public final class CompletionBody { @JsonProperty("max_tokens") private Integer maxTokens; - @JsonInclude(JsonInclude.Include.NON_NULL) + /** + * How many completions to generate for each prompt. Minimum of 1 (default) and maximum of 128 allowed. + * Note: Because this parameter generates many completions, it can quickly consume your token quota. + */ private Integer n; - @JsonInclude(JsonInclude.Include.NON_NULL) + /** + * If specified, our system will make the best effort to sample deterministically, + * such that repeated requests with the same seed and parameters should return the same result. + * Determinism isn't guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend. + */ private Integer seed; - @JsonInclude(JsonInclude.Include.NON_NULL) @JsonProperty("response_format") private ResponseFormat responseFormat; - @JsonInclude(JsonInclude.Include.NON_NULL) private String[] stop; public CompletionBody(CompletionQuery query) { diff --git a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionResponse.java b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionResponse.java index de98fe9d..a9b6fab3 100644 --- a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionResponse.java +++ b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionResponse.java @@ -5,6 +5,8 @@ import io.quarkus.runtime.annotations.RegisterForReflection; +import com.fasterxml.jackson.annotation.JsonProperty; + import de.l3s.interweb.core.completion.Choice; import de.l3s.interweb.core.completion.Usage; @@ -14,6 +16,8 @@ public class CompletionResponse { private String object; private String model; private Usage usage; + @JsonProperty("system_fingerprint") + private String systemFingerprint; private Instant created; private List choices; @@ -41,14 +45,6 @@ public void setModel(String model) { this.model = model; } - public List getChoices() { - return choices; - } - - public void setChoices(List choices) { - this.choices = choices; - } - public Usage getUsage() { return usage; } @@ -57,6 +53,14 @@ public void setUsage(Usage usage) { this.usage = usage; } + public String getSystemFingerprint() { + return systemFingerprint; + } + + public void setSystemFingerprint(String systemFingerprint) { + this.systemFingerprint = systemFingerprint; + } + public Instant getCreated() { return created; } @@ -64,4 +68,12 @@ public Instant getCreated() { public void setCreated(Instant created) { this.created = created; } + + public List getChoices() { + return choices; + } + + public void setChoices(List choices) { + this.choices = choices; + } } diff --git a/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionQuery.java b/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionQuery.java index 0e7f4eba..0fda8d6c 100644 --- a/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionQuery.java +++ b/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionQuery.java @@ -99,13 +99,27 @@ public class CompletionQuery { @JsonProperty(value = "generate_title") private boolean generateTitle; - + /** + * How many completions to generate for each prompt. Minimum of 1 (default) and maximum of 128 allowed. + * Note: Because this parameter generates many completions, it can quickly consume your token quota. + */ private Integer n; + /** + * If specified, our system will make the best effort to sample deterministically, + * such that repeated requests with the same seed and parameters should return the same result. + * Determinism isn't guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend. + */ private Integer seed; + /** + * An object specifying the format that the model must output. Used to enable JSON mode. + */ private ResponseFormat responseFormat; + /** + * Up to 4 sequences where the API will stop generating further tokens. + */ @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) private String[] stop; diff --git a/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionResults.java b/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionResults.java index 04a726ab..aaa2ed37 100644 --- a/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionResults.java +++ b/interweb-core/src/main/java/de/l3s/interweb/core/completion/CompletionResults.java @@ -15,17 +15,19 @@ @RegisterForReflection @JsonIgnoreProperties("results") -@JsonPropertyOrder({"id", "title", "model", "choices", "usage", "cost", "elapsed_time", "created"}) +@JsonPropertyOrder({"id", "object", "title", "model", "choices", "usage", "cost", "elapsed_time", "system_fingerprint", "created"}) public class CompletionResults extends Results { @JsonProperty(value = "id") private UUID chatId; @JsonProperty(value = "title") private String chatTitle; + private String object; private String model; private Usage usage; private UsageCost cost; + @JsonProperty(value = "system_fingerprint") + private String systemFingerprint; private Instant created; - private final String object = "chat.completion"; public UUID getChatId() { return chatId; @@ -43,6 +45,14 @@ public void setChatTitle(String chatTitle) { this.chatTitle = chatTitle; } + public String getObject() { + return this.object; + } + + public void setObject(String object) { + this.object = object; + } + public String getModel() { return model; } @@ -82,6 +92,14 @@ public UsageCost getCost() { return cost; } + public String getSystemFingerprint() { + return systemFingerprint; + } + + public void setSystemFingerprint(String systemFingerprint) { + this.systemFingerprint = systemFingerprint; + } + public Instant getCreated() { return created; } @@ -97,8 +115,4 @@ public void updateCosts(UsagePrice price) { cost = new UsageCost(); cost.setResponse(promptCost + completionCost); } - - public String getObject() { - return this.object; - } }