Commit 34e0449c authored by R10's avatar R10

智写-文书写作模板-ai对话

parent c6b38d89
...@@ -98,6 +98,9 @@ public class BizAiDialoguesServiceImpl extends BaseServiceImpl ...@@ -98,6 +98,9 @@ public class BizAiDialoguesServiceImpl extends BaseServiceImpl
if (entity.getTitle() != null) { if (entity.getTitle() != null) {
model.setTitle(entity.getTitle()); model.setTitle(entity.getTitle());
} }
if (entity.getDialoguesType() != null) {
model.setDialoguesType(entity.getDialoguesType());
}
if (entity.getMemberId() != null) { if (entity.getMemberId() != null) {
model.setMemberId(entity.getMemberId()); model.setMemberId(entity.getMemberId());
} }
......
...@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
* @author alex.yao * @author alex.yao
* @date 2025/7/28 * @date 2025/7/28
*/ */
@Permission(Access.Anonymous) @Permission(Access.Safety)
public interface LegalRest extends BaseRest { public interface LegalRest extends BaseRest {
/** /**
...@@ -26,7 +26,7 @@ public interface LegalRest extends BaseRest { ...@@ -26,7 +26,7 @@ public interface LegalRest extends BaseRest {
/** /**
* ai对话 * ai对话
*/ */
void AIWritingCall(@RequestBody AiLawDialoguesDto dto) throws Exception; void aiWritingCall(@RequestBody AiLawDialoguesDto dto) throws Exception;
/** /**
* templateAi对话 * templateAi对话
......
...@@ -48,7 +48,7 @@ public class LegalRestImpl implements LegalRest { ...@@ -48,7 +48,7 @@ public class LegalRestImpl implements LegalRest {
private AiLawService aiLawService; private AiLawService aiLawService;
@Override @Override
public void AIWritingCall(AiLawDialoguesDto dto) throws Exception { public void aiWritingCall(AiLawDialoguesDto dto) throws Exception {
cn.hutool.core.lang.Assert.notNull(dto.getDialoguesId(), "对话id不能为空"); cn.hutool.core.lang.Assert.notNull(dto.getDialoguesId(), "对话id不能为空");
cn.hutool.core.lang.Assert.notNull(dto.getInput(), "问题不能为空"); cn.hutool.core.lang.Assert.notNull(dto.getInput(), "问题不能为空");
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException(); UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
......
...@@ -36,6 +36,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.function.AbstractFunctionResult; ...@@ -36,6 +36,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.function.AbstractFunctionResult;
import cn.com.poc.thirdparty.resource.demand.ai.function.web_seach.WebSearchFunction; import cn.com.poc.thirdparty.resource.demand.ai.function.web_seach.WebSearchFunction;
import cn.com.poc.thirdparty.resource.demand.ai.function.web_seach.WebSearchFunctionResult; import cn.com.poc.thirdparty.resource.demand.ai.function.web_seach.WebSearchFunctionResult;
import cn.com.poc.thirdparty.service.LLMService; import cn.com.poc.thirdparty.service.LLMService;
import cn.com.poc.writing.dto.AiWritingTitleGenerationDto;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.frame.service.FmxParamConfigService; import cn.com.yict.framemax.frame.service.FmxParamConfigService;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
...@@ -168,6 +169,13 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -168,6 +169,13 @@ public class AiLawServiceImpl implements AiLawService {
} }
} }
//作文标题生成
AiWritingTitleGenerationDto aiWritingTitleGenerationDto = titleGeneration(input);
Boolean needWriting = aiWritingTitleGenerationDto.getNeedWriting();
if (needWriting && StringUtils.isNotBlank(aiWritingTitleGenerationDto.getTitle())) {
sseUtil.send(JsonUtils.serialize(aiWritingTitleGenerationDto));
}
//组装请求参数 //组装请求参数
List<Message> messages = buildMessages(dialoguesId, userId, input, fileUrl, null, toolFunction); List<Message> messages = buildMessages(dialoguesId, userId, input, fileUrl, null, toolFunction);
LargeModelResponse largeModelResponse = new LargeModelResponse(); LargeModelResponse largeModelResponse = new LargeModelResponse();
...@@ -577,4 +585,54 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -577,4 +585,54 @@ public class AiLawServiceImpl implements AiLawService {
} }
} }
public AiWritingTitleGenerationDto titleGeneration(String input) {
String system = "## 角色\n" +
"你的任务需要帮我判断用户是否需要进行【写作】\n" +
"\n" +
"## 输出\n" +
"1.包含字段有 needWriting:bool 判断是否需要写作 true-需要 false-不需要 。 title-写作标题,如果需要则生成文章的标题\n" +
"2.仅使用文本方式输出内容。\n" +
"\n" +
"## 输出案例\n" +
"{”needWriting“:true,\"title\":\"论人工智能发展对生产力的影响\"}";
// 配置message
List<Message> messages = new ArrayList<>();
Message systemMessage = new Message();
systemMessage.setContent(system);
systemMessage.setRole(LLMRoleEnum.SYSTEM.getRole());
messages.add(systemMessage);
Message userMessage = new Message();
userMessage.setContent(input);
userMessage.setRole(LLMRoleEnum.USER.getRole());
messages.add(userMessage);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setTopP(0.7F);
largeModelResponse.setTemperature(0.5F);
largeModelResponse.setStream(false);
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
if (largeModelDemandResult == null || StringUtils.isBlank(largeModelDemandResult.getMessage())) {
throw new BusinessException("调用大模型失败");
}
String message = largeModelDemandResult.getMessage();
int startEnd = message.indexOf("{");
int endIndex = message.lastIndexOf("}");
if (startEnd == -1 || endIndex == -1) {
logger.error("解析内容失败, message:{}", message);
throw new BusinessException("解析内容失败");
}
String substring = message.substring(startEnd, endIndex + 1);
AiWritingTitleGenerationDto aiWritingTitleGenerationDto = JsonUtils.deSerialize(substring, AiWritingTitleGenerationDto.class);
if (aiWritingTitleGenerationDto == null) {
aiWritingTitleGenerationDto.setNeedWriting(false);
aiWritingTitleGenerationDto.setTitle(StringUtils.EMPTY);
}
return aiWritingTitleGenerationDto;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment