Skip to content

Commit

Permalink
chore: add some docs, expose system_fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
astappiev committed Jul 10, 2024
1 parent a1e4a25 commit ed07279
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public Uni<CompletionResults> 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;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompletionMessage> messages;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Choice> choices;

Expand Down Expand Up @@ -41,14 +45,6 @@ public void setModel(String model) {
this.model = model;
}

public List<Choice> getChoices() {
return choices;
}

public void setChoices(List<Choice> choices) {
this.choices = choices;
}

public Usage getUsage() {
return usage;
}
Expand All @@ -57,11 +53,27 @@ 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;
}

public void setCreated(Instant created) {
this.created = created;
}

public List<Choice> getChoices() {
return choices;
}

public void setChoices(List<Choice> choices) {
this.choices = choices;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Choice> {
@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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -97,8 +115,4 @@ public void updateCosts(UsagePrice price) {
cost = new UsageCost();
cost.setResponse(promptCost + completionCost);
}

public String getObject() {
return this.object;
}
}

0 comments on commit ed07279

Please sign in to comment.