mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-03-13 21:27:19 +08:00
add deep seek tool action
This commit is contained in:
@@ -5,6 +5,7 @@ import com.zl.mjga.component.PositionOperatorTool;
|
||||
import com.zl.mjga.component.UserRolePermissionOperatorTool;
|
||||
import dev.langchain4j.community.model.zhipu.ZhipuAiStreamingChatModel;
|
||||
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
||||
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
|
||||
import dev.langchain4j.service.AiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -28,4 +29,14 @@ public class ToolsInitializer {
|
||||
.tools(userRolePermissionOperatorTool, departmentOperatorTool, positionOperatorTool)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("flywayInitializer")
|
||||
public SystemToolAssistant deepSeekToolAssistant(OpenAiStreamingChatModel deepSeekChatModel) {
|
||||
return AiServices.builder(SystemToolAssistant.class)
|
||||
.streamingChatModel(deepSeekChatModel)
|
||||
.chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
|
||||
.tools(userRolePermissionOperatorTool, departmentOperatorTool, positionOperatorTool)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class AiController {
|
||||
@PostMapping(value = "/action/execute", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public Flux<String> actionExecute(Principal principal, @RequestBody String userMessage) {
|
||||
Sinks.Many<String> sink = Sinks.many().unicast().onBackpressureBuffer();
|
||||
TokenStream chat = aiChatService.actionExecuteWithZhiPu(principal.getName(), userMessage);
|
||||
TokenStream chat = aiChatService.actionPrecedenceExecuteWith(principal.getName(), userMessage);
|
||||
chat.onPartialResponse(
|
||||
(text) -> {
|
||||
log.debug("ai action partialResponse: {}", text);
|
||||
|
||||
@@ -19,6 +19,7 @@ public class AiChatService {
|
||||
private final AiChatAssistant deepSeekChatAssistant;
|
||||
private final AiChatAssistant zhiPuChatAssistant;
|
||||
private final SystemToolAssistant zhiPuToolAssistant;
|
||||
private final SystemToolAssistant deepSeekToolAssistant;
|
||||
private final LlmService llmService;
|
||||
|
||||
public TokenStream chatWithDeepSeek(String sessionIdentifier, String userMessage) {
|
||||
@@ -29,8 +30,13 @@ public class AiChatService {
|
||||
return zhiPuChatAssistant.chat(sessionIdentifier, userMessage);
|
||||
}
|
||||
|
||||
public TokenStream actionExecuteWithZhiPu(String sessionIdentifier, String userMessage) {
|
||||
return zhiPuToolAssistant.ask(sessionIdentifier, userMessage);
|
||||
public TokenStream actionPrecedenceExecuteWith(String sessionIdentifier, String userMessage) {
|
||||
LlmCodeEnum code = getPrecedenceLlmCode();
|
||||
return switch (code) {
|
||||
case ZHI_PU -> zhiPuToolAssistant.ask(sessionIdentifier, userMessage);
|
||||
case DEEP_SEEK -> deepSeekToolAssistant.ask(sessionIdentifier, userMessage);
|
||||
default -> throw new BusinessException(String.format("无效的模型代码 %s", code));
|
||||
};
|
||||
}
|
||||
|
||||
public TokenStream chatPrecedenceLlmWith(String sessionIdentifier, String userMessage) {
|
||||
|
||||
Reference in New Issue
Block a user