Skip to content

Commit 3846d75

Browse files
committed
Ollama: support path config
Signed-off-by: lambochen <[email protected]>
1 parent 925def2 commit 3846d75

File tree

7 files changed

+378
-11
lines changed

7 files changed

+378
-11
lines changed

auto-configurations/models/spring-ai-autoconfigure-model-ollama/src/main/java/org/springframework/ai/model/ollama/autoconfigure/OllamaApiAutoConfiguration.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @author Eddú Meléndez
3434
* @author Thomas Vitale
3535
* @author Ilayaperumal Gopinathan
36+
* @author lambochen
3637
* @since 0.8.0
3738
*/
3839
@AutoConfiguration
@@ -53,6 +54,13 @@ public OllamaApi ollamaApi(OllamaConnectionDetails connectionDetails,
5354
ObjectProvider<WebClient.Builder> webClientBuilderProvider) {
5455
return OllamaApi.builder()
5556
.baseUrl(connectionDetails.getBaseUrl())
57+
.chatPath(connectionDetails.getChatPath())
58+
.embedPath(connectionDetails.getEmbedPath())
59+
.listModelsPath(connectionDetails.getListModelsPath())
60+
.showModelPath(connectionDetails.getShowModelPath())
61+
.copyModelPath(connectionDetails.getCopyModelPath())
62+
.deleteModelPath(connectionDetails.getDeleteModelPath())
63+
.pullModelPath(connectionDetails.getPullModelPath())
5664
.restClientBuilder(restClientBuilderProvider.getIfAvailable(RestClient::builder))
5765
.webClientBuilder(webClientBuilderProvider.getIfAvailable(WebClient::builder))
5866
.build();
@@ -71,6 +79,41 @@ public String getBaseUrl() {
7179
return this.properties.getBaseUrl();
7280
}
7381

82+
@Override
83+
public String getChatPath() {
84+
return this.properties.getChatPath();
85+
}
86+
87+
@Override
88+
public String getEmbedPath() {
89+
return this.properties.getEmbedPath();
90+
}
91+
92+
@Override
93+
public String getListModelsPath() {
94+
return this.properties.getListModelsPath();
95+
}
96+
97+
@Override
98+
public String getShowModelPath() {
99+
return this.properties.getShowModelPath();
100+
}
101+
102+
@Override
103+
public String getCopyModelPath() {
104+
return this.properties.getCopyModelPath();
105+
}
106+
107+
@Override
108+
public String getDeleteModelPath() {
109+
return this.properties.getDeleteModelPath();
110+
}
111+
112+
@Override
113+
public String getPullModelPath() {
114+
return this.properties.getPullModelPath();
115+
}
116+
74117
}
75118

76119
}

auto-configurations/models/spring-ai-autoconfigure-model-ollama/src/main/java/org/springframework/ai/model/ollama/autoconfigure/OllamaConnectionDetails.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@
2222
* Connection details for an Ollama service.
2323
*
2424
* @author Eddú Meléndez
25+
* @author lambochen
2526
*/
2627
public interface OllamaConnectionDetails extends ConnectionDetails {
2728

2829
String getBaseUrl();
2930

31+
String getChatPath();
32+
33+
String getEmbedPath();
34+
35+
String getListModelsPath();
36+
37+
String getShowModelPath();
38+
39+
String getCopyModelPath();
40+
41+
String getDeleteModelPath();
42+
43+
String getPullModelPath();
44+
3045
}

auto-configurations/models/spring-ai-autoconfigure-model-ollama/src/main/java/org/springframework/ai/model/ollama/autoconfigure/OllamaConnectionProperties.java

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
package org.springframework.ai.model.ollama.autoconfigure;
1818

19+
import org.springframework.ai.ollama.api.common.OllamaApiConstants;
1920
import org.springframework.boot.context.properties.ConfigurationProperties;
2021

2122
/**
2223
* Ollama connection autoconfiguration properties.
2324
*
2425
* @author Christian Tzolov
26+
* @author lambochen
2527
* @since 0.8.0
2628
*/
2729
@ConfigurationProperties(OllamaConnectionProperties.CONFIG_PREFIX)
@@ -32,7 +34,42 @@ public class OllamaConnectionProperties {
3234
/**
3335
* Base URL where Ollama API server is running.
3436
*/
35-
private String baseUrl = "http://localhost:11434";
37+
private String baseUrl = OllamaApiConstants.DEFAULT_BASE_URL;
38+
39+
/**
40+
* The path of the chat endpoint.
41+
*/
42+
private String chatPath = OllamaApiConstants.DEFAULT_CHAT_PATH;
43+
44+
/**
45+
* The path of the embed endpoint.
46+
*/
47+
private String embedPath = OllamaApiConstants.DEFAULT_EMBED_PATH;
48+
49+
/**
50+
* The path of the list models endpoint.
51+
*/
52+
private String listModelsPath = OllamaApiConstants.DEFAULT_LIST_MODELS_PATH;
53+
54+
/**
55+
* The path of the show model endpoint.
56+
*/
57+
private String showModelPath = OllamaApiConstants.DEFAULT_SHOW_MODEL_PATH;
58+
59+
/**
60+
* The path of the copy model endpoint.
61+
*/
62+
private String copyModelPath = OllamaApiConstants.DEFAULT_COPY_MODEL_PATH;
63+
64+
/**
65+
* The path of the delete model endpoint.
66+
*/
67+
private String deleteModelPath = OllamaApiConstants.DEFAULT_DELETE_MODEL_PATH;
68+
69+
/**
70+
* The path of the pull model endpoint.
71+
*/
72+
private String pullModelPath = OllamaApiConstants.DEFAULT_PULL_MODEL_PATH;
3673

3774
public String getBaseUrl() {
3875
return this.baseUrl;
@@ -42,4 +79,60 @@ public void setBaseUrl(String baseUrl) {
4279
this.baseUrl = baseUrl;
4380
}
4481

82+
public String getChatPath() {
83+
return chatPath;
84+
}
85+
86+
public void setChatPath(String chatPath) {
87+
this.chatPath = chatPath;
88+
}
89+
90+
public String getEmbedPath() {
91+
return embedPath;
92+
}
93+
94+
public void setEmbedPath(String embedPath) {
95+
this.embedPath = embedPath;
96+
}
97+
98+
public String getListModelsPath() {
99+
return listModelsPath;
100+
}
101+
102+
public void setListModelsPath(String listModelsPath) {
103+
this.listModelsPath = listModelsPath;
104+
}
105+
106+
public String getShowModelPath() {
107+
return showModelPath;
108+
}
109+
110+
public void setShowModelPath(String showModelPath) {
111+
this.showModelPath = showModelPath;
112+
}
113+
114+
public String getCopyModelPath() {
115+
return copyModelPath;
116+
}
117+
118+
public void setCopyModelPath(String copyModelPath) {
119+
this.copyModelPath = copyModelPath;
120+
}
121+
122+
public String getDeleteModelPath() {
123+
return deleteModelPath;
124+
}
125+
126+
public void setDeleteModelPath(String deleteModelPath) {
127+
this.deleteModelPath = deleteModelPath;
128+
}
129+
130+
public String getPullModelPath() {
131+
return pullModelPath;
132+
}
133+
134+
public void setPullModelPath(String pullModelPath) {
135+
this.pullModelPath = pullModelPath;
136+
}
137+
45138
}

0 commit comments

Comments
 (0)