Skip to content

Commit a7720d3

Browse files
committed
Update test and docs to use DockerModelRunnerContainer
Testcontainers offers `DockerModelRunnerContainer`. Replace the `SocatContainer` usage with `DockerModelRunnerContainer`. Signed-off-by: Eddú Meléndez <[email protected]>
1 parent c2103b0 commit a7720d3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/DockerModelRunnerWithOpenAiChatModelIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.junit.jupiter.api.Test;
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
32-
import org.testcontainers.containers.SocatContainer;
32+
import org.testcontainers.containers.DockerModelRunnerContainer;
3333
import org.testcontainers.junit.jupiter.Container;
3434
import org.testcontainers.junit.jupiter.Testcontainers;
3535
import reactor.core.publisher.Flux;
@@ -69,15 +69,16 @@
6969
*/
7070
@Testcontainers
7171
@SpringBootTest(classes = DockerModelRunnerWithOpenAiChatModelIT.Config.class)
72-
@Disabled("Requires Docker Model Runner enabled. See https://docs.docker.com/desktop/features/model-runner/")
72+
// @Disabled("Requires Docker Model Runner enabled. See
73+
// https://docs.docker.com/desktop/features/model-runner/")
7374
class DockerModelRunnerWithOpenAiChatModelIT {
7475

7576
private static final Logger logger = LoggerFactory.getLogger(DockerModelRunnerWithOpenAiChatModelIT.class);
7677

7778
private static final String DEFAULT_MODEL = "ai/gemma3:4B-F16";
7879

7980
@Container
80-
private static final SocatContainer socat = new SocatContainer().withTarget(80, "model-runner.docker.internal");
81+
private static final DockerModelRunnerContainer DMR = new DockerModelRunnerContainer("alpine/socat:1.7.4.3-r0");
8182

8283
@Value("classpath:/prompts/system-message.st")
8384
private Resource systemResource;
@@ -89,7 +90,7 @@ class DockerModelRunnerWithOpenAiChatModelIT {
8990
public static void beforeAll() throws IOException, InterruptedException {
9091
logger.info("Start pulling the '" + DEFAULT_MODEL + "' generative ... would take several minutes ...");
9192

92-
String baseUrl = "http://%s:%d".formatted(socat.getHost(), socat.getMappedPort(80));
93+
String baseUrl = "http://%s:%d".formatted(DMR.getHost(), DMR.getMappedPort(80));
9394

9495
RestAssured.given().baseUri(baseUrl).body("""
9596
{
@@ -352,8 +353,7 @@ static class Config {
352353

353354
@Bean
354355
public OpenAiApi chatCompletionApi() {
355-
var baseUrl = "http://%s:%d/engines".formatted(socat.getHost(), socat.getMappedPort(80));
356-
return OpenAiApi.builder().baseUrl(baseUrl).apiKey("test").build();
356+
return OpenAiApi.builder().baseUrl(DMR.getOpenAIEndpoint()).apiKey("test").build();
357357
}
358358

359359
@Bean

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/dmr-chat.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Option 2:
2727
[source,java]
2828
----
2929
@Container
30-
private static final SocatContainer socat = new SocatContainer().withTarget(80, "model-runner.docker.internal");
30+
private static final DockerModelRunnerContainer DMR = new DockerModelRunnerContainer("alpine/socat:1.7.4.3-r0");
3131
3232
@Bean
3333
public OpenAiApi chatCompletionApi() {
34-
var baseUrl = "http://%s:%d/engines".formatted(socat.getHost(), socat.getMappedPort(80));
34+
var baseUrl = DMR.getOpenAIEndpoint();
3535
return OpenAiApi.builder().baseUrl(baseUrl).apiKey("test").build();
3636
}
3737
----

0 commit comments

Comments
 (0)