Testcontainers

Spring AI 提供 Testcontainers 支持,用于测试您的 AI 应用程序。

概述

Testcontainers 允许您在 Docker 容器中针对真实服务运行测试,提供更真实的测试环境。

特性

  • AI 模型的预配置容器
  • 向量数据库容器
  • 与 Spring Boot 测试的轻松集成
  • 自动容器生命周期管理

开始使用

将以下依赖项添加到您的项目中:

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-testcontainers</artifactId>
    <scope>test</scope>
</dependency>

使用方法

@SpringBootTest
class MyAITest {

    @Container
    static OllamaContainer ollama = new OllamaContainer();

    @Test
    void testWithOllama() {
        // 在此处编写测试代码
    }
}

可用容器

  • OllamaContainer
  • MilvusContainer
  • QdrantContainer
  • WeaviateContainer
  • ChromaContainer

配置

可以通过属性或编程方式配置容器:

@Container
static OllamaContainer ollama = new OllamaContainer()
    .withModel("llama2")
    .withPort(11434);

文档有误?请协助编辑

发现文档问题?点击此处直接在 GitHub 上编辑并提交 PR,帮助我们改进文档!