Skip to content

Commit 29fde4f

Browse files
dev-jonghoonparkilayaperumalg
authored andcommitted
Make allow negative keep alive value with OllamaEmbeddingModel
Signed-off-by: jonghoon park <[email protected]>
1 parent 092bbae commit 29fde4f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Diff for: models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/OllamaEmbeddingModel.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,6 +60,7 @@
6060
* @author Christian Tzolov
6161
* @author Thomas Vitale
6262
* @author Ilayaperumal Gopinathan
63+
* @author Jonghoon Park
6364
* @since 0.8.0
6465
*/
6566
public class OllamaEmbeddingModel extends AbstractEmbeddingModel {
@@ -188,7 +189,7 @@ public void setObservationConvention(EmbeddingModelObservationConvention observa
188189

189190
public static class DurationParser {
190191

191-
private static final Pattern PATTERN = Pattern.compile("(\\d+)(ms|s|m|h)");
192+
private static final Pattern PATTERN = Pattern.compile("(-?\\d+)(ms|s|m|h)");
192193

193194
public static Duration parse(String input) {
194195

Diff for: models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaEmbeddingRequestTests.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ai.ollama;
1818

19+
import java.time.Duration;
1920
import java.util.List;
2021

2122
import org.junit.jupiter.api.Test;
@@ -28,6 +29,7 @@
2829
/**
2930
* @author Christian Tzolov
3031
* @author Thomas Vitale
32+
* @author Jonghoon Park
3133
*/
3234
public class OllamaEmbeddingRequestTests {
3335

@@ -67,4 +69,14 @@ public void ollamaEmbeddingRequestRequestOptions() {
6769
assertThat(request.input()).isEqualTo(List.of("Hello"));
6870
}
6971

72+
@Test
73+
public void ollamaEmbeddingRequestWithNegativeKeepAlive() {
74+
75+
var promptOptions = OllamaOptions.builder().model("PROMPT_MODEL").keepAlive("-1m").build();
76+
77+
var request = this.embeddingModel.ollamaEmbeddingRequest(List.of("Hello"), promptOptions);
78+
79+
assertThat(request.keepAlive()).isEqualTo(Duration.ofMinutes(-1));
80+
}
81+
7082
}

0 commit comments

Comments
 (0)