parent
0e8acc7aa8
commit
0a00a61fcb
@ -0,0 +1,13 @@
|
||||
package com.supervision.chat.client.dto.chat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ChatResDTO {
|
||||
|
||||
private String answer;
|
||||
|
||||
private List<String> docs;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.supervision.chat.client.dto.chat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class History {
|
||||
|
||||
private String role;
|
||||
|
||||
private String content;
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.supervision.police.controller;
|
||||
|
||||
import com.supervision.common.domain.R;
|
||||
import com.supervision.police.service.ChatService;
|
||||
import com.supervision.police.vo.ChatReqVO;
|
||||
import com.supervision.police.vo.ChatResVO;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "对话接口")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/robot")
|
||||
public class ChatController {
|
||||
|
||||
private final ChatService chatService;
|
||||
|
||||
@PostMapping("/chat")
|
||||
public R<ChatResVO> chat(@RequestBody ChatReqVO chatReqVO) {
|
||||
|
||||
ChatResVO chatResVO = chatService.chat(chatReqVO);
|
||||
return R.ok(chatResVO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.supervision.police.service;
|
||||
|
||||
import com.supervision.police.vo.ChatReqVO;
|
||||
import com.supervision.police.vo.ChatResVO;
|
||||
|
||||
public interface ChatService {
|
||||
ChatResVO chat(ChatReqVO chatReqVO);
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.supervision.police.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.supervision.chat.client.LangChainChatService;
|
||||
import com.supervision.chat.client.dto.chat.ChatReqDTO;
|
||||
import com.supervision.chat.client.dto.chat.ChatResDTO;
|
||||
import com.supervision.police.domain.ModelCase;
|
||||
import com.supervision.police.service.ChatService;
|
||||
import com.supervision.police.service.ModelCaseService;
|
||||
import com.supervision.police.vo.ChatReqVO;
|
||||
import com.supervision.police.vo.ChatResVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ChatServiceImpl implements ChatService {
|
||||
|
||||
private final LangChainChatService langChainChatService;
|
||||
|
||||
|
||||
private final ModelCaseService modelCaseService;
|
||||
|
||||
|
||||
@Override
|
||||
public ChatResVO chat(ChatReqVO chatReqVO) {
|
||||
|
||||
|
||||
Assert.notEmpty(chatReqVO.getQuery(), "query 不能为空");
|
||||
Assert.notEmpty(chatReqVO.getCaseId(), "caseId 不能为空");
|
||||
|
||||
ModelCase modelCase = modelCaseService.getById(chatReqVO.getCaseId());
|
||||
Assert.notNull(modelCase, "案件不存在");
|
||||
|
||||
log.info("chat: caseNo:{},query{}", modelCase.getCaseNo(), chatReqVO.getQuery());
|
||||
|
||||
ChatResDTO chat = langChainChatService.chat(
|
||||
ChatReqDTO.create(chatReqVO.getQuery(), modelCase.getCaseNo(),chatReqVO.getHistory()));
|
||||
|
||||
log.info("chat: caseNo:{},query{},answer:{}", modelCase.getCaseNo(), chatReqVO.getQuery(),chat.getAnswer());
|
||||
|
||||
return new ChatResVO(chat);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.supervision.police.vo;
|
||||
|
||||
import com.supervision.chat.client.dto.chat.History;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ChatReqVO {
|
||||
|
||||
@Schema(description = "案件id")
|
||||
private String caseId;
|
||||
|
||||
@Schema(description = "用户输入的文本")
|
||||
private String query;
|
||||
|
||||
@Schema(description = "历史会话")
|
||||
private List<History> history;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.supervision.police.vo;
|
||||
|
||||
import com.supervision.chat.client.dto.chat.ChatResDTO;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
public class ChatResVO {
|
||||
|
||||
private String answer;
|
||||
|
||||
private List<String> docs;
|
||||
|
||||
|
||||
public ChatResVO() {
|
||||
}
|
||||
|
||||
public ChatResVO(ChatResDTO chatResDTO) {
|
||||
if (Objects.isNull(chatResDTO)){
|
||||
return;
|
||||
}
|
||||
this.answer = chatResDTO.getAnswer();
|
||||
this.docs = chatResDTO.getDocs();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.supervision.police.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class ModelCaseVO {
|
||||
|
||||
@Schema(description = "主键")
|
||||
private String id;
|
||||
|
||||
|
||||
@Schema(description = "案件编号")
|
||||
private String caseNo;
|
||||
|
||||
|
||||
@Schema(description = "案件名称")
|
||||
private String caseName;
|
||||
|
||||
|
||||
@Schema(description = "案件类型")
|
||||
private String caseType;
|
||||
|
||||
@Schema(description = "认定结果")
|
||||
private List<String> identifyResult;
|
||||
|
||||
@Schema(description = "行为人")
|
||||
private String lawActor;
|
||||
|
||||
|
||||
@Schema(description = "当事人")
|
||||
private String lawParty;
|
||||
|
||||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||
private LocalDateTime updateStartTime;
|
||||
|
||||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||
private LocalDateTime updateEndTime;
|
||||
|
||||
}
|
Loading…
Reference in New Issue