Skip to content

Commit ce3af29

Browse files
committed
feat: implement chat completion n param to all models
1 parent 815ddbc commit ce3af29

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

interweb-core/src/main/java/de/l3s/interweb/core/chat/Duration.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ public void setCompletionGeneration(Long completionGeneration) {
6060
this.completionGeneration = completionGeneration;
6161
}
6262

63+
public void add(Duration other) {
64+
if (total != null && other.total != null) {
65+
total += other.total;
66+
}
67+
if (load != null && other.load != null) {
68+
load += other.load;
69+
}
70+
if (promptEvaluation != null && other.promptEvaluation != null) {
71+
promptEvaluation += other.promptEvaluation;
72+
}
73+
if (completionGeneration != null && other.completionGeneration != null) {
74+
completionGeneration += other.completionGeneration;
75+
}
76+
}
77+
6378
public static Duration of(long ns) {
6479
Duration duration = new Duration();
6580
duration.setTotal(ns);

interweb-core/src/main/java/de/l3s/interweb/core/chat/Usage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ public int getTotalTokens() {
4545
public void setTotalTokens(int totalTokens) {
4646
this.totalTokens = totalTokens;
4747
}
48+
49+
public void add(Usage other) {
50+
this.promptTokens += other.promptTokens;
51+
this.completionTokens += other.completionTokens;
52+
this.totalTokens += other.totalTokens;
53+
}
4854
}

interweb-core/src/main/java/de/l3s/interweb/core/chat/UsageCost.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ public double getChatTotal() {
4545
public void setChatTotal(double chatTotal) {
4646
this.chatTotal = chatTotal;
4747
}
48+
49+
public void add(UsageCost other) {
50+
this.prompt += other.prompt;
51+
this.completion += other.completion;
52+
this.total += other.total;
53+
this.chatTotal += other.chatTotal;
54+
}
4855
}

interweb-server/src/main/java/de/l3s/interweb/server/features/openai/OpenaiV1Resource.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,21 @@ public Uni<CompletionsResults> chatCompletions(@Valid CompletionsQuery query) {
5757

5858
return chatService.completions(query, apikey).chain(results -> {
5959
results.setChatId(null); // reset chatId if it was set
60+
return populateMoreChoices(apikey, query, results);
61+
});
62+
}
63+
64+
public Uni<CompletionsResults> populateMoreChoices(ApiKey apikey, CompletionsQuery query, CompletionsResults results) {
65+
if (query.getN() == null || query.getN() <= 1 || results.getChoices().size() >= query.getN()) {
6066
return Uni.createFrom().item(results);
67+
}
68+
69+
return chatService.completions(query, apikey).chain(newResults -> {
70+
results.getChoices().addAll(newResults.getChoices());
71+
results.getCost().add(newResults.getCost());
72+
results.getUsage().add(newResults.getUsage());
73+
results.getDuration().add(newResults.getDuration());
74+
return populateMoreChoices(apikey, query, results);
6175
});
6276
}
6377

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
2121
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
22-
<quarkus.platform.version>3.16.4</quarkus.platform.version>
22+
<quarkus.platform.version>3.17.3</quarkus.platform.version>
2323

2424
<surefire-plugin.version>3.5.2</surefire-plugin.version>
2525
<enforcer-plugin.version>3.5.0</enforcer-plugin.version>
2626
<dependency-plugin.version>3.8.1</dependency-plugin.version>
2727
<compiler-plugin.version>3.13.0</compiler-plugin.version>
2828
<source-plugin.version>3.3.1</source-plugin.version>
29-
<javadoc-plugin.version>3.11.1</javadoc-plugin.version>
29+
<javadoc-plugin.version>3.11.2</javadoc-plugin.version>
3030
<gpg-plugin.version>3.2.7</gpg-plugin.version>
3131
<sonatype-plugin.version>0.6.0</sonatype-plugin.version>
3232
<resources-plugin.version>3.3.1</resources-plugin.version>

0 commit comments

Comments
 (0)