|
@@ -1,17 +1,30 @@
|
|
|
package com.backendsys.modules.ai.deepSeek.controller;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import com.backendsys.modules.ai.deepSeek.entity.DeepSeekParam;
|
|
|
import com.backendsys.modules.ai.deepSeek.utils.OllamaUtil;
|
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
|
import com.backendsys.modules.common.utils.Result;
|
|
|
+import com.backendsys.modules.sse.entity.SseResponse;
|
|
|
+import com.backendsys.modules.sse.entity.SseResponseEnum;
|
|
|
+import com.backendsys.modules.sse.utils.SseUtil;
|
|
|
+import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
|
|
|
+import io.github.pigmesh.ai.deepseek.core.chat.AssistantMessage;
|
|
|
+import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionChoice;
|
|
|
+import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
@Validated
|
|
|
@RestController
|
|
@@ -21,14 +34,61 @@ public class DeepSeekController {
|
|
|
@Autowired
|
|
|
private OllamaUtil ollamaUtil;
|
|
|
|
|
|
+ @Value("${spring.application.name}")
|
|
|
+ private String APPLICATION_NAME;
|
|
|
+ @Autowired
|
|
|
+ private SseUtil sseUtil;
|
|
|
+ @Autowired
|
|
|
+ private DeepSeekClient deepSeekClient;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * deepseek4j
|
|
|
+ * https://javaai.pig4cloud.com/deepseek/quickstart
|
|
|
+ *
|
|
|
+ * deepseek开放平台
|
|
|
+ * https://platform.deepseek.com/
|
|
|
+ */
|
|
|
+
|
|
|
@Operation(summary = "提问")
|
|
|
@PreAuthorize("@sr.hasPermission('101')")
|
|
|
@PostMapping("/api/deepSeek/ask")
|
|
|
public Result ask(@Validated @RequestBody DeepSeekParam param) {
|
|
|
+
|
|
|
Long userId = SecurityUtil.getUserId();
|
|
|
+ String emitterKey = APPLICATION_NAME + "-userid-" + Convert.toStr(userId);
|
|
|
+
|
|
|
+ Flux<ChatCompletionResponse> flux = deepSeekClient.chatFluxCompletion(param.getQuestion());
|
|
|
+ System.out.println(flux);
|
|
|
+
|
|
|
+// // 创建一个 CompletableFuture 来执行异步任务
|
|
|
+// CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
|
|
+//
|
|
|
+// System.out.println("question: " + param.getQuestion());
|
|
|
+//
|
|
|
+// System.out.println(flux);
|
|
|
+//
|
|
|
+// flux.doOnNext(i -> {
|
|
|
+// System.out.println("i.");
|
|
|
+// List<ChatCompletionChoice> contentList = i.choices();
|
|
|
+// contentList.stream().forEach(content -> {
|
|
|
+// AssistantMessage message = content.message();
|
|
|
+// System.out.println("message: " + message.content());
|
|
|
+//
|
|
|
+// // [SSE] 发送消息
|
|
|
+// String dataStr = (new SseResponse(SseResponseEnum.DEEPSEEK, message.content())).toJsonStr();
|
|
|
+// sseUtil.send(emitterKey, dataStr);
|
|
|
+//
|
|
|
+// });
|
|
|
+// // 其他ELT流程
|
|
|
+// }).doOnError(e -> {
|
|
|
+// System.out.println(e.getMessage());
|
|
|
+// });
|
|
|
+//
|
|
|
+// });
|
|
|
|
|
|
// ollamaUtil.chatDeepSeek("deepseek-r1:1.5b", param.getQuestion(), userId);
|
|
|
- ollamaUtil.chatDeepSeek("deepseek-r1:7b", param.getQuestion(), userId);
|
|
|
+// ollamaUtil.chatDeepSeek("deepseek-r1:7b", param.getQuestion(), userId);
|
|
|
|
|
|
return Result.success();
|
|
|
}
|