Getting Started
本部分提供了有关如何开始使用 Spring AI 的切入点。
This section offers jumping off points for how to get started using Spring AI.
您应该根据需要遵循以下每个部分中的步骤。
You should follow the steps in each of the following sections according to your needs.
Spring AI 支持 Spring Boot 3.4.x。当 Spring Boot 3.5.x 发布时,我们也将支持它。 |
Spring AI supports Spring Boot 3.4.x. When Spring Boot 3.5.x is released, we will support that as well. |
Spring Initializr
进入 start.spring.io,选择要在新应用程序中使用的 AI 模型和向量存储。
Head on over to start.spring.io and select the AI Models and Vector Stores that you want to use in your new applications.
Artifact Repositories
Milestones - Use Maven Central
截至 1.0.0-M6,版本可在 Maven Central 中找到。您的构建文件无需更改。
As of 1.0.0-M6, releases are available in Maven Central. No changes to your build file are required.
Snapshots - Add Snapshot Repositories
要使用 Snapshot(和 1.0.0-M6 之前的里程碑)版本,您需要在构建文件中添加以下快照存储库。
To use the Snapshot (and pre 1.0.0-M6 milestone) versions, you need to add the following snapshot repositories in your build file.
将以下存储库定义添加到您的 Maven 或 Gradle 构建文件:
Add the following repository definitions to your Maven or Gradle build file:
-
Maven
-
Gradle
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<name>Central Portal Snapshots</name>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
maven {
name = 'Central Portal Snapshots'
url = 'https://central.sonatype.com/repository/maven-snapshots/'
}
}
NOTE: 使用 Maven 和 Spring AI 快照时,请注意您的 Maven 镜像配置。如果您在 settings.xml
中配置了镜像,如下所示:
NOTE: When using Maven with Spring AI snapshots, pay attention to your Maven mirror configuration. If you have configured a mirror in your settings.xml
like this:
<mirror>
<id>my-mirror</id>
<mirrorOf>*</mirrorOf>
<url>https://my-company-repository.com/maven</url>
</mirror>
通配符 *
会将所有存储库请求重定向到您的镜像,从而阻止访问 Spring 快照存储库。要解决此问题,请修改 mirrorOf
配置以排除 Spring 存储库:
The wildcard *
will redirect all repository requests to your mirror, preventing access to Spring snapshot repositories. To fix this, modify the mirrorOf
configuration to exclude Spring repositories:
<mirror>
<id>my-mirror</id>
<mirrorOf>*,!spring-snapshots,!central-portal-snapshots</mirrorOf>
<url>https://my-company-repository.com/maven</url>
</mirror>
此配置允许 Maven 直接访问 Spring 快照存储库,同时仍将您的镜像用于其他依赖项。
This configuration allows Maven to access Spring snapshot repositories directly while still using your mirror for other dependencies.
Dependency Management
Spring AI 物料清单 (BOM) 声明了给定 Spring AI 版本使用的所有依赖项的推荐版本。这是一个仅 BOM 版本,它仅包含依赖管理,不包含插件声明或直接引用 Spring 或 Spring Boot。您可以使用 Spring Boot 父 POM,或使用 Spring Boot 的 BOM ( spring-boot-dependencies
) 来管理 Spring Boot 版本。
The Spring AI Bill of Materials (BOM) declares the recommended versions of all the dependencies used by a given release of Spring AI.
This is a BOM-only version and it just contains dependency management and no plugin declarations or direct references to Spring or Spring Boot.
You can use the Spring Boot parent POM, or use the BOM from Spring Boot (spring-boot-dependencies
) to manage Spring Boot versions.
将 BOM 添加到您的项目:
Add the BOM to your project:
- Maven
-
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-bom</artifactId> <version>1.0.0-SNAPSHOT</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
- Gradle
-
dependencies { implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT") // Replace the following with the starter dependencies of specific modules you wish to use implementation 'org.springframework.ai:spring-ai-openai' }
Gradle 用户还可以通过利用 Gradle (5.0+) 本机支持使用 Maven BOM 声明依赖约束来使用 Spring AI BOM。这通过将“platform”依赖处理程序方法添加到 Gradle 构建脚本的依赖项部分来实现。
Gradle users can also use the Spring AI BOM by leveraging Gradle (5.0+) native support for declaring dependency constraints using a Maven BOM. This is implemented by adding a 'platform' dependency handler method to the dependencies section of your Gradle build script.