当前位置:首页 » 《关注互联网》 » 正文

Spring AI

18 人参与  2024年05月06日 13:50  分类 : 《关注互联网》  评论

点击全文阅读


Spring AI

文章目录

Spring AI关于 Spring AI使用Spring CLISpring Initializr添加 Milestone 和 Snapshot Repositories依赖管理为特定组件添加依赖项Embeddings ModelsChat ModelsImage Generation ModelsVector Databases 示例工程


关于 Spring AI

github : https://github.com/spring-projects/spring-ai官方文档:https://docs.spring.io/spring-ai/reference/
Spring 中文网 - Spring AI 简介
https://springdoc.cn/spring-ai-intro/

Spring AI 项目旨在简化 包含AI 功能的 应用程序的开发,而不会带来 不必要的复杂性。
该项目的灵感来自著名的Python项目,如LangChain和LlamaIndex,但Spring AI并不是这些项目的直接端口。
Spring AI 相信,下一波Generative AI应用程序将不仅面向Python开发人员,而且将在许多编程语言中无处不在。

Spring AI的核心是 提供抽象,作为开发人工智能应用程序的基础。
这些抽象有多个实现,能够以最小的代码更改实现简单的组件交换。

Spring AI提供以下功能:

支持所有主要的模型,如OpenAI、微软、亚马逊、谷歌和Huggingface。支持的模型类型有聊天和文本到图像,还有更多。跨AI 提供 的 可移植聊天API 和 嵌入模型。同时支持同步和流API选项。还支持下拉访问特定于型号的功能。人工智能模型输出到POJO的映射。支持所有主要的向量数据库提供商,如Azure Vector Search、Chroma、Milvus、Neo4j、PostgreSQL/PGVector、PineCone、Qdrant、Redis和Weaviate跨矢量存储提供商的可移植API,包括一个新的 类似SQL 的元数据过滤器API,它也是可移植的。函数调用用于AI模型和矢量存储的Spring Boot自动配置和启动器。用于数据工程的ETL框架

此功能集允许您实现常见用例,如“文档问答”或“与文档聊天”


使用

本节提供了如何开始使用Spring AI的切入点。

您应该根据自己的需要,按照以下各节中的步骤进行操作。


Spring CLI

Spring CLI 详见:https://docs.spring.io/spring-cli/reference/index.html

Spring CLI 简化了直接从终端创建新应用程序的过程。

与熟悉JavaScript生态系统的用户使用的 create-react-app 命令一样,Spring CLI提供了一个 spring boot new 命令来创建基于Spring的项目。

Spring CLI还提供了将外部代码库集成到当前项目中的功能,以及许多其他功能。

重要的是要理解,“Spring CLI”是一个与“Spring Boot CLI”不同的项目,每个项目都有自己的一组功能。


要开始创建Spring AI应用程序,请执行以下步骤:

1、下载最新的Spring CLIRelease并遵循安装说明.
2、要创建一个简单的基于OpenAI的应用程序,请使用以下命令:

spring boot new --from ai --name myaiCopied!

3、要将相同的简单AI 应用程序添加到现有项目中,请执行:

spring boot add aiCopied!

Spring CLI允许用户定义自己的项目目录,定义可以创建哪些项目或将其添加到现有代码库中。


Spring Initializr

前往start.spring.io并选择要在新应用程序中使用的AI模型和矢量存储。

添加 Milestone 和 Snapshot Repositories

如果您喜欢手动添加依赖项片段,请按照以下部分中的说明进行操作。

要使用Milestone 和 Snapshot版本,您需要在构建文件中添加对 Spring Milestone 和/或Snapshot 存储库的引用。

对于Maven,根据需要添加以下存储库定义:

  <repositories>    <repository>      <id>spring-milestones</id>      <name>Spring Milestones</name>      <url>https://repo.spring.io/milestone</url>      <snapshots>        <enabled>false</enabled>      </snapshots>    </repository>    <repository>      <id>spring-snapshots</id>      <name>Spring Snapshots</name>      <url>https://repo.spring.io/snapshot</url>      <releases>        <enabled>false</enabled>      </releases>    </repository>  </repositories>Copied!

对于 Gradle,添加如下:

repositories {  mavenCentral()  maven { url 'https://repo.spring.io/milestone' }  maven { url 'https://repo.spring.io/snapshot' }}Copied!

依赖管理

Spring AI Bill of Materials (BOM) 声明了给定版本的Spring AI所使用的所有依赖项的推荐版本。

使用应用程序构建脚本中的BOM可以避免您自己指定和维护依赖项版本。

相反,您使用的BOM的版本决定了所使用的依赖关系版本。它还确保默认情况下使用受支持和测试的依赖关系版本,除非您选择覆盖它们。

如果您是Maven用户,您可以通过将以下内容添加到pom.xml文件中来使用BOM-

<dependencyManagement>    <dependencies>        <dependency>            <groupId>org.springframework.ai</groupId>            <artifactId>spring-ai-bom</artifactId>            <version>0.8.1-SNAPSHOT</version>            <type>pom</type>            <scope>import</scope>        </dependency>    </dependencies></dependencyManagement>Copied!

Gradle用户还可以通过利用Gradle(5.0+)本机支持 使用Maven BOM声明依赖关系约束,来使用Spring AI BOM。

这是通过将“平台”依赖关系 处理程序方法,添加到Gradle构建脚本的依赖关系部分来实现的。

如下面的片段所示,然后可以为您希望使用的一个或多个spring-ai模块(例如 spring-ai-openai)声明Starter依赖项的无版本声明。

dependencies {  implementation platform("org.springframework.ai:spring-ai-bom:0.8.1-SNAPSHOT")  // Replace the following with the starter dependencies of specific modules you wish to use  implementation 'org.springframework.ai:spring-ai-openai'}Copied!

为特定组件添加依赖项

文档中的以下每个部分都显示了 需要添加到项目构建系统中的依赖项。

Embeddings Models
Embeddings API Spring AI OpenAI EmbeddingsSpring AI Azure OpenAI EmbeddingsSpring AI Ollama EmbeddingsSpring AI Transformers (ONNX) EmbeddingsSpring AI PostgresML EmbeddingsSpring AI Bedrock Cohere EmbeddingsSpring AI Bedrock Titan EmbeddingsSpring AI VertexAI EmbeddingsSpring AI MistralAI Embeddings
Chat Models
Chat Completion API OpenAI Chat Completion (streaming and function-calling support)Microsoft Azure Open AI Chat Completion (streaming and function-calling support)Ollama Chat CompletionHuggingFace Chat Completion (no streaming support)Google Vertex AI PaLM2 Chat Completion (no streaming support)Google Vertex AI Gemini Chat Completion (streaming, multi-modality & function-calling support)Amazon Bedrock Cohere Chat CompletionLlama2 Chat CompletionTitan Chat CompletionAnthropic Chat Completion MistralAI Chat Completion (streaming and function-calling support)
Image Generation Models
Image Generation API OpenAI Image GenerationStabilityAI Image Generation
Vector Databases
Vector Database API Azure Vector Search - The Azure vector store.ChromaVectorStore - The Chroma vector store.MilvusVectorStore - The Milvus vector store.Neo4jVectorStore - The Neo4j vector store.PgVectorStore - The PostgreSQL/PGVector vector store.PineconeVectorStore - PineCone vector store.QdrantVectorStore - Qdrant vector store.RedisVectorStore - The Redis vector store.WeaviateVectorStore - The Weaviate vector store.SimpleVectorStore - A simple (in-memory) implementation of persistent vector storage, good for educational purposes.

示例工程

You can clone these projects on GitHub to get started.

你可以在GitHub上克隆这些项目 来开始。

OpenAI
github.com/rd-1-2022/ai-openai-helloworldAzure OpenAI github.com/rd-1-2022/ai-azure-openai-helloworldgithub.com/Azure-Samples/spring-ai-azure-workshop

2024-04-23(二)


点击全文阅读


本文链接:http://zhangshiyu.com/post/104160.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1