| | |
| | | import cc.mrbird.febs.ai.service.AiService; |
| | | import cc.mrbird.febs.ai.utils.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | productLinkQuery.last("limit 1"); |
| | | AiProductRoleLink aiProductRoleLink = aiProductRoleLinkService.getByQuery(productLinkQuery); |
| | | if(ObjectUtil.isNull(aiProductRoleLink)){ |
| | | throw new RuntimeException("产品AI陪练不存在"); |
| | | throw new FebsException("产品AI陪练不存在"); |
| | | } |
| | | |
| | | Date nowTime = new Date(); |
| | |
| | | aiMemberTalk = this.add(memberUuid,productId,nowTime); |
| | | } |
| | | |
| | | AiResponse aiResponse = aiService.start(aiProductRoleLink.getProductRoleId(),"开始出题"); |
| | | AiResponse aiResponse = aiService.start(aiProductRoleLink.getProductRoleId(),"<strong>\"生成题目\"</strong>"); |
| | | if(aiResponse.getCode().equals("200")){ |
| | | aiMemberTalkItemService.add(memberUuid,aiMemberTalk.getId(),1,aiResponse.getResContext(),nowTime); |
| | | this.updateTimeUpdate(nowTime,aiMemberTalk.getId()); |
| | | }else{ |
| | | throw new RuntimeException(aiResponse.getDescription()); |
| | | throw new FebsException(aiResponse.getDescription()); |
| | | } |
| | | ApiMemberTalkVo apiMemberTalkVo = new ApiMemberTalkVo(); |
| | | apiMemberTalkVo.setMemberTalkId(aiMemberTalk.getId()); |
| | | apiMemberTalkVo.setType(1); |
| | | apiMemberTalkVo.setContext(aiResponse.getResContext()); |
| | | apiMemberTalkVo.setReport(aiResponse.getReport()); |
| | | |
| | | return new FebsResponse().success().data(apiMemberTalkVo); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public static final String ANSWER_FORMAT = "{}/n回答:{}/n请根据回答给出以下四个方面的总结,这个四个方面分别是亮点、建议、参考答案和核心知识点回顾。重点:四个方面的总结都是必须要有内容。"; |
| | | public static final String ANSWER_FORMAT = "{}/n[回答]{}/n"; |
| | | @Override |
| | | public FebsResponse answer(ApiMemberTalkAnswerDto dto) { |
| | | String memberUuid = LoginUserUtil.getLoginUser().getMemberUuid(); |
| | | String memberTalkId = dto.getId(); |
| | | AiMemberTalk aiMemberTalk = this.getById(memberTalkId); |
| | | if (ObjectUtil.isNull(aiMemberTalk)){ |
| | | throw new RuntimeException("产品AI陪练对话不存在"); |
| | | throw new FebsException("产品AI陪练对话不存在"); |
| | | } |
| | | |
| | | LambdaQueryWrapper<AiProductRoleLink> productLinkQuery = Wrappers.lambdaQuery(AiProductRoleLink.class); |
| | |
| | | productLinkQuery.last("limit 1"); |
| | | AiProductRoleLink aiProductRoleLink = aiProductRoleLinkService.getByQuery(productLinkQuery); |
| | | if(ObjectUtil.isNull(aiProductRoleLink)){ |
| | | throw new RuntimeException("产品AI陪练不存在"); |
| | | throw new FebsException("产品AI陪练不存在"); |
| | | } |
| | | |
| | | String reqContext = dto.getReqContext(); |
| | |
| | | String format = StrUtil.format(ANSWER_FORMAT, aiMemberTalkItem.getContext(), reqContext); |
| | | log.info("format:{}",format); |
| | | AiResponse aiResponse = aiService.start(aiProductRoleLink.getProductRoleId(), format); |
| | | // AiResponse aiResponse = aiService.start(aiProductRoleLink.getProductRoleId(), reqContext); |
| | | if(aiResponse.getCode().equals("200")){ |
| | | Date nowTime = new Date(); |
| | | aiMemberTalkItemService.add(memberUuid,aiMemberTalk.getId(),3,aiResponse.getResContext(),nowTime); |
| | | this.updateTimeUpdate(nowTime,aiMemberTalk.getId()); |
| | | }else{ |
| | | throw new RuntimeException(aiResponse.getDescription()); |
| | | throw new FebsException(aiResponse.getDescription()); |
| | | } |
| | | ApiMemberTalkVo apiMemberTalkVo = new ApiMemberTalkVo(); |
| | | apiMemberTalkVo.setMemberTalkId(aiMemberTalk.getId()); |
| | | apiMemberTalkVo.setType(1); |
| | | apiMemberTalkVo.setType(3); |
| | | apiMemberTalkVo.setContext(aiResponse.getResContext()); |
| | | |
| | | apiMemberTalkVo.setReport(aiResponse.getReport()); |
| | | return new FebsResponse().success().data(apiMemberTalkVo); |
| | | } |
| | | |
| | | @Override |
| | | public AiMemberTalk add(String memberUuid, String productId, Date nowTime) { |
| | | AiMemberTalk aiMemberTalk = new AiMemberTalk(); |