Skip to content
Merged
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 @@ -135,7 +135,8 @@ OllamaApi.EmbeddingRequest ollamaEmbeddingRequest(String inputContent, Embedding
throw new IllegalArgumentException("Model is not set!");
}
String model = mergedOptions.getModel();
return new EmbeddingRequest(model, inputContent, OllamaOptions.filterNonSupportedFields(mergedOptions.toMap()));
return new EmbeddingRequest(model, inputContent, null,
OllamaOptions.filterNonSupportedFields(mergedOptions.toMap()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ public record GenerateRequest(
@JsonProperty("template") String template,
@JsonProperty("context") List<Integer> context,
@JsonProperty("stream") Boolean stream,
@JsonProperty("raw") Boolean raw) {
@JsonProperty("raw") Boolean raw,
@JsonProperty("images") List<String> images,
@JsonProperty("keep_alive") String keepAlive) {

/**
* Short cut constructor to create a CompletionRequest without options.
Expand All @@ -159,7 +161,7 @@ public record GenerateRequest(
* @param stream Whether to stream the response.
*/
public GenerateRequest(String model, String prompt, Boolean stream) {
this(model, prompt, null, null, null, null, null, stream, null);
this(model, prompt, null, null, null, null, null, stream, null, null, null);
}

/**
Expand All @@ -170,7 +172,7 @@ public GenerateRequest(String model, String prompt, Boolean stream) {
* @param stream Whether to stream the response.
*/
public GenerateRequest(String model, String prompt, boolean enableJsonFormat, Boolean stream) {
this(model, prompt, (enableJsonFormat) ? "json" : null, null, null, null, null, stream, null);
this(model, prompt, (enableJsonFormat) ? "json" : null, null, null, null, null, stream, null, null, null);
}

/**
Expand All @@ -192,6 +194,8 @@ public static class Builder {
private List<Integer> context;
private Boolean stream;
private Boolean raw;
private List<String> images;
private String keepAlive;

public Builder(String prompt) {
this.prompt = prompt;
Expand Down Expand Up @@ -242,8 +246,18 @@ public Builder withRaw(Boolean raw) {
return this;
}

public Builder withImages(List<String> images) {
this.images = images;
return this;
}

public Builder withKeepAlive(String keepAlive) {
this.keepAlive = keepAlive;
return this;
}

public GenerateRequest build() {
return new GenerateRequest(model, prompt, format, options, system, template, context, stream, raw);
return new GenerateRequest(model, prompt, format, options, system, template, context, stream, raw, images, keepAlive);
}

}
Expand Down Expand Up @@ -462,14 +476,14 @@ public Builder withTemplate(String template) {
}

public Builder withOptions(Map<String, Object> options) {
Objects.requireNonNullElse(options, "The options can not be null.");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the method name here to prevent NullPointerExceptions

Objects.requireNonNull(options, "The options can not be null.");

this.options = OllamaOptions.filterNonSupportedFields(options);
return this;
}

public Builder withOptions(OllamaOptions options) {
Objects.requireNonNullElse(options, "The options can not be null.");
Objects.requireNonNull(options, "The options can not be null.");
this.options = OllamaOptions.filterNonSupportedFields(options.toMap());
return this;
}
Expand Down Expand Up @@ -574,6 +588,7 @@ public Flux<ChatResponse> streamingChat(ChatRequest chatRequest) {
public record EmbeddingRequest(
@JsonProperty("model") String model,
@JsonProperty("prompt") String prompt,
@JsonProperty("keep_alive") Duration keepAlive,
@JsonProperty("options") Map<String, Object> options) {

/**
Expand All @@ -582,7 +597,7 @@ public record EmbeddingRequest(
* @param prompt The text to generate embeddings for.
*/
public EmbeddingRequest(String model, String prompt) {
this(model, prompt, null);
this(model, prompt, null, null);
}
}

Expand Down