You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/ollama-chat.adoc
+11-15Lines changed: 11 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ Spring AI supports the Ollama text generation with `OllamaChatClient`.
6
6
== Prerequisites
7
7
8
8
You first need to run Ollama on your local machine.
9
-
Refer to the official Ollama project link:https://github.com/jmorganca/ollama[README] to get started running models on your local machine.
9
+
Refer to the official Ollama project link:https://github.com/ollama/ollama[README] to get started running models on your local machine.
10
10
11
-
NOTE: installing `ollama run llama2` will download a 4GB docker image.
11
+
NOTE: installing `ollama run llama3` will download a 4.7GB model artifact.
12
12
13
13
=== Add Repositories and BOM
14
14
@@ -53,7 +53,7 @@ The prefix `spring.ai.ollama` is the property prefix to configure the connection
53
53
|====
54
54
55
55
The prefix `spring.ai.ollama.chat.options` is the property prefix that configures the Ollama chat client .
56
-
It includes the Ollama request (advanced) parameters such as the `model`, `keep-alive`, `format` and `template` as well as the Ollama model `options` properties.
56
+
It includes the Ollama request (advanced) parameters such as the `model`, `keep-alive`, and `format` as well as the Ollama model `options` properties.
57
57
58
58
Here are the advanced request parameter for the Ollama chat client:
59
59
@@ -62,12 +62,12 @@ Here are the advanced request parameter for the Ollama chat client:
| spring.ai.ollama.chat.options.model | The name of the https://github.com/ollama/ollama?tab=readme-ov-file#model-library[supported models] to use. | mistral
65
+
| spring.ai.ollama.chat.options.model | The name of the https://github.com/ollama/ollama?tab=readme-ov-file#model-library[supported model] to use. | mistral
66
66
| spring.ai.ollama.chat.options.format | The format to return a response in. Currently the only accepted value is `json` | -
67
67
| spring.ai.ollama.chat.options.keep_alive | Controls how long the model will stay loaded into memory following the request | 5m
68
68
|====
69
69
70
-
The `options` properties are based on the link:https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values[Ollama Valid Parameters and Values] and link:https://github.com/jmorganca/ollama/blob/main/api/types.go[Ollama Types]. The default values are based on: link:https://github.com/ollama/ollama/blob/b538dc3858014f94b099730a592751a5454cab0a/api/types.go#L364[Ollama type defaults].
70
+
The remaining `options` properties are based on the link:https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values[Ollama Valid Parameters and Values] and link:https://github.com/ollama/ollama/blob/main/api/types.go[Ollama Types]. The default values are based on: link:https://github.com/ollama/ollama/blob/b538dc3858014f94b099730a592751a5454cab0a/api/types.go#L364[Ollama type defaults].
71
71
72
72
[cols="3,6,1"]
73
73
|====
@@ -84,8 +84,6 @@ The `options` properties are based on the link:https://github.com/jmorganca/olla
| spring.ai.ollama.chat.options.num-thread | Sets the number of threads to use during computation. By default, Ollama will detect this for optimal performance. It is recommended to set this value to the number of physical CPU cores your system has (as opposed to the logical number of cores). 0 = let the runtime decide | 0
| spring.ai.ollama.chat.options.seed | Sets the random number seed to use for generation. Setting this to a specific number will make the model generate the same text for the same prompt. | -1
@@ -100,14 +98,12 @@ The `options` properties are based on the link:https://github.com/jmorganca/olla
| spring.ai.ollama.chat.options.mirostat-tau | 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. | 5.0
104
-
| spring.ai.ollama.chat.options.mirostat-eta | Controls the balance between coherence and diversity of the output. A lower value will result in more focused and coherent text. | 0.1
101
+
| spring.ai.ollama.chat.options.mirostat-tau | Controls the balance between coherence and diversity of the output. A lower value will result in more focused and coherent text. | 5.0
102
+
| spring.ai.ollama.chat.options.mirostat-eta | 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. | 0.1
| spring.ai.ollama.chat.options.stop | Sets the stop sequences to use. When this pattern is encountered the LLM will stop generating text and return. Multiple stop patterns may be set by specifying multiple separate stop parameters in a modelfile. | -
107
105
|====
108
106
109
-
NOTE: The list of options for chat is to be reviewed. This https://github.com/spring-projects/spring-ai/issues/230[issue] will track progress.
110
-
111
107
TIP: All properties prefixed with `spring.ai.ollama.chat.options` can be overridden at runtime by adding a request specific <<chat-options>> to the `Prompt` call.
112
108
113
109
== Runtime Options [[chat-options]]
@@ -270,13 +266,13 @@ The `OllamaOptions` provides the configuration information for all chat requests
270
266
271
267
== Low-level OllamaApi Client [[low-level-api]]
272
268
273
-
The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/api/OllamaApi.java[OllamaApi] provides is lightweight Java client for Ollama Chat API link:https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion[Ollama Chat Completion API].
269
+
The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/api/OllamaApi.java[OllamaApi] provides a lightweight Java client for the Ollama Chat Completion API link:https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion[Ollama Chat Completion API].
274
270
275
-
Following class diagram illustrates the `OllamaApi` chat interfaces and building blocks:
271
+
The following class diagram illustrates the `OllamaApi` chat interfaces and building blocks:
276
272
277
273
image::ollama-chat-completion-api.jpg[OllamaApi Chat Completion API Diagram, 800, 600]
278
274
279
-
Here is a simple snippet how to use the api programmatically:
275
+
Here is a simple snippet showing how to use the API programmatically:
280
276
281
277
[source,java]
282
278
----
@@ -288,7 +284,7 @@ var request = ChatRequest.builder("orca-mini")
288
284
.withStream(false) // not streaming
289
285
.withMessages(List.of(
290
286
Message.builder(Role.SYSTEM)
291
-
.withContent("You are geography teacher. You are talking to a student.")
287
+
.withContent("You are a geography teacher. You are talking to a student.")
292
288
.build(),
293
289
Message.builder(Role.USER)
294
290
.withContent("What is the capital of Bulgaria and what is the size? "
0 commit comments