Skip to content

Commit 70d5c56

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 70d5c56

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

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

Lines changed: 5 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,15 @@
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 https://docs.docker.com/desktop/features/model-runner/")
7373
class DockerModelRunnerWithOpenAiChatModelIT {
7474

7575
private static final Logger logger = LoggerFactory.getLogger(DockerModelRunnerWithOpenAiChatModelIT.class);
7676

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)