diff --git a/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaEmbeddingModel.java b/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaEmbeddingModel.java index 9a5e7a8ab54..b3b64cd1339 100644 --- a/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaEmbeddingModel.java +++ b/models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaEmbeddingModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,6 +60,7 @@ * @author Christian Tzolov * @author Thomas Vitale * @author Ilayaperumal Gopinathan + * @author Jonghoon Park * @since 0.8.0 */ public class OllamaEmbeddingModel extends AbstractEmbeddingModel { @@ -188,7 +189,7 @@ public void setObservationConvention(EmbeddingModelObservationConvention observa public static class DurationParser { - private static final Pattern PATTERN = Pattern.compile("(\\d+)(ms|s|m|h)"); + private static final Pattern PATTERN = Pattern.compile("(-?\\d+)(ms|s|m|h)"); public static Duration parse(String input) { diff --git a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaEmbeddingRequestTests.java b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaEmbeddingRequestTests.java index b28e868ef6b..9cc260a72c0 100644 --- a/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaEmbeddingRequestTests.java +++ b/models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaEmbeddingRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.ai.ollama; +import java.time.Duration; import java.util.List; import org.junit.jupiter.api.Test; @@ -28,6 +29,7 @@ /** * @author Christian Tzolov * @author Thomas Vitale + * @author Jonghoon Park */ public class OllamaEmbeddingRequestTests { @@ -67,4 +69,14 @@ public void ollamaEmbeddingRequestRequestOptions() { assertThat(request.input()).isEqualTo(List.of("Hello")); } + @Test + public void ollamaEmbeddingRequestWithNegativeKeepAlive() { + + var promptOptions = OllamaOptions.builder().model("PROMPT_MODEL").keepAlive("-1m").build(); + + var request = this.embeddingModel.ollamaEmbeddingRequest(List.of("Hello"), promptOptions); + + assertThat(request.keepAlive()).isEqualTo(Duration.ofMinutes(-1)); + } + }