Skip to content

Refactor Option Builder #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f8ee49c
add test code
youngmoneee Mar 6, 2024
e0dd9b1
refactor separate FunctionCallingOptions
youngmoneee Mar 7, 2024
b99466a
refactor ChatOptionsBuilder.java
youngmoneee Mar 7, 2024
41f3f3c
refactor FunctionCallingOptionsBuilder.java
youngmoneee Mar 7, 2024
3e64f5b
feat PortableFunctionCallingOptionsBuilder.java
youngmoneee Mar 7, 2024
75065af
refactor Fix side-effect
youngmoneee Mar 7, 2024
092b6a9
refactor ImageOptionsBuilder.java
youngmoneee Mar 7, 2024
9bf18a1
test add TestCode for Options
youngmoneee Mar 7, 2024
5ddf788
fix elements undermining immutability
youngmoneee Mar 8, 2024
231e9cc
docs FunctionCallingOptionsBuilder.java
youngmoneee Mar 8, 2024
38621b6
Add Ollama enum with supported models and their ids
sblashuk Mar 1, 2024
f85facd
Exclude .antlr and aot.factories from license headers check
tzolov Mar 7, 2024
927cf9f
Refactor and centralize Retry logic:
tzolov Mar 6, 2024
f7293ce
Resolve OpenAiApi initialization bug
tzolov Mar 7, 2024
8fe6705
Adjust the retry properties names and documentation
tzolov Mar 8, 2024
0187c87
Use platform independent line separators
tzolov Mar 8, 2024
d23065e
Move the maven license plugin into a 'license' profile
tzolov Mar 8, 2024
77eb2ff
Update auto-configure classes to return the most specific class types
tzolov Mar 8, 2024
bf75669
Add ETL pipeline diagrams
tzolov Mar 8, 2024
80ab883
Fix spring-ai-retry BOM version
tzolov Mar 8, 2024
6ea92e4
Merge branch 'main' into refactor_openai_builder
youngmoneee Mar 8, 2024
13f4130
Revert "docs FunctionCallingOptionsBuilder.java"
youngmoneee Mar 8, 2024
fbb0fc3
refactor Private Class to Static
youngmoneee Mar 10, 2024
a80fa1d
docs FunctionCallingOptionsBuilder.java
youngmoneee Mar 10, 2024
d353505
docs add Comment for javadoc
youngmoneee Mar 10, 2024
784a3af
refactor DefaultContentFormatter.java
youngmoneee Mar 13, 2024
c7a7ec3
Merge branch 'refactor_builder_vectorstore' into refactor_openai_builder
youngmoneee Mar 13, 2024
eed83f4
refactor OpenAiImageOptions.java
youngmoneee Mar 15, 2024
c1b11dd
refactor OpenAiImageProperties.java
youngmoneee Mar 15, 2024
15ce8e2
fix side-effect
youngmoneee Mar 15, 2024
36a231c
fix returning implementations
youngmoneee Mar 16, 2024
8edd1a7
add header and null check logic
youngmoneee Mar 16, 2024
4b58013
refactor OpenAiChatOptions.java
youngmoneee Mar 16, 2024
285002e
refactor OpenAiChatOptionsProperties.java
youngmoneee Mar 16, 2024
77e683c
fix side-effect
youngmoneee Mar 16, 2024
26a0319
refactor OpenAiAudioTranscriptionOptions.java
youngmoneee Mar 17, 2024
1e5d85e
refactor OpenAiAudioTranscriptionProperties.java
youngmoneee Mar 17, 2024
7e76931
fix side-effect
youngmoneee Mar 17, 2024
5e31771
refactor OpenAiEmbeddingOptions.java
youngmoneee Mar 17, 2024
ce8b353
refactor OpenAiEmbeddingProperties.java
youngmoneee Mar 17, 2024
49f205e
fix side-effect
youngmoneee Mar 17, 2024
dea1cbd
Merge branch 'main' into refactor_openai_builder
youngmoneee Mar 19, 2024
7ed7572
Merge branch 'main' into refactor_openai_builder
youngmoneee Mar 21, 2024
c7f6cfc
Merge branch 'main' into refactor_openai_builder
youngmoneee Apr 16, 2024
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 @@ -206,7 +206,6 @@ public List<FunctionCallback> getFunctionCallbacks() {
return this.functionCallbacks;
}

@Override
public void setFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
Assert.notNull(functionCallbacks, "FunctionCallbacks must not be null");
this.functionCallbacks = functionCallbacks;
Expand All @@ -217,7 +216,6 @@ public Set<String> getFunctions() {
return this.functions;
}

@Override
public void setFunctions(Set<String> functions) {
Assert.notNull(functions, "Function must not be null");
this.functions = functions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest.ResponseFormat;
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest.ToolChoice;
import org.springframework.ai.mistralai.api.MistralAiApi.FunctionTool;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.ai.model.function.PortableFunctionCallingOptions;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;

Expand All @@ -38,7 +37,7 @@
* @since 0.8.1
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions {
public class MistralAiChatOptions implements PortableFunctionCallingOptions {

/**
* ID of the model to use
Expand Down Expand Up @@ -292,21 +291,9 @@ public List<FunctionCallback> getFunctionCallbacks() {
return this.functionCallbacks;
}

@Override
public void setFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
Assert.notNull(functionCallbacks, "FunctionCallbacks must not be null");
this.functionCallbacks = functionCallbacks;
}

@Override
public Set<String> getFunctions() {
return this.functions;
}

@Override
public void setFunctions(Set<String> functions) {
Assert.notNull(functions, "Function must not be null");
this.functions = functions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class OpenAiAudioTranscriptionClient
*/
public OpenAiAudioTranscriptionClient(OpenAiAudioApi audioApi) {
this(audioApi,
OpenAiAudioTranscriptionOptions.builder()
OpenAiAudioTranscriptionOptionsBuilder.builder()
.withModel(OpenAiAudioApi.WhisperModel.WHISPER_1.getValue())
.withResponseFormat(OpenAiAudioApi.TranscriptResponseFormat.JSON)
.withTemperature(0.7f)
Expand Down Expand Up @@ -209,19 +209,18 @@ private byte[] toBytes(Resource resource) {

private OpenAiAudioTranscriptionOptions merge(OpenAiAudioTranscriptionOptions source,
OpenAiAudioTranscriptionOptions target) {

OpenAiAudioTranscriptionOptionsBuilder builder = OpenAiAudioTranscriptionOptionsBuilder.builder();
if (source == null) {
source = new OpenAiAudioTranscriptionOptions();
source = OpenAiAudioTranscriptionOptionsBuilder.builder().build();
}

OpenAiAudioTranscriptionOptions merged = new OpenAiAudioTranscriptionOptions();
merged.setLanguage(source.getLanguage() != null ? source.getLanguage() : target.getLanguage());
merged.setModel(source.getModel() != null ? source.getModel() : target.getModel());
merged.setPrompt(source.getPrompt() != null ? source.getPrompt() : target.getPrompt());
merged.setResponseFormat(
builder.withLanguage(source.getLanguage() != null ? source.getLanguage() : target.getLanguage());
builder.withModel(source.getModel() != null ? source.getModel() : target.getModel());
builder.withPrompt(source.getPrompt() != null ? source.getPrompt() : target.getPrompt());
builder.withResponseFormat(
source.getResponseFormat() != null ? source.getResponseFormat() : target.getResponseFormat());
merged.setTemperature(source.getTemperature() != null ? source.getTemperature() : target.getTemperature());
return merged;
builder.withTemperature(source.getTemperature() != null ? source.getTemperature() : target.getTemperature());
return builder.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,187 +18,47 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.springframework.ai.model.ModelOptions;
import org.springframework.ai.openai.api.OpenAiAudioApi.TranscriptResponseFormat;
import org.springframework.ai.openai.api.OpenAiAudioApi.TranscriptionRequest.GranularityType;

/**
* @author youngmon
* @author Michael Lavelle
* @author Christian Tzolov
* @since 0.8.1
*/
@JsonInclude(Include.NON_NULL)
public class OpenAiAudioTranscriptionOptions implements ModelOptions {
public interface OpenAiAudioTranscriptionOptions extends ModelOptions {

// @formatter:off
/**
* ID of the model to use.
*/
private @JsonProperty("model") String model;
@JsonProperty("model")
String getModel();

/**
* The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt.
* The format of the transcript output, in one of these options: json, text, srt,
* verbose_json, or vtt.
*/
private @JsonProperty("response_format") TranscriptResponseFormat responseFormat;
@JsonProperty("response_format")
TranscriptResponseFormat getResponseFormat();

private @JsonProperty("prompt") String prompt;
@JsonProperty("prompt")
String getPrompt();

private @JsonProperty("language") String language;
@JsonProperty("language")
String getLanguage();

/**
* What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output
* more random, while lower values like 0.2 will make it more focused and deterministic.
* What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make
* the output more random, while lower values like 0.2 will make it more focused and
* deterministic.
*/
private @JsonProperty("temperature") Float temperature;

private @JsonProperty("timestamp_granularities") GranularityType granularityType;

public static Builder builder() {
return new Builder();
}

public static class Builder {

protected OpenAiAudioTranscriptionOptions options;

public Builder() {
this.options = new OpenAiAudioTranscriptionOptions();
}

public Builder(OpenAiAudioTranscriptionOptions options) {
this.options = options;
}

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

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

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

public Builder withResponseFormat(TranscriptResponseFormat responseFormat) {
this.options.responseFormat = responseFormat;
return this;
}

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

public Builder withGranularityType(GranularityType granularityType) {
this.options.granularityType = granularityType;
return this;
}

public OpenAiAudioTranscriptionOptions build() {
return this.options;
}

}

public String getModel() {
return this.model;
}

public void setModel(String model) {
this.model = model;
}

public String getLanguage() {
return this.language;
}

public void setLanguage(String language) {
this.language = language;
}

public String getPrompt() {
return this.prompt;
}

public void setPrompt(String prompt) {
this.prompt = prompt;
}

public Float getTemperature() {
return this.temperature;
}

public void setTemperature(Float temperature) {
this.temperature = temperature;
}


public TranscriptResponseFormat getResponseFormat() {
return this.responseFormat;
}

public void setResponseFormat(TranscriptResponseFormat responseFormat) {
this.responseFormat = responseFormat;
}

public GranularityType getGranularityType() {
return this.granularityType;
}

public void setGranularityType(GranularityType granularityType) {
this.granularityType = granularityType;
}
@JsonProperty("temperature")
Float getTemperature();

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((model == null) ? 0 : model.hashCode());
result = prime * result + ((prompt == null) ? 0 : prompt.hashCode());
result = prime * result + ((language == null) ? 0 : language.hashCode());
result = prime * result + ((responseFormat == null) ? 0 : responseFormat.hashCode());
return result;
}
@JsonProperty("timestamp_granularities")
GranularityType getGranularityType();

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OpenAiAudioTranscriptionOptions other = (OpenAiAudioTranscriptionOptions) obj;
if (this.model == null) {
if (other.model != null)
return false;
}
else if (!model.equals(other.model))
return false;
if (this.prompt == null) {
if (other.prompt != null)
return false;
}
else if (!this.prompt.equals(other.prompt))
return false;
if (this.language == null) {
if (other.language != null)
return false;
}
else if (!this.language.equals(other.language))
return false;
if (this.responseFormat == null) {
if (other.responseFormat != null)
return false;
}
else if (!this.responseFormat.equals(other.responseFormat))
return false;
return true;
}
}
Loading