当前位置:   article > 正文

原来spring也可以AI_langchain springai

langchain springai

最近大模型是相当的火,尤其是在自然语言处理(NLP)、图像识别、语音识别等领域的应用,那对于工程同学来说应该如何接住这波破天的富贵呢?
在这里插入图片描述

想啥来啥,前段时间LangChain给我们整了一套钢铁战甲,让我们轻松奴架Javis。

LangChain

在这里插入图片描述

LangChain是一个强大的框架,旨在帮助开发人员使用语言模型构建端到端的应用程序。它提供了一套工具、组件和接口,可简化创建由大型语言模型 (LLM) 和聊天模型提供支持的应用程序的过程。

LangChain 可以轻松管理与语言模型的交互,将多个组件链接在一起,并集成额外的资源。但是LangChain是python开发的,对我等java开发来说不太方便。

哎…,spring最近推出了其AI项目,解了java同学的燃眉之急,来,一起看下spring是如何玩转AI的。

Spring AI

Spring AI是一个用于AI工程的应用程序框架。它的目标是将AI领域的Spring生态系统设计原则(如可移植性和模块化设计)应用到AI领域,并推动使用POJO作为应用程序的构建块。

spring-ai提供了对跨AI提供商的Chat、文本到图像和嵌入式模型的可移植API支持。支持同步和流API选项。还支持降级访问特定于模型的功能。

现在正式版本是0.8.1

Chat Models(模型支持)

  • OpenAI
  • Azure Open AI
  • Amazon Bedrock
    • Cohere’s Command
    • AI21 Labs’ Jurassic-2
    • Meta’s LLama 2
    • Amazon’s Titan
  • Google Vertex AI Palm
  • Google Gemini
  • HuggingFace - access thousands of models, including those from Meta such as Llama2
  • Ollama - run AI models on your local machine
  • MistralAI

Text-to-image Models

  • OpenAI with DALL-E
  • StabilityAI

Transcription (audio to text) Models

  • OpenAI
  • Embedding Models(embedding 算法)
  • OpenAI
  • Azure OpenAI
  • Ollama
  • ONNX
  • PostgresML
  • Bedrock Cohere
  • Bedrock Titan
  • Google VertexAI
  • Mistal AI

Vector Databases(向量数据库)

Vector Store API 提供了跨不同提供商的可移植性,具有一种新颖的类似 SQL 的元数据过滤 API,保持可移植性。

  • Azure Vector Search
  • Chroma
  • Milvus
  • Neo4j
  • PostgreSQL/PGVector
  • PineCone
  • Redis
  • Weaviate
  • Qdrant

Maven依赖

 <dependencies>
			<dependency>
				<groupId>org.springframework.ai</groupId>
				<artifactId>spring-ai-bom</artifactId>
				<version>0.8.1</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
</dependencies>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

代码示例

import org.springframework.ai.chat.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class SimpleAiController {

	private final ChatClient chatClient;

	@Autowired
	public SimpleAiController(ChatClient chatClient) {
		this.chatClient = chatClient;
	}

	@GetMapping("/ai/simple")
	public Map<String, String> completion(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
		return Map.of("generation", chatClient.call(message));
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

Very simple

附录

examples-Simple HelloWorld

Spring AI

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/906709
推荐阅读
相关标签
  

闽ICP备14008679号