Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public class QianFanChatModel implements ChatModel, StreamingChatModel {
* @throws IllegalArgumentException if QianFanApi is null
*/
public QianFanChatModel(QianFanApi qianFanApi) {
this(qianFanApi,
QianFanChatOptions.builder().withModel(QianFanApi.DEFAULT_CHAT_MODEL).withTemperature(0.7).build());
this(qianFanApi, QianFanChatOptions.builder().model(QianFanApi.DEFAULT_CHAT_MODEL).temperature(0.7).build());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* frequency penalty, max tokens, etc.
*
* @author Geng Rong
* @author Ilayaperumal Gopinathan
* @since 1.0
* @see ChatOptions
*/
Expand Down Expand Up @@ -87,14 +88,14 @@ public static Builder builder() {

public static QianFanChatOptions fromOptions(QianFanChatOptions fromOptions) {
return QianFanChatOptions.builder()
.withModel(fromOptions.getModel())
.withFrequencyPenalty(fromOptions.getFrequencyPenalty())
.withMaxTokens(fromOptions.getMaxTokens())
.withPresencePenalty(fromOptions.getPresencePenalty())
.withResponseFormat(fromOptions.getResponseFormat())
.withStop(fromOptions.getStop())
.withTemperature(fromOptions.getTemperature())
.withTopP(fromOptions.getTopP())
.model(fromOptions.getModel())
.frequencyPenalty(fromOptions.getFrequencyPenalty())
.maxTokens(fromOptions.getMaxTokens())
.presencePenalty(fromOptions.getPresencePenalty())
.responseFormat(fromOptions.getResponseFormat())
.stop(fromOptions.getStop())
.temperature(fromOptions.getTemperature())
.topP(fromOptions.getTopP())
.build();
}

Expand Down Expand Up @@ -296,41 +297,115 @@ public Builder(QianFanChatOptions options) {
this.options = options;
}

public Builder model(String model) {
this.options.model = model;
return this;
}

public Builder frequencyPenalty(Double frequencyPenalty) {
this.options.frequencyPenalty = frequencyPenalty;
return this;
}

public Builder maxTokens(Integer maxTokens) {
this.options.maxTokens = maxTokens;
return this;
}

public Builder presencePenalty(Double presencePenalty) {
this.options.presencePenalty = presencePenalty;
return this;
}

public Builder responseFormat(QianFanApi.ChatCompletionRequest.ResponseFormat responseFormat) {
this.options.responseFormat = responseFormat;
return this;
}

public Builder stop(List<String> stop) {
this.options.stop = stop;
return this;
}

public Builder temperature(Double temperature) {
this.options.temperature = temperature;
return this;
}

public Builder topP(Double topP) {
this.options.topP = topP;
return this;
}

/**
* @deprecated use {@link #model(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withModel(String model) {
this.options.model = model;
return this;
}

/**
* @deprecated use {@link #frequencyPenalty(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withFrequencyPenalty(Double frequencyPenalty) {
this.options.frequencyPenalty = frequencyPenalty;
return this;
}

/**
* @deprecated use {@link #maxTokens(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withMaxTokens(Integer maxTokens) {
this.options.maxTokens = maxTokens;
return this;
}

/**
* @deprecated use {@link #presencePenalty(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withPresencePenalty(Double presencePenalty) {
this.options.presencePenalty = presencePenalty;
return this;
}

/**
* @deprecated use
* {@link #responseFormat(QianFanApi.ChatCompletionRequest.ResponseFormat)}
* instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withResponseFormat(QianFanApi.ChatCompletionRequest.ResponseFormat responseFormat) {
this.options.responseFormat = responseFormat;
return this;
}

/**
* @deprecated use {@link #stop(List)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withStop(List<String> stop) {
this.options.stop = stop;
return this;
}

/**
* @deprecated use {@link #temperature(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTemperature(Double temperature) {
this.options.temperature = temperature;
return this;
}

/**
* @deprecated use {@link #topP(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTopP(Double topP) {
this.options.topP = topP;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public QianFanEmbeddingModel(QianFanApi qianFanApi) {
*/
public QianFanEmbeddingModel(QianFanApi qianFanApi, MetadataMode metadataMode) {
this(qianFanApi, metadataMode,
QianFanEmbeddingOptions.builder().withModel(QianFanApi.DEFAULT_EMBEDDING_MODEL).build());
QianFanEmbeddingOptions.builder().model(QianFanApi.DEFAULT_EMBEDDING_MODEL).build());
}

/**
Expand Down Expand Up @@ -206,8 +206,8 @@ private QianFanEmbeddingOptions mergeOptions(@Nullable EmbeddingOptions runtimeO
}

return QianFanEmbeddingOptions.builder()
.withModel(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel()))
.withUser(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getUser(), defaultOptions.getUser()))
.model(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel()))
.user(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getUser(), defaultOptions.getUser()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @author Geng Rong
* @author Thomas Vitale
* @author Ilayaperumal Gopinathan
* @since 1.0
*/
@JsonInclude(Include.NON_NULL)
Expand Down Expand Up @@ -81,11 +82,29 @@ public Builder() {
this.options = new QianFanEmbeddingOptions();
}

public Builder model(String model) {
this.options.setModel(model);
return this;
}

public Builder user(String user) {
this.options.setUser(user);
return this;
}

/**
* @deprecated use {@link #model(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withModel(String model) {
this.options.setModel(model);
return this;
}

/**
* @deprecated use {@link #user(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withUser(String user) {
this.options.setUser(user);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,13 @@ private QianFanImageOptions mergeOptions(@Nullable ImageOptions runtimeImageOpti
}

return QianFanImageOptions.builder()
.withModel(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel()))
.withN(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getN(), defaultOptions.getN()))
.withModel(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel()))
.withWidth(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getWidth(), defaultOptions.getWidth()))
.withHeight(
ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getHeight(), defaultOptions.getHeight()))
.withStyle(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getStyle(), defaultOptions.getStyle()))
.withUser(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getUser(), defaultOptions.getUser()))
.model(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel()))
.N(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getN(), defaultOptions.getN()))
.model(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel()))
.width(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getWidth(), defaultOptions.getWidth()))
.height(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getHeight(), defaultOptions.getHeight()))
.style(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getStyle(), defaultOptions.getStyle()))
.user(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getUser(), defaultOptions.getUser()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* QianFan Image API options. QianFanImageOptions.java
*
* @author Geng Rong
* @author Ilayaperumal Gopinathan
* @since 1.0
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -196,31 +197,85 @@ private Builder() {
this.options = new QianFanImageOptions();
}

public Builder N(Integer n) {
this.options.setN(n);
return this;
}

public Builder model(String model) {
this.options.setModel(model);
return this;
}

public Builder width(Integer width) {
this.options.setWidth(width);
return this;
}

public Builder height(Integer height) {
this.options.setHeight(height);
return this;
}

public Builder style(String style) {
this.options.setStyle(style);
return this;
}

public Builder user(String user) {
this.options.setUser(user);
return this;
}

/**
* @deprecated use {@link #N(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withN(Integer n) {
this.options.setN(n);
return this;
}

/**
* @deprecated use {@link #model(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withModel(String model) {
this.options.setModel(model);
return this;
}

/**
* @deprecated use {@link #width(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withWidth(Integer width) {
this.options.setWidth(width);
return this;
}

/**
* @deprecated use {@link #height(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withHeight(Integer height) {
this.options.setHeight(height);
return this;
}

/**
* @deprecated use {@link #style(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withStyle(String style) {
this.options.setStyle(style);
return this;
}

/**
* @deprecated use {@link #user(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withUser(String user) {
this.options.setUser(user);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ChatCompletionRequestTests {
public void createRequestWithChatOptions() {

var client = new QianFanChatModel(new QianFanApi("TEST", "TEST"),
QianFanChatOptions.builder().withModel("DEFAULT_MODEL").withTemperature(66.6).build());
QianFanChatOptions.builder().model("DEFAULT_MODEL").temperature(66.6).build());

var request = client.createRequest(new Prompt("Test message content"), false);

Expand All @@ -43,7 +43,7 @@ public void createRequestWithChatOptions() {
assertThat(request.temperature()).isEqualTo(66.6);

request = client.createRequest(new Prompt("Test message content",
QianFanChatOptions.builder().withModel("PROMPT_MODEL").withTemperature(99.9).build()), true);
QianFanChatOptions.builder().model("PROMPT_MODEL").temperature(99.9).build()), true);

assertThat(request.messages()).hasSize(1);
assertThat(request.stream()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ void beforeEach() {
void observationForChatOperation() {

var options = QianFanChatOptions.builder()
.withModel(QianFanApi.ChatModel.ERNIE_Speed_8K.getValue())
.withFrequencyPenalty(0.0)
.withMaxTokens(2048)
.withPresencePenalty(0.0)
.withStop(List.of("this-is-the-end"))
.withTemperature(0.7)
.withTopP(1.0)
.model(QianFanApi.ChatModel.ERNIE_Speed_8K.getValue())
.frequencyPenalty(0.0)
.maxTokens(2048)
.presencePenalty(0.0)
.stop(List.of("this-is-the-end"))
.temperature(0.7)
.topP(1.0)
.build();

Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
Expand All @@ -94,13 +94,13 @@ void observationForChatOperation() {
@Test
void observationForStreamingChatOperation() {
var options = QianFanChatOptions.builder()
.withModel(QianFanApi.ChatModel.ERNIE_Speed_8K.getValue())
.withFrequencyPenalty(0.0)
.withMaxTokens(2048)
.withPresencePenalty(0.0)
.withStop(List.of("this-is-the-end"))
.withTemperature(0.7)
.withTopP(1.0)
.model(QianFanApi.ChatModel.ERNIE_Speed_8K.getValue())
.frequencyPenalty(0.0)
.maxTokens(2048)
.presencePenalty(0.0)
.stop(List.of("this-is-the-end"))
.temperature(0.7)
.topP(1.0)
.build();

Prompt prompt = new Prompt("Why does a raven look like a desk?", options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class QianFanEmbeddingModelObservationIT {
@Test
void observationForEmbeddingOperation() {
var options = QianFanEmbeddingOptions.builder()
.withModel(QianFanApi.EmbeddingModel.BGE_LARGE_ZH.getValue())
.model(QianFanApi.EmbeddingModel.BGE_LARGE_ZH.getValue())
.build();

EmbeddingRequest embeddingRequest = new EmbeddingRequest(List.of("Here comes the sun"), options);
Expand Down
Loading
Loading