当前位置: 首页 > article >正文

SpringAI快速上手

 一、导入依赖

 镜像(导入maven依赖)

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

 依赖(导入maven依赖)

<!-- SpringAI -->
<dependency>
      <groupId>org.springframework.experimental.ai</groupId>
      <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
      <version>0.7.1-SNAPSHOT</version>
</dependency>
​
<!-- 测试依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

二、申请AI免费的 Key

前提:有一个自己的 github账号

Key申请位置:GitCode - 全球开发者的开源社区,开源代码托管平台

一直往下翻,找到申请领取Key,如:

 或者点击链接: 申请领取内测免费API Key

三、配置ai-key与base-url

将 api-key 的位置替换成自己申请的 key

spring:
  ai:
    openai:
      api-key: 	#	替换成自己申请的key
      base-url: https://api.chatanywhere.tech

四、快速上手AI

测试类中通过 AiClient 调用,如:

import org.junit.jupiter.api.Test;
import org.springframework.ai.client.AiClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class SpringaiApplicationTests {

    @Autowired
    private  AiClient aiClient;
    @Test
    void testAiClient() {
		//	问题
        String ask = "庆余年是什么电视剧";
		//	回答
        String answer = aiClient.generate(ask);
		//	输出打印
        System.out.println(answer);
    }
}

显示效果:


http://www.kler.cn/news/350796.html

相关文章:

  • 985研一,转嵌入式好还是后端开发好?
  • JavaEE----多线程(二)
  • Unity3D学习FPS游戏(4)重力模拟和角色跳跃
  • ResNet-RS 乳腺癌识别
  • git入门操作(2)
  • leetCode算法题爬楼梯递归写法
  • Spring Boot为大创项目提供智能报表解决方案
  • 什么是爬虫?
  • Flink时间语义和时间窗口
  • Milvus×Dify半小时轻松构建RAG系统
  • NAT:网络地址转换
  • 基于深度学习的自主学习和任务规划
  • 无人驾驶驶入安吉“绿水青山”
  • 非线性关卡设计
  • php的echo和print输出语句⑥
  • RPA工具选国外的还是国内的?各有什么优缺点?
  • 【MATLAB代码】TDOA定位,求三维下的位置(1主锚点、3副锚点),附代码
  • 200Kg大载重多旋无人机价格高昂技术分析
  • 【PhpSpreadsheet】ThinkPHP5+PhpSpreadsheet实现批量导出数据
  • 智能摆件(墨水屏)
  • Python | Leetcode Python题解之第475题供暖器
  • Linux——综合实用操作
  • 8.扩散模型的未来---GPT及大模型(2)
  • 基于MinIO配置bucket,用于文件下载和浏览
  • 4、.Net 快速开发框架:DncZeus - 开源项目研究文章
  • MyEclipse中讲解Git使用——结合GitLab