Ollama: Update APIs, Testcontainers, Documentation
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This commit is contained in:
committed by
Christian Tzolov
parent
70c8c5a529
commit
f91ccf0047
@@ -73,5 +73,11 @@
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>ollama</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -139,6 +139,8 @@ public class OllamaApi {
|
||||
* context will be returned. You may choose to use the raw parameter if you are
|
||||
* specifying a full templated prompt in your request to the API, and are managing
|
||||
* history yourself.
|
||||
* @param images (optional) a list of base64-encoded images (for multimodal models such as llava).
|
||||
* @param keepAlive (optional) controls how long the model will stay loaded into memory following the request (default: 5m).
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record GenerateRequest(
|
||||
@@ -503,9 +505,9 @@ public class OllamaApi {
|
||||
* @param evalCount number of tokens in the response.
|
||||
* @param evalDuration time spent generating the response.
|
||||
* @see <a href=
|
||||
* "https://github.com/jmorganca/ollama/blob/main/docs/api.md#generate-a-chat-completion">Chat
|
||||
* "https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion">Chat
|
||||
* Completion API</a>
|
||||
* @see <a href="https://github.com/jmorganca/ollama/blob/main/api/types.go">Ollama
|
||||
* @see <a href="https://github.com/ollama/ollama/blob/main/api/types.go">Ollama
|
||||
* Types</a>
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@@ -573,6 +575,7 @@ public class OllamaApi {
|
||||
*
|
||||
* @param model The name of model to generate embeddings from.
|
||||
* @param prompt The text to generate embeddings for.
|
||||
* @param keepAlive Controls how long the model will stay loaded into memory following the request (default: 5m).
|
||||
* @param options Additional model parameters listed in the documentation for the
|
||||
* Modelfile such as temperature.
|
||||
*/
|
||||
|
||||
@@ -28,6 +28,11 @@ public enum OllamaModel {
|
||||
*/
|
||||
LLAMA2("llama2"),
|
||||
|
||||
/**
|
||||
* Llama 3 is a collection of language models ranging from 8B and 70B parameters.
|
||||
*/
|
||||
LLAMA3("llama3"),
|
||||
|
||||
/**
|
||||
* The 7B parameters model
|
||||
*/
|
||||
@@ -43,6 +48,11 @@ public enum OllamaModel {
|
||||
*/
|
||||
PHI("phi"),
|
||||
|
||||
/**
|
||||
* The Phi-3 3.8B language model
|
||||
*/
|
||||
PHI3("phi3"),
|
||||
|
||||
/**
|
||||
* A fine-tuned Mistral model
|
||||
*/
|
||||
|
||||
@@ -35,10 +35,9 @@ import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
* @author Christian Tzolov
|
||||
* @since 0.8.0
|
||||
* @see <a href=
|
||||
* "https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values">Ollama
|
||||
* "https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values">Ollama
|
||||
* Valid Parameters and Values</a>
|
||||
* @see <a href="https://github.com/jmorganca/ollama/blob/main/api/types.go">Ollama
|
||||
* Types</a>
|
||||
* @see <a href="https://github.com/ollama/ollama/blob/main/api/types.go">Ollama Types</a>
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
@@ -47,6 +46,8 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
|
||||
private static final List<String> NON_SUPPORTED_FIELDS = List.of("model", "format", "keep_alive");
|
||||
|
||||
// Following fields are ptions which must be set when the model is loaded into memory.
|
||||
|
||||
// @formatter:off
|
||||
/**
|
||||
* useNUMA Whether to use NUMA.
|
||||
@@ -110,16 +111,6 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
*/
|
||||
@JsonProperty("use_mlock") private Boolean useMLock;
|
||||
|
||||
/**
|
||||
* ???
|
||||
*/
|
||||
@JsonProperty("rope_frequency_base") private Float ropeFrequencyBase;
|
||||
|
||||
/**
|
||||
* ???
|
||||
*/
|
||||
@JsonProperty("rope_frequency_scale") private Float ropeFrequencyScale;
|
||||
|
||||
/**
|
||||
* Sets the number of threads to use during computation. By default,
|
||||
* Ollama will detect this for optimal performance. It is recommended to set this
|
||||
@@ -128,6 +119,8 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
*/
|
||||
@JsonProperty("num_thread") private Integer numThread;
|
||||
|
||||
// Following fields are predict options used at runtime.
|
||||
|
||||
/**
|
||||
* ???
|
||||
*/
|
||||
@@ -156,8 +149,8 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
/**
|
||||
* Works together with top-k. A higher value (e.g., 0.95) will lead to
|
||||
* more diverse text, while a lower value (e.g., 0.5) will generate more focused and
|
||||
* conservative text. (Default: 0.9)
|
||||
*/
|
||||
* conservative text. (Default: 0.9)
|
||||
*/
|
||||
@JsonProperty("top_p") private Float topP;
|
||||
|
||||
/**
|
||||
@@ -208,16 +201,15 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
@JsonProperty("mirostat") private Integer mirostat;
|
||||
|
||||
/**
|
||||
* Influences how quickly the algorithm responds to feedback from
|
||||
* the generated text. A lower learning rate will result in slower adjustments, while
|
||||
* a higher learning rate will make the algorithm more responsive. (Default: 0.1).
|
||||
* Controls the balance between coherence and diversity of the output.
|
||||
* A lower value will result in more focused and coherent text. (Default: 5.0)
|
||||
*/
|
||||
@JsonProperty("mirostat_tau") private Float mirostatTau;
|
||||
|
||||
/**
|
||||
* Controls the balance between coherence and diversity of the
|
||||
* output. A lower value will result in more focused and coherent text. (Default:
|
||||
* 5.0).
|
||||
* Influences how quickly the algorithm responds to feedback from the generated text.
|
||||
* A lower learning rate will result in slower adjustments, while a higher learning rate
|
||||
* will make the algorithm more responsive. (Default: 0.1)
|
||||
*/
|
||||
@JsonProperty("mirostat_eta") private Float mirostatEta;
|
||||
|
||||
@@ -235,6 +227,7 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
|
||||
|
||||
// Following fields are not part of the Ollama Options API but part of the Request.
|
||||
|
||||
/**
|
||||
* NOTE: Synthetic field not part of the official Ollama API.
|
||||
* Used to allow overriding the model name with prompt options.
|
||||
@@ -341,16 +334,6 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
public OllamaOptions withRopeFrequencyBase(Float ropeFrequencyBase) {
|
||||
this.ropeFrequencyBase = ropeFrequencyBase;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OllamaOptions withRopeFrequencyScale(Float ropeFrequencyScale) {
|
||||
this.ropeFrequencyScale = ropeFrequencyScale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OllamaOptions withNumThread(Integer numThread) {
|
||||
this.numThread = numThread;
|
||||
return this;
|
||||
@@ -553,22 +536,6 @@ public class OllamaOptions implements ChatOptions, EmbeddingOptions {
|
||||
this.useMLock = useMLock;
|
||||
}
|
||||
|
||||
public Float getRopeFrequencyBase() {
|
||||
return this.ropeFrequencyBase;
|
||||
}
|
||||
|
||||
public void setRopeFrequencyBase(Float ropeFrequencyBase) {
|
||||
this.ropeFrequencyBase = ropeFrequencyBase;
|
||||
}
|
||||
|
||||
public Float getRopeFrequencyScale() {
|
||||
return this.ropeFrequencyScale;
|
||||
}
|
||||
|
||||
public void setRopeFrequencyScale(Float ropeFrequencyScale) {
|
||||
this.ropeFrequencyScale = ropeFrequencyScale;
|
||||
}
|
||||
|
||||
public Integer getNumThread() {
|
||||
return this.numThread;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.ai.chat.metadata.Usage;
|
||||
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
@@ -50,6 +49,7 @@ import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.testcontainers.ollama.OllamaContainer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -63,7 +63,7 @@ class OllamaChatClientIT {
|
||||
private static final Log logger = LogFactory.getLog(OllamaChatClientIT.class);
|
||||
|
||||
@Container
|
||||
static GenericContainer<?> ollamaContainer = new GenericContainer<>("ollama/ollama:0.1.29").withExposedPorts(11434);
|
||||
static OllamaContainer ollamaContainer = new OllamaContainer("ollama/ollama:0.1.32");
|
||||
|
||||
static String baseUrl;
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
@@ -39,6 +38,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.testcontainers.ollama.OllamaContainer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -52,7 +52,7 @@ class OllamaChatClientMultimodalIT {
|
||||
private static final Log logger = LogFactory.getLog(OllamaChatClientIT.class);
|
||||
|
||||
@Container
|
||||
static GenericContainer<?> ollamaContainer = new GenericContainer<>("ollama/ollama:0.1.29").withExposedPorts(11434);
|
||||
static OllamaContainer ollamaContainer = new OllamaContainer("ollama/ollama:0.1.32");
|
||||
|
||||
static String baseUrl;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.testcontainers.ollama.OllamaContainer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -45,7 +46,7 @@ class OllamaEmbeddingClientIT {
|
||||
private static final Log logger = LogFactory.getLog(OllamaApiIT.class);
|
||||
|
||||
@Container
|
||||
static GenericContainer<?> ollamaContainer = new GenericContainer<>("ollama/ollama:0.1.29").withExposedPorts(11434);
|
||||
static OllamaContainer ollamaContainer = new OllamaContainer("ollama/ollama:0.1.32");
|
||||
|
||||
static String baseUrl;
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.ollama.OllamaContainer;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.ai.ollama.api.OllamaApi.ChatRequest;
|
||||
@@ -50,7 +50,7 @@ public class OllamaApiIT {
|
||||
private static final Log logger = LogFactory.getLog(OllamaApiIT.class);
|
||||
|
||||
@Container
|
||||
static GenericContainer<?> ollamaContainer = new GenericContainer<>("ollama/ollama:0.1.29").withExposedPorts(11434);
|
||||
static OllamaContainer ollamaContainer = new OllamaContainer("ollama/ollama:0.1.32");
|
||||
|
||||
static OllamaApi ollamaApi;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user