refactor(module-llm):优化 Prompt 模板使用次数更新逻辑
- 在 ConversationServiceImpl 中,将 PromptTemplatesSaveReqVO 的使用次数更新逻辑改为调用新的 updatePromptTemplatesUseCount 方法 - 在 PromptTemplatesApplicationsMapper 中添加 updatePromptTemplatesUseCount 方法,用于更新 Prompt 模板的使用次数 - 在 PromptTemplatesApplicationsMapper.xml 中添加对应的 SQL 语句,用于更新 Prompt 模板的使用次数- 在 PromptTemplatesService 中添加 updatePromptTemplatesUseCount 方法的接口定义 - 在 PromptTemplatesServiceImpl 中实现
This commit is contained in:
parent
720210d6b9
commit
d454971b8f
@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.prompttemplatesapplications.PromptTemplatesApplicationsDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.llm.controller.admin.prompttemplatesapplications.vo.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* Prompt 模板 应用关系表,记录模板和应用之间的多对多关系 Mapper
|
||||
@ -25,4 +26,6 @@ public interface PromptTemplatesApplicationsMapper extends BaseMapperX<PromptTem
|
||||
.orderByDesc(PromptTemplatesApplicationsDO::getId));
|
||||
}
|
||||
|
||||
|
||||
void updatePromptTemplatesUseCount (@Param("promptId") Integer promptId, @Param("count") Integer count);
|
||||
}
|
||||
|
@ -330,8 +330,8 @@ public class ConversationServiceImpl implements ConversationService {
|
||||
|
||||
Optional.ofNullable(application.getPromptId()).ifPresent(promptId -> {
|
||||
PromptTemplatesRespVO promptTemplates = promptTemplatesService.getPromptTemplates(promptId);
|
||||
promptTemplates.setUseCount(Math.max(1, Optional.ofNullable(promptTemplates.getUseCount()).orElse(0) + 1));
|
||||
promptTemplatesService.updatePromptTemplates(BeanUtil.toBean(promptTemplates, PromptTemplatesSaveReqVO.class));
|
||||
int count = Math.max(1, Optional.ofNullable(promptTemplates.getUseCount()).orElse(0) + 1);
|
||||
promptTemplatesService.updatePromptTemplatesUseCount(Math.toIntExact(promptId),count);
|
||||
});
|
||||
|
||||
log.info("已更新系统提示信息为: {}", chatReqVO.getSystemPrompt());
|
||||
|
@ -15,7 +15,7 @@ public interface PromptTemplatesService {
|
||||
Long createPromptTemplates (@Valid PromptTemplatesSaveReqVO createReqVO);
|
||||
|
||||
void updatePromptTemplates (@Valid PromptTemplatesSaveReqVO updateReqVO);
|
||||
|
||||
void updatePromptTemplatesUseCount (Integer promptId,Integer count);
|
||||
/**
|
||||
* 删除 Prompt模板
|
||||
*
|
||||
|
@ -184,6 +184,12 @@ public class PromptTemplatesServiceImpl implements PromptTemplatesService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePromptTemplatesUseCount (Integer promptId,Integer count) {
|
||||
//
|
||||
this.promptTemplatesApplicationsMapper.updatePromptTemplatesUseCount(promptId,count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 Prompt模板
|
||||
*
|
||||
|
@ -9,4 +9,7 @@
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
<update id="updatePromptTemplatesUseCount">
|
||||
UPDATE llm_prompt_templates t SET t.use_count = #{count} WHERE t.id = #{promptId}
|
||||
</update>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user