diff --git a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiClient.java b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiClient.java index 4f9402de..e974de99 100644 --- a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiClient.java +++ b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/OpenaiClient.java @@ -10,7 +10,7 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; import de.l3s.interweb.connector.openai.entity.CompletionResponse; -import de.l3s.interweb.connector.openai.entity.CompletionsBody; +import de.l3s.interweb.connector.openai.entity.CompletionBody; import de.l3s.interweb.core.ConnectorException; @Path("/openai/deployments") @@ -26,7 +26,7 @@ public interface OpenaiClient { */ @POST @Path("/{model}/chat/completions") - Uni chatCompletions(@PathParam("model") String model, @QueryParam("api-version") String apiVersion, CompletionsBody body); + Uni chatCompletions(@PathParam("model") String model, @QueryParam("api-version") String apiVersion, CompletionBody body); @ClientExceptionMapper static RuntimeException toException(Response response) { 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 7591f2ff..e3b34efc 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 @@ -7,7 +7,7 @@ import io.smallrye.mutiny.Uni; import org.eclipse.microprofile.rest.client.inject.RestClient; -import de.l3s.interweb.connector.openai.entity.CompletionsBody; +import de.l3s.interweb.connector.openai.entity.CompletionBody; import de.l3s.interweb.core.ConnectorException; import de.l3s.interweb.core.completion.CompletionConnector; import de.l3s.interweb.core.completion.CompletionQuery; @@ -52,7 +52,7 @@ public UsagePrice getPrice(String model) { @Override public Uni complete(CompletionQuery query) throws ConnectorException { - return openai.chatCompletions(query.getModel(), version, new CompletionsBody(query)).map(response -> { + return openai.chatCompletions(query.getModel(), version, new CompletionBody(query)).map(response -> { CompletionResults results = new CompletionResults(); results.setModel(query.getModel()); results.setCreated(response.getCreated()); diff --git a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionsBody.java b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionBody.java similarity index 79% rename from connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionsBody.java rename to connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionBody.java index 57cc296b..fcc17c90 100644 --- a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionsBody.java +++ b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionBody.java @@ -5,12 +5,11 @@ import io.quarkus.runtime.annotations.RegisterForReflection; import de.l3s.interweb.core.completion.CompletionQuery; -import de.l3s.interweb.core.completion.Message; @RegisterForReflection -public final class CompletionsBody { +public final class CompletionBody { - private List messages; + private List messages; private Double temperature; @@ -22,8 +21,8 @@ public final class CompletionsBody { private Integer maxTokens; - public CompletionsBody(CompletionQuery query) { - this.messages = query.getMessages(); + public CompletionBody(CompletionQuery query) { + this.messages = query.getMessages().stream().map(CompletionMessage::new).toList(); this.temperature = query.getTemperature(); this.topP = query.getTopP(); this.frequencyPenalty = query.getPresencePenalty(); @@ -31,7 +30,7 @@ public CompletionsBody(CompletionQuery query) { this.maxTokens = query.getMaxTokens(); } - public List getMessages() { + public List getMessages() { return messages; } diff --git a/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionMessage.java b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionMessage.java new file mode 100644 index 00000000..150dd3b9 --- /dev/null +++ b/connectors/OpenaiConnector/src/main/java/de/l3s/interweb/connector/openai/entity/CompletionMessage.java @@ -0,0 +1,42 @@ +package de.l3s.interweb.connector.openai.entity; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +import de.l3s.interweb.core.completion.Message; + +@RegisterForReflection +public final class CompletionMessage { + private String role; + private String name; + private String content; + + public CompletionMessage(Message message) { + this.role = message.getRole().name(); + this.name = message.getName(); + this.content = message.getContent(); + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/interweb-core/src/main/java/de/l3s/interweb/core/completion/Message.java b/interweb-core/src/main/java/de/l3s/interweb/core/completion/Message.java index 6d37c9cd..18b0c6e8 100644 --- a/interweb-core/src/main/java/de/l3s/interweb/core/completion/Message.java +++ b/interweb-core/src/main/java/de/l3s/interweb/core/completion/Message.java @@ -10,7 +10,6 @@ import io.quarkus.runtime.annotations.RegisterForReflection; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; @RegisterForReflection @JsonIgnoreProperties(ignoreUnknown = true) @@ -24,13 +23,12 @@ public enum Role { assistant } - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) private Long id; @NotNull private Role role; + private String name; @NotEmpty private String content; - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) private Instant created; public Message() { @@ -62,6 +60,14 @@ public void setRole(final Role role) { this.role = role; } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public String getContent() { return content; } diff --git a/pom.xml b/pom.xml index cbc5674f..f5282da7 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ quarkus-bom io.quarkus.platform - 3.7.1 + 3.7.3 3.2.5 3.4.1 @@ -30,7 +30,7 @@ 3.5.1 3.1.6 3.3.1 - 4.8.3.0 + 4.8.3.1