|
@@ -0,0 +1,45 @@
|
|
|
|
+package com.zhentao.controller.AI;
|
|
|
|
+
|
|
|
|
+import com.mashape.unirest.http.exceptions.UnirestException;
|
|
|
|
+import com.zhentao.controller.dto.DeeseekRequest;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+import com.mashape.unirest.http.HttpResponse;
|
|
|
|
+import com.mashape.unirest.http.Unirest;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+public class Deekseep {
|
|
|
|
+ private final Gson gson = new Gson();
|
|
|
|
+ //智能Ai智能推荐功能
|
|
|
|
+ @RequestMapping("tall")
|
|
|
|
+ public String tallQuestion(String question) throws IOException, UnirestException {
|
|
|
|
+
|
|
|
|
+ Unirest.setTimeouts(0, 0);
|
|
|
|
+//DeeseekRequest: 自己的实体类名称
|
|
|
|
+
|
|
|
|
+ List<DeeseekRequest.Message> messages = new ArrayList<>();
|
|
|
|
+//给deepSeek一个角色
|
|
|
|
+ messages.add(DeeseekRequest.Message.builder().role("system").content("你是一个美食家").build());
|
|
|
|
+
|
|
|
|
+// question:说你自己想说的话
|
|
|
|
+ messages.add(DeeseekRequest.Message.builder().role("user").content(question).build());
|
|
|
|
+
|
|
|
|
+ DeeseekRequest requestBody = DeeseekRequest.builder()
|
|
|
|
+ .model("deepseek-chat")
|
|
|
|
+ .messages(messages)
|
|
|
|
+ .build();
|
|
|
|
+ HttpResponse<String> response = Unirest.post("https://api.deepseek.com/chat/completions")
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
+ .header("Accept", "application/json")
|
|
|
|
+ .header("Authorization", "Bearer "+"sk-df51dab7323441998d41f18494098ddc")
|
|
|
|
+ .body(gson.toJson(requestBody))
|
|
|
|
+ .asString();
|
|
|
|
+ return response.getBody();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|