偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Spring Cloud Alibaba AI 入門與實(shí)踐

開發(fā) 前端
當(dāng)前版本的 Spring Cloud Alibaba AI? 主要完成了幾種常見生成式模型的適配,涵蓋對話、文生圖、文生語音等。在未來的版本中將繼續(xù)推進(jìn) VectorStore、Embedding、ETL Pipeline、RAG? 等更多 AI 應(yīng)用開發(fā)場景的建設(shè)。?

一、概述

Spring AI 是 Spring 官方社區(qū)項(xiàng)目,旨在簡化 Java AI 應(yīng)用程序開發(fā),讓 Java 開發(fā)者像使用 Spring 開發(fā)普通應(yīng)用一樣開發(fā) AI 應(yīng)用。

Spring Cloud Alibaba AI 是一個(gè)將 Spring Cloud 微服務(wù)生態(tài)與阿里巴巴 AI 能力無縫集成的框架,幫助開發(fā)者快速構(gòu)建具備 AI 功能的現(xiàn)代化應(yīng)用。本文將介紹 Spring Cloud Alibaba AI 的基本概念、主要特性和功能,并演示如何完成一個(gè) 在線聊天 和 在線畫圖 的 AI 應(yīng)用。

二、主要特性和功能

Spring Cloud Alibaba AI 目前基于 Spring AI 0.8.1 版本 API 完成通義系列大模型的接入。通義接入是基于阿里云 阿里云百煉 服務(wù);而 阿里云百煉 建立在 模型即服務(wù)(MaaS) 的理念基礎(chǔ)之上,圍繞 AI 各領(lǐng)域模型,通過標(biāo)準(zhǔn)化的 API 提供包括模型推理、模型微調(diào)訓(xùn)練在內(nèi)的多種模型服務(wù)。

主要提供以下核心功能:

2.1. 簡單易用的集成

通過 Spring Boot 風(fēng)格的自動(dòng)配置機(jī)制,開發(fā)者只需少量代碼配置,即可快速接入阿里云的 AI 服務(wù)。

2.2. 豐富的 AI 服務(wù)支持

支持以下核心能力:

  • 自然語言處理(NLP):文本分析、智能問答、翻譯。
  • 計(jì)算機(jī)視覺(CV):圖像生成、圖像識別、目標(biāo)檢測。
  • 語音處理:語音識別、語音合成。
  • 數(shù)據(jù)分析與預(yù)測:數(shù)據(jù)建模、趨勢分析。

2.3. 高度擴(kuò)展性

通過配置中心和注冊中心(如 Nacos)實(shí)現(xiàn)動(dòng)態(tài)擴(kuò)展,支持微服務(wù)架構(gòu)的擴(kuò)展需求。 提供接口定義,方便接入第三方 AI 平臺。

三、構(gòu)建 AI 應(yīng)用

Spring Cloud Alibaba AI 對 Java 版本有要求,所以需要提前預(yù)裝好 Java 17 環(huán)境。

3.1. 申請 API-KEY

登錄阿里云,進(jìn)入 阿里云百煉 的頁面:

https://bailian.console.aliyun.com/?apiKey=1#/api-key

創(chuàng)建自己的 API-KEY

圖片圖片

3.2. 添加依賴

在 Spring Boot 項(xiàng)目的 pom.xml 中添加 alibaba-ai 依賴

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-ai</artifactId>
</dependency>

<repositories>
    <repository>
        <id>alimaven</id>
        <url>https://maven.aliyun.com/repository/public</url>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-snapshots</id>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

3.3. 配置 API-KEY

在 application.yml 中配置 Kafka 的相關(guān)屬性,包括服務(wù)器地址、認(rèn)證信息等。

spring:
  cloud:
    ai:
      tongyi:
        connection:
          api-key: sk-xxxxxx
  • api-key 配置在阿里云百煉里申請的api-key

3.4. 創(chuàng)建模型調(diào)用服務(wù)

@Service
@Slf4j
publicclass TongYiSimpleService {
    @Resource
    private TongYiChatModel chatClient;
    @Resource
    private TongYiImagesModel imageClient;

    public String chat(String message) {
        Prompt prompt = new Prompt(new UserMessage(message));
        return chatClient.call(prompt).getResult().getOutput().getContent();
    }

    public String image(String message) {
        ImagePrompt prompt = new ImagePrompt(message);
        Image image = imageClient.call(prompt).getResult().getOutput();
        return image.getB64Json();
    }
}

聊天和圖片的服務(wù),分別通過注入 TongYiChatModel 和 TongYiImagesModel 對象來實(shí)現(xiàn),屏蔽底層通義大模型交互細(xì)節(jié)。

3.5. 創(chuàng)建controller

@RestController
@RequestMapping("/ai")
publicclass TongYiController {
    @Resource
    private TongYiSimpleService tongYiSimpleService;

    @GetMapping("/chat")
    public String chat(@RequestParam(value = "message") String message) {
        return tongYiSimpleService.chat(message);
    }

    @GetMapping("/image")
    public ResponseEntity<byte[]> image(@RequestParam(value = "message") String message) {
        String b64Str = tongYiSimpleService.image(message);
        byte[] imageBytes = Base64.getDecoder().decode(b64Str);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.IMAGE_JPEG);
        returnnew ResponseEntity<>(imageBytes, headers, HttpStatus.OK);
    }
}

3.6. 測試效果

3.6.1. 聊天接口

在瀏覽器輸入:http://localhost:8009/ai/chat?message=你是誰

圖片圖片

3.6.2. 圖片接口

在瀏覽器輸入:http://localhost:8009/ai/image?message=意大利面拌42號混凝土

圖片圖片

3.6.3. 搭配聊天頁面

圖片圖片

四、總結(jié)

當(dāng)前版本的 Spring Cloud Alibaba AI 主要完成了幾種常見生成式模型的適配,涵蓋對話、文生圖、文生語音等。在未來的版本中將繼續(xù)推進(jìn) VectorStore、Embedding、ETL Pipeline、RAG 等更多 AI 應(yīng)用開發(fā)場景的建設(shè)。

責(zé)任編輯:武曉燕 來源: 陶陶技術(shù)筆記
相關(guān)推薦

2022-02-07 07:10:32

服務(wù)注冊功能

2024-09-14 09:21:55

Spring微服務(wù)服務(wù)間調(diào)用

2020-12-08 11:43:03

Spring Clou分布式Seata

2025-05-08 02:10:00

SpringAIAPI

2022-02-14 07:02:04

Spring閾值Nacos

2017-09-05 14:05:11

微服務(wù)spring clou路由

2025-04-14 02:25:00

2025-06-13 18:20:02

Spring AI云原生AI 應(yīng)用

2023-12-19 09:33:40

微服務(wù)監(jiān)控

2025-02-27 08:00:00

熔斷機(jī)制微服務(wù)Spring

2022-02-08 12:15:25

Spring微服務(wù)Spring Clo

2024-05-31 08:12:19

2024-04-16 00:00:00

Spring微服務(wù)架構(gòu)

2025-03-04 08:53:10

2025-05-27 08:05:00

Spring開發(fā)服務(wù)調(diào)用

2022-02-28 07:40:23

Nacos注冊中心客戶端

2017-07-03 08:29:42

Spring Clou服務(wù)詳解

2024-12-24 14:01:10

2024-11-15 16:35:13

2025-04-18 09:45:47

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號