mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-04-08 06:27:36 +00: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 com.zl.mjga.component.UserRolePermissionOperatorTool;
|
||||||
import dev.langchain4j.community.model.zhipu.ZhipuAiStreamingChatModel;
|
import dev.langchain4j.community.model.zhipu.ZhipuAiStreamingChatModel;
|
||||||
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
||||||
|
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
|
||||||
import dev.langchain4j.service.AiServices;
|
import dev.langchain4j.service.AiServices;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -28,4 +29,14 @@ public class ToolsInitializer {
|
|||||||
.tools(userRolePermissionOperatorTool, departmentOperatorTool, positionOperatorTool)
|
.tools(userRolePermissionOperatorTool, departmentOperatorTool, positionOperatorTool)
|
||||||
.build();
|
.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)
|
@PostMapping(value = "/action/execute", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
public Flux<String> actionExecute(Principal principal, @RequestBody String userMessage) {
|
public Flux<String> actionExecute(Principal principal, @RequestBody String userMessage) {
|
||||||
Sinks.Many<String> sink = Sinks.many().unicast().onBackpressureBuffer();
|
Sinks.Many<String> sink = Sinks.many().unicast().onBackpressureBuffer();
|
||||||
TokenStream chat = aiChatService.actionExecuteWithZhiPu(principal.getName(), userMessage);
|
TokenStream chat = aiChatService.actionPrecedenceExecuteWith(principal.getName(), userMessage);
|
||||||
chat.onPartialResponse(
|
chat.onPartialResponse(
|
||||||
(text) -> {
|
(text) -> {
|
||||||
log.debug("ai action partialResponse: {}", text);
|
log.debug("ai action partialResponse: {}", text);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class AiChatService {
|
|||||||
private final AiChatAssistant deepSeekChatAssistant;
|
private final AiChatAssistant deepSeekChatAssistant;
|
||||||
private final AiChatAssistant zhiPuChatAssistant;
|
private final AiChatAssistant zhiPuChatAssistant;
|
||||||
private final SystemToolAssistant zhiPuToolAssistant;
|
private final SystemToolAssistant zhiPuToolAssistant;
|
||||||
|
private final SystemToolAssistant deepSeekToolAssistant;
|
||||||
private final LlmService llmService;
|
private final LlmService llmService;
|
||||||
|
|
||||||
public TokenStream chatWithDeepSeek(String sessionIdentifier, String userMessage) {
|
public TokenStream chatWithDeepSeek(String sessionIdentifier, String userMessage) {
|
||||||
@@ -29,8 +30,13 @@ public class AiChatService {
|
|||||||
return zhiPuChatAssistant.chat(sessionIdentifier, userMessage);
|
return zhiPuChatAssistant.chat(sessionIdentifier, userMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenStream actionExecuteWithZhiPu(String sessionIdentifier, String userMessage) {
|
public TokenStream actionPrecedenceExecuteWith(String sessionIdentifier, String userMessage) {
|
||||||
return zhiPuToolAssistant.ask(sessionIdentifier, 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) {
|
public TokenStream chatPrecedenceLlmWith(String sessionIdentifier, String userMessage) {
|
||||||
|
|||||||
Reference in New Issue
Block a user