Skip to content

Commit

Permalink
feat(chat): add message id and created on conversation history re…
Browse files Browse the repository at this point in the history
…quest
  • Loading branch information
astappiev committed Feb 19, 2024
1 parent c52f946 commit 6903da4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -26,7 +26,7 @@ public interface OpenaiClient {
*/
@POST
@Path("/{model}/chat/completions")
Uni<CompletionResponse> chatCompletions(@PathParam("model") String model, @QueryParam("api-version") String apiVersion, CompletionsBody body);
Uni<CompletionResponse> chatCompletions(@PathParam("model") String model, @QueryParam("api-version") String apiVersion, CompletionBody body);

@ClientExceptionMapper
static RuntimeException toException(Response response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +52,7 @@ public UsagePrice getPrice(String model) {

@Override
public Uni<CompletionResults> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> messages;
private List<CompletionMessage> messages;

private Double temperature;

Expand All @@ -22,16 +21,16 @@ 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();
this.presencePenalty = query.getPresencePenalty();
this.maxTokens = query.getMaxTokens();
}

public List<Message> getMessages() {
public List<CompletionMessage> getMessages() {
return messages;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.7.1</quarkus.platform.version>
<quarkus.platform.version>3.7.3</quarkus.platform.version>

<surefire-plugin.version>3.2.5</surefire-plugin.version>
<enforcer-plugin.version>3.4.1</enforcer-plugin.version>
Expand All @@ -30,7 +30,7 @@
<shade-plugin.version>3.5.1</shade-plugin.version>
<jandex-plugin.version>3.1.6</jandex-plugin.version>
<checkstyle-plugin.version>3.3.1</checkstyle-plugin.version>
<spotbugs-plugin.version>4.8.3.0</spotbugs-plugin.version>
<spotbugs-plugin.version>4.8.3.1</spotbugs-plugin.version>
</properties>

<modules>
Expand Down

0 comments on commit 6903da4

Please sign in to comment.