Skip to content

Commit c7b7d69

Browse files
eddumelendezilayaperumalg
authored andcommitted
Update test and docs to use DockerModelRunnerContainer
Testcontainers offers `DockerModelRunnerContainer`. Replace the `SocatContainer` usage with `DockerModelRunnerContainer`. Auto-cherry-pick to 1.0.x Fixes #4353 Signed-off-by: Eddú Meléndez <[email protected]>
1 parent 1decd34 commit c7b7d69

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 4 additions & 5 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;
@@ -77,7 +77,7 @@ class DockerModelRunnerWithOpenAiChatModelIT {
7777
private static final String DEFAULT_MODEL = "ai/gemma3:4B-F16";
7878

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

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

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

9494
RestAssured.given().baseUri(baseUrl).body("""
9595
{
@@ -352,8 +352,7 @@ static class Config {
352352

353353
@Bean
354354
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();
355+
return OpenAiApi.builder().baseUrl(DMR.getOpenAIEndpoint()).apiKey("test").build();
357356
}
358357

359358
@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)