Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -33,6 +33,7 @@
* @author Eddú Meléndez
* @author Thomas Vitale
* @author Ilayaperumal Gopinathan
* @author lambochen
* @since 0.8.0
*/
@AutoConfiguration
Expand All @@ -53,6 +54,13 @@ public OllamaApi ollamaApi(OllamaConnectionDetails connectionDetails,
ObjectProvider<WebClient.Builder> webClientBuilderProvider) {
return OllamaApi.builder()
.baseUrl(connectionDetails.getBaseUrl())
.chatPath(connectionDetails.getChatPath())
.embedPath(connectionDetails.getEmbedPath())
.listModelsPath(connectionDetails.getListModelsPath())
.showModelPath(connectionDetails.getShowModelPath())
.copyModelPath(connectionDetails.getCopyModelPath())
.deleteModelPath(connectionDetails.getDeleteModelPath())
.pullModelPath(connectionDetails.getPullModelPath())
.restClientBuilder(restClientBuilderProvider.getIfAvailable(RestClient::builder))
.webClientBuilder(webClientBuilderProvider.getIfAvailable(WebClient::builder))
.build();
Expand All @@ -71,6 +79,41 @@ public String getBaseUrl() {
return this.properties.getBaseUrl();
}

@Override
public String getChatPath() {
return this.properties.getChatPath();
}

@Override
public String getEmbedPath() {
return this.properties.getEmbedPath();
}

@Override
public String getListModelsPath() {
return this.properties.getListModelsPath();
}

@Override
public String getShowModelPath() {
return this.properties.getShowModelPath();
}

@Override
public String getCopyModelPath() {
return this.properties.getCopyModelPath();
}

@Override
public String getDeleteModelPath() {
return this.properties.getDeleteModelPath();
}

@Override
public String getPullModelPath() {
return this.properties.getPullModelPath();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@
* Connection details for an Ollama service.
*
* @author Eddú Meléndez
* @author lambochen
*/
public interface OllamaConnectionDetails extends ConnectionDetails {

String getBaseUrl();

String getChatPath();

String getEmbedPath();

String getListModelsPath();

String getShowModelPath();

String getCopyModelPath();

String getDeleteModelPath();

String getPullModelPath();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

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

import org.springframework.ai.ollama.api.common.OllamaApiConstants;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* Ollama connection autoconfiguration properties.
*
* @author Christian Tzolov
* @author lambochen
* @since 0.8.0
*/
@ConfigurationProperties(OllamaConnectionProperties.CONFIG_PREFIX)
Expand All @@ -32,7 +34,42 @@ public class OllamaConnectionProperties {
/**
* Base URL where Ollama API server is running.
*/
private String baseUrl = "http://localhost:11434";
private String baseUrl = OllamaApiConstants.DEFAULT_BASE_URL;

/**
* The path of the chat endpoint.
*/
private String chatPath = OllamaApiConstants.DEFAULT_CHAT_PATH;

/**
* The path of the embed endpoint.
*/
private String embedPath = OllamaApiConstants.DEFAULT_EMBED_PATH;

/**
* The path of the list models endpoint.
*/
private String listModelsPath = OllamaApiConstants.DEFAULT_LIST_MODELS_PATH;

/**
* The path of the show model endpoint.
*/
private String showModelPath = OllamaApiConstants.DEFAULT_SHOW_MODEL_PATH;

/**
* The path of the copy model endpoint.
*/
private String copyModelPath = OllamaApiConstants.DEFAULT_COPY_MODEL_PATH;

/**
* The path of the delete model endpoint.
*/
private String deleteModelPath = OllamaApiConstants.DEFAULT_DELETE_MODEL_PATH;

/**
* The path of the pull model endpoint.
*/
private String pullModelPath = OllamaApiConstants.DEFAULT_PULL_MODEL_PATH;

public String getBaseUrl() {
return this.baseUrl;
Expand All @@ -42,4 +79,60 @@ public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getChatPath() {
return chatPath;
}

public void setChatPath(String chatPath) {
this.chatPath = chatPath;
}

public String getEmbedPath() {
return embedPath;
}

public void setEmbedPath(String embedPath) {
this.embedPath = embedPath;
}

public String getListModelsPath() {
return listModelsPath;
}

public void setListModelsPath(String listModelsPath) {
this.listModelsPath = listModelsPath;
}

public String getShowModelPath() {
return showModelPath;
}

public void setShowModelPath(String showModelPath) {
this.showModelPath = showModelPath;
}

public String getCopyModelPath() {
return copyModelPath;
}

public void setCopyModelPath(String copyModelPath) {
this.copyModelPath = copyModelPath;
}

public String getDeleteModelPath() {
return deleteModelPath;
}

public void setDeleteModelPath(String deleteModelPath) {
this.deleteModelPath = deleteModelPath;
}

public String getPullModelPath() {
return pullModelPath;
}

public void setPullModelPath(String pullModelPath) {
this.pullModelPath = pullModelPath;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.springframework.ai.model.ollama.autoconfigure;

import org.junit.jupiter.api.Test;
import org.springframework.ai.ollama.api.OllamaApi;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

/**
* @author lambochen
*/
public class OllamaApiBuilderTests {

@Test
void fullBuilder() {
OllamaApi ollamaApi = OllamaApi.builder()
.baseUrl("http://localhost:11434")
.chatPath("/api/chat")
.embedPath("/api/embeddings")
.listModelsPath("/api/tags")
.showModelPath("/api/show")
.copyModelPath("/api/copy")
.deleteModelPath("/api/delete")
.pullModelPath("/api/pull")
.build();

assertThat(ollamaApi).isNotNull();
}

@Test
void defaultBuilder() {
OllamaApi ollamaApi = OllamaApi.builder().build();
assertThat(ollamaApi).isNotNull();
}

@Test
void invalidPath() {
assertThatThrownBy(() -> OllamaApi.builder().chatPath("").build()).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().embedPath("").build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().listModelsPath("").build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().showModelPath("").build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().copyModelPath("").build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().deleteModelPath("").build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().pullModelPath("").build())
.isInstanceOf(IllegalArgumentException.class);

assertThatThrownBy(() -> OllamaApi.builder().chatPath(null).build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().embedPath(null).build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().listModelsPath(null).build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().showModelPath(null).build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().copyModelPath(null).build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().deleteModelPath(null).build())
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> OllamaApi.builder().pullModelPath(null).build())
.isInstanceOf(IllegalArgumentException.class);
}

}
Loading