1.1 SpringAI 简介
Spring AI 是一个用于构建人工智能应用程序的开源框架,旨在简化 Java 开发者与大语言模型的交互。
1.2 需要环境
- JDK 17 或更高版本(注:springboot 项目)
- Maven 或 Gradle 构建工具
- DeepSeek API Key
1.3 示例 - 对话&流式调用
步骤一:去 deepseek 平台对应大模型平台申请 App Key
申请地址:https://api-docs.deepseek.com/zh-cn/
使用 curl 测试一下 appkey(调用 deepseek 的 api 接口测试一下):
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer sk-xxx" -d '{"model": "deepseek-chat","messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello!"}],"stream":false}' https://api.deepseek.com/chat/completions
注意:余额不足返回:{"error":{"message":"Insufficient Balance","type":"unknown_error","param":null,"code":"invalid_request_error"}}
步骤二:添加 pom
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
</dependencies>

