Package com.bytedesk.ai.springai.service
Class BaseSpringAIService
java.lang.Object
com.bytedesk.ai.springai.service.BaseSpringAIService
- All Implemented Interfaces:
SpringAIService
- Direct Known Subclasses:
SpringAIBaiduService
,SpringAICustomService
,SpringAIDashscopeService
,SpringAIDeepseekService
,SpringAIGiteeService
,SpringAIOllamaService
,SpringAIOpenaiService
,SpringAIOpenrouterService
,SpringAISiliconFlowService
,SpringAITencentService
,SpringAIVolcengineService
,SpringAIZhipuaiService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChunkElasticService
protected ChunkVectorService
protected FaqElasticService
protected FaqVectorService
protected MessagePersistCache
protected MessageRestService
protected IMessageSendService
protected RobotMessageCache
protected RobotRestService
protected TextElasticService
protected TextVectorService
protected ThreadRestService
protected UidUtils
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
BaseSpringAIService
(SpringAIVectorStoreService springAIVectorService, IMessageSendService messageSendService) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
createAndProcessPrompt
(String query, String context, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) private String
createAndProcessPromptSync
(String query, String context, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) protected <T> T
createDynamicOptions
(RobotLlm llm, Function<RobotLlm, T> optionBuilder) private void
executeFulltextSearch
(String query, String kbUid, List<FaqProtobuf> searchResultList) private void
executeVectorSearch
(String query, String kbUid, List<FaqProtobuf> searchResultList) protected String
extractTextFromResponse
(Object response) protected void
handleSseError
(Throwable error, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) protected boolean
isEmitterCompleted
(org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) void
persistMessage
(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, Boolean isUnanswered) 消息持久化 用于保存用户查询和机器人回复的消息记录private void
processAnswerMessage
(String answer, MessageTypeEnum type, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, Boolean isUnanswered, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) processDirectLlmRequest
(String query, RobotProtobuf robot) 直接处理LLM请求并同步返回结果 主要用于RobotAgentService中的processLlmRequest方法private void
processDirectResponse
(String query, List<FaqProtobuf> searchContentList, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) private void
processLlmResponse
(String query, List<FaqProtobuf> searchResultList, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) protected void
processLlmResponseWebsocket
(String query, List<FaqProtobuf> searchResultList, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) protected abstract void
processPromptSse
(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) protected abstract String
processPromptSync
(String message, RobotProtobuf robot) protected abstract void
processPromptWebsocket
(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) protected List<FaqProtobuf>
searchKnowledgeBase
(String query, RobotProtobuf robot) protected void
sendMessageWebsocket
(MessageTypeEnum type, String content, MessageProtobuf messageProtobufReply) void
sendSseMessage
(String query, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) 发送Sse消息protected void
sendStreamEndMessage
(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) protected void
sendStreamMessage
(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String content) protected void
sendStreamStartMessage
(MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String initialContent) sendSyncMessage
(String query, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) 发送同步消息并返回回复内容void
sendWebsocketMessage
(String query, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) 发送websocket消息
-
Field Details
-
faqElasticService
-
faqVectorService
-
textElasticService
-
textVectorService
-
chunkElasticService
-
chunkVectorService
-
messageSendService
-
uidUtils
-
robotRestService
-
threadRestService
-
messagePersistCache
-
robotMessageCache
-
messageRestService
-
-
Constructor Details
-
BaseSpringAIService
protected BaseSpringAIService() -
BaseSpringAIService
protected BaseSpringAIService(SpringAIVectorStoreService springAIVectorService, IMessageSendService messageSendService)
-
-
Method Details
-
sendWebsocketMessage
public void sendWebsocketMessage(String query, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) Description copied from interface:SpringAIService
发送websocket消息- Specified by:
sendWebsocketMessage
in interfaceSpringAIService
- Parameters:
query
- 用户查询robot
- 机器人实体
-
sendSseMessage
public void sendSseMessage(String query, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) Description copied from interface:SpringAIService
发送Sse消息- Specified by:
sendSseMessage
in interfaceSpringAIService
emitter
- SseEmitter
-
sendSyncMessage
public String sendSyncMessage(String query, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) Description copied from interface:SpringAIService
发送同步消息并返回回复内容- Specified by:
sendSyncMessage
in interfaceSpringAIService
- Parameters:
query
- 用户查询robot
- 机器人实体messageProtobufQuery
- 查询消息messageProtobufReply
- 回复消息- Returns:
- 回复内容
-
persistMessage
public void persistMessage(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, Boolean isUnanswered) Description copied from interface:SpringAIService
消息持久化 用于保存用户查询和机器人回复的消息记录- Specified by:
persistMessage
in interfaceSpringAIService
-
processDirectLlmRequest
Description copied from interface:SpringAIService
直接处理LLM请求并同步返回结果 主要用于RobotAgentService中的processLlmRequest方法- Specified by:
processDirectLlmRequest
in interfaceSpringAIService
- Parameters:
query
- 用户查询robot
- 机器人配置- Returns:
- 大模型生成的回复内容
-
searchKnowledgeBase
-
executeFulltextSearch
-
executeVectorSearch
-
processLlmResponse
private void processLlmResponse(String query, List<FaqProtobuf> searchResultList, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) -
processLlmResponseWebsocket
protected void processLlmResponseWebsocket(String query, List<FaqProtobuf> searchResultList, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) -
createAndProcessPrompt
private void createAndProcessPrompt(String query, String context, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) -
createAndProcessPromptSync
private String createAndProcessPromptSync(String query, String context, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) -
processDirectResponse
private void processDirectResponse(String query, List<FaqProtobuf> searchContentList, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) -
processAnswerMessage
private void processAnswerMessage(String answer, MessageTypeEnum type, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, Boolean isUnanswered, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) -
sendMessageWebsocket
protected void sendMessageWebsocket(MessageTypeEnum type, String content, MessageProtobuf messageProtobufReply) -
handleSseError
protected void handleSseError(Throwable error, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) -
sendStreamStartMessage
protected void sendStreamStartMessage(MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String initialContent) -
sendStreamMessage
protected void sendStreamMessage(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String content) -
sendStreamEndMessage
protected void sendStreamEndMessage(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) -
extractTextFromResponse
-
isEmitterCompleted
protected boolean isEmitterCompleted(org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) -
createDynamicOptions
-
processPromptWebsocket
protected abstract void processPromptWebsocket(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) -
processPromptSync
-
processPromptSse
protected abstract void processPromptSse(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter)
-