15分钟实战:SpringBoot + Vue2快速构建AI对话系统(集成DeepSeek)
一、环境准备(2分钟)
1.1 技术栈清单
- 后端:SpringBoot 2.7 + JDK 11
- 前端:Vue2 + Axios
- AI引擎:DeepSeek API
- 工具:Postman、IDEA、VS Code
-----------------------博主本期好物推荐笔记编辑器(淘宝链接):Typora Markdown 编辑器 -------------------------
1.2 快速初始化
# 创建SpringBoot项目
spring init --dependencies=web,devtools ai-backend
# 创建Vue2项目
vue create ai-frontend --preset default
二、后端开发(6分钟)
2.1 添加API请求工具类
// src/main/java/com/example/util/ApiClient.java
public class ApiClient {
private static final String DEEPSEEK_URL = "https://api.deepseek.com/v1/chat/completions";
public static String getAIResponse(String prompt, String apiKey) throws IOException {
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
String jsonBody = String.format("{\"model\":\"deepseek-r1\",\"messages\":[{\"role\":\"user\",\"content\":\"%s\"}],\"temperature\":0.7}",
prompt.replace(