|
|
@@ -0,0 +1,61 @@
|
|
|
+package com.storlead.knowledge.api;
|
|
|
+
|
|
|
+
|
|
|
+import com.storlead.framework.common.result.Result;
|
|
|
+import com.storlead.knowledge.config.DifyProperties;
|
|
|
+import com.storlead.knowledge.pojo.dto.ChatDTO;
|
|
|
+import com.storlead.knowledge.service.WorkflowsService;
|
|
|
+import com.storlead.knowledge.utils.HttpService;
|
|
|
+import com.storlead.knowledge.utils.JacksonHolder;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/workflows/")
|
|
|
+@Api(tags = "知识库: 流程")
|
|
|
+public class WorkflowsController {
|
|
|
+ @Resource
|
|
|
+ private HttpService httpService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DifyProperties difyProperties;
|
|
|
+ @Resource
|
|
|
+ private WorkflowsService workflowsService;
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("blocking")
|
|
|
+ @ApiOperation("执行流程")
|
|
|
+ // “”
|
|
|
+ public Result<Object> workflowsBlock(@RequestBody ChatDTO chatDTO) {
|
|
|
+ return workflowsService.AiWorkflows(chatDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("streaming")
|
|
|
+ @ApiOperation("执行流程 流式返回")
|
|
|
+ public SseEmitter workflowsStreaming(@RequestBody ChatDTO chatDTO) throws IOException {
|
|
|
+
|
|
|
+ SseEmitter emitter = new SseEmitter(0L); // 0 = 不超时
|
|
|
+
|
|
|
+ String url = difyProperties.getBaseUrl() + "workflows/run";
|
|
|
+
|
|
|
+ String body = JacksonHolder.OBJECT_MAPPER.writeValueAsString(chatDTO);
|
|
|
+ httpService.postStream(
|
|
|
+ url,
|
|
|
+ "Bearer " +chatDTO.getAppId(),
|
|
|
+ body,
|
|
|
+ emitter,
|
|
|
+ null
|
|
|
+ );
|
|
|
+
|
|
|
+ return emitter;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|