Springboot 集成spring-ai-alibaba-starter
1.获取api-key
https://bailian.console.aliyun.com/#/home
个人主页获取
2.依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<relativePath/>
</parent>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-starter</artifactId>
<version>1.0.0-M3.1</version>
</dependency>
<!--spring boot and web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.配置文件
spring:
ai:
dashscope:
api-key: 123456
4.测试接口
@RestController
@RequestMapping("/helloworld")
public class HelloworldController {
private final ChatClient chatClient;
public HelloworldController(ChatClient.Builder builder) {
this.chatClient = builder
.build();
}
@GetMapping(value = "/simple/chat", consumes = "text/plain")
public String simpleChat(@RequestBody String query) {
return this.chatClient.prompt()
.user(query)
.call()
.content();
}
}
5.ssl证书
chorme浏览器打开https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
点击url前面的锁 -> 证书 -> 详细信息 -> 导出到文件 name.cer
jdk的bin目录下
keytool -importcert -file C:\Users\liu.wenxuan1\Desktop\lwx.cer -alias dashscope -keystore
"C:\Program Files\Java\jdk-1.8\lib\security\cacerts" -storepass changeit
密码changeit
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律