DifyController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package cn.cslg.pas.controller.outApi;
  2. import cn.cslg.pas.common.core.base.Constants;
  3. import cn.cslg.pas.common.model.dify.*;
  4. import cn.cslg.pas.common.model.dify.confessionSession.ConfessionSessionDetailDTO;
  5. import cn.cslg.pas.common.model.dify.confessionSession.ConfessionSessionDetailVO;
  6. import cn.cslg.pas.common.model.dify.generatePatentResult.ExportPatentDTO;
  7. import cn.cslg.pas.common.model.dify.generatePatentResult.GeneratePatentResultDTO;
  8. import cn.cslg.pas.common.utils.CacheUtils;
  9. import cn.cslg.pas.common.utils.LoginUtils;
  10. import cn.cslg.pas.common.utils.Response;
  11. import cn.cslg.pas.factorys.difyFactory.GeneratePatentResultService;
  12. import cn.cslg.pas.service.common.DifyService;
  13. import cn.cslg.pas.service.dify.*;
  14. import com.alibaba.fastjson2.JSONObject;
  15. import io.swagger.v3.oas.annotations.Operation;
  16. import io.swagger.v3.oas.annotations.tags.Tag;
  17. import lombok.RequiredArgsConstructor;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.context.annotation.Lazy;
  20. import org.springframework.http.MediaType;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RequestMethod;
  24. import org.springframework.web.bind.annotation.RestController;
  25. import reactor.core.publisher.Flux;
  26. import java.io.IOException;
  27. @SuppressWarnings({"all"})
  28. @Tag(name = "外部人员调用接口")
  29. @RestController
  30. @RequestMapping(Constants.API_XiaoSHI + "/dify")
  31. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  32. public class DifyController {
  33. private final DifyService difyService;
  34. private final DifySessionService difySessionService;
  35. private final GenerateInstructionService generateInstructionService;
  36. private final GenerateDiscoveryResultService generateDiscoveryResultService;
  37. private final ConfessionSessionService confessionSessionService;
  38. @Autowired
  39. private CacheUtils cacheUtils;
  40. @Autowired
  41. private LoginUtils loginUtils;
  42. private final PatentResultService patentResultService;
  43. @RequestMapping(value = "/chatMessage", method = RequestMethod.POST, produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  44. @Operation(summary = "发送对话")
  45. public Flux<String> chatMessage(@RequestBody ChatMessageDTO chatMessageDTO) throws IOException {
  46. return difyService.getOkhttp(chatMessageDTO);
  47. }
  48. @RequestMapping(value = "/queryHistoryMessage", method = RequestMethod.POST)
  49. @Operation(summary = "查询历史会话")
  50. public Response queryHistoryMessage(@RequestBody DifyHistoryMessageDTO difyHistoryMessageDTO) throws IOException {
  51. String jsons = difyService.queryHistoryMessage(difyHistoryMessageDTO);
  52. JSONObject jsonObject = JSONObject.parseObject(jsons);
  53. return Response.success(jsonObject);
  54. }
  55. @RequestMapping(value = "/querySessionId", method = RequestMethod.GET)
  56. @Operation(summary = "查询会话id")
  57. public Response querySessionId(Integer projectId) throws IOException {
  58. String userId = loginUtils.getId().toString();
  59. return Response.success(difySessionService.getSessionId(projectId, userId));
  60. }
  61. @RequestMapping(value = "/stopMessage", method = RequestMethod.GET)
  62. @Operation(summary = "停止会话")
  63. public Response stopMessage(String taskId,Integer type) throws IOException {
  64. return Response.success(difyService.stopMessage(taskId,type));
  65. }
  66. @RequestMapping(value = "/generateInventionPoint", method = RequestMethod.POST)
  67. @Operation(summary = "生成发明点")
  68. public Response generateInventionPoint(@RequestBody ChatMessageDTO chatMessageDTO) throws IOException {
  69. return Response.success(difyService.generateInventionPoint(chatMessageDTO));
  70. }
  71. @RequestMapping(value = "/generateClaimExplain", method = RequestMethod.POST)
  72. @Operation(summary = "生成权利要求解释和有益效果")
  73. public Response generateClaimExplain(@RequestBody GenerateClaimDTO generateClaimDTO) throws Exception {
  74. return Response.success(difyService.generateClaimExplain(generateClaimDTO));
  75. }
  76. @RequestMapping(value = "/sendOADefense", method = RequestMethod.POST, produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  77. @Operation(summary = "OA答辩")
  78. public Flux<String> sendOADefense(@RequestBody OAParamDTO paramDTO) throws IOException {
  79. return difyService.successGetOAHttp1(paramDTO);
  80. }
  81. @RequestMapping(value = "/generateInstruction", method = RequestMethod.POST, produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  82. @Operation(summary = "生成说明书")
  83. public Flux<String> addConfessionSession(@RequestBody GenerateClaimDTO generateClaimDTO) throws Exception {
  84. return generateInstructionService.generateInstruction2(generateClaimDTO);
  85. }
  86. @RequestMapping(value = "/generateDiscoveryResult", method = RequestMethod.POST)
  87. @Operation(summary = "生成技术交底书理解结果")
  88. public Response generateDiscoveryResult(@RequestBody ChatMessageDTO chatMessageDTO) throws Exception {
  89. return Response.success(generateDiscoveryResultService.generateResult(chatMessageDTO));
  90. }
  91. @RequestMapping(value = "/generateDiscoveryResult/detail", method = RequestMethod.POST)
  92. @Operation(summary = "获取技术交底书理解结果详情")
  93. public Response detail(@RequestBody ConfessionSessionDetailDTO confessionSessionDetailDTO) throws IOException {
  94. ConfessionSessionDetailVO confessionSessionDetailVO = confessionSessionService.getConfessionSessionDetail(confessionSessionDetailDTO);
  95. return Response.success(confessionSessionDetailVO);
  96. }
  97. @RequestMapping(value = "/generateDiscoveryResult/dialogue", method = RequestMethod.POST, produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  98. @Operation(summary = "ai对话")
  99. public Flux<String> discoveryResultDialogue(@RequestBody ChatMessageDTO chatMessageDTO) throws Exception {
  100. return difyService.discoveryResultDialogue(chatMessageDTO);
  101. }
  102. @RequestMapping(value = "/generatePatentResult", method = RequestMethod.POST)
  103. @Operation(summary = "生成专利申请文档结果")
  104. public Flux<String> generatePatentResult(@RequestBody ExportPatentDTO exportPatentDTO) throws Exception {
  105. return patentResultService.aiGeneratePatentResult(generatePatentResultDTO);
  106. }
  107. }