1、效果截图:



2、代码部分:
application.properties
server.port=8080
deepseek.api.token=sk-d34e929e887b4881813395241df2f745
deepseek.api.url=https://api.deepseek.com/chat/completions
controller部分 请求参数可以缩短,写成实体类形式
package com.example.springbootai.demos.web;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import java.util.*;
/**
* @author caojun
*/
@RestController
public class TestController {
public static final RestTemplate restTemplate = new RestTemplate();
@Value("${deepseek.api.token}")
private String apiToken;
@Value("${deepseek.api.url}")
private String apiUrl;
@PostMapping("/deepSeek")
public String callDeepSeek(@RequestBody String question) {
// 创建消息列表
List
3、依赖
com.alibaba
fastjson
1.2.83
controller可以简化这样的
@PostMapping("/deepSeek")
public String callDeepSeek(@RequestBody String question) {
// 创建消息列表
List