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, SpringAISiliconFlowService, SpringAITencentService, SpringAIVolcengineService, SpringAIZhipuaiService

public abstract class BaseSpringAIService extends Object implements SpringAIService
  • Field Details

  • Constructor Details

  • Method Details

    • sendWebsocketMessage

      public void sendWebsocketMessage(String query, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply)
      Description copied from interface: SpringAIService
      发送websocket消息
      Specified by:
      sendWebsocketMessage in interface SpringAIService
      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 interface SpringAIService
      emitter - SseEmitter
    • executeFulltextSearch

      private void executeFulltextSearch(String query, String kbUid, List<String> searchContentList, List<FaqProtobuf> faqProtobufList)
      执行全文搜索
    • executeVectorSearch

      private void executeVectorSearch(String query, String kbUid, List<String> searchContentList, List<FaqProtobuf> faqProtobufList)
      执行向量搜索
    • processLlmResponse

      private void processLlmResponse(String query, List<String> searchContentList, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter)
    • createAndProcessPrompt

      private void createAndProcessPrompt(String query, String context, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter)
      创建提示词并处理SSE消息的通用方法
      Parameters:
      query - 用户查询
      context - 上下文信息
      robot - 机器人配置
      messageProtobufQuery - 查询消息
      messageProtobufReply - 回复消息
      emitter - SSE发射器
    • processSearchResponse

      private void processSearchResponse(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, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter)
    • generateFaqPairsAsync

      public String generateFaqPairsAsync(String chunk)
      Description copied from interface: SpringAIService
      异步生成FAQ对
      Specified by:
      generateFaqPairsAsync in interface SpringAIService
      Parameters:
      chunk - 文本块
      Returns:
      生成的FAQ对
    • generateFaqPairsSync

      public void generateFaqPairsSync(String chunk)
      Description copied from interface: SpringAIService
      同步生成FAQ对
      Specified by:
      generateFaqPairsSync in interface SpringAIService
      Parameters:
      chunk - 文本块
    • persistMessage

      public void persistMessage(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply)
      Specified by:
      persistMessage in interface SpringAIService
    • buildKbPrompt

      public String buildKbPrompt(String systemPrompt, String query, String history, String context)
    • processPrompt

      protected abstract void processPrompt(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply)
    • processPromptSync

      protected abstract String processPromptSync(String message)
    • 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)
    • generateFaqPairs

      protected abstract String generateFaqPairs(String prompt)
    • sendMessage

      protected void sendMessage(MessageTypeEnum type, String content, MessageProtobuf messageProtobufReply)
      发送消息的通用方法
      Parameters:
      type - 消息类型
      content - 消息内容
      messageProtobufReply - 回复消息对象
    • isEmitterCompleted

      protected boolean isEmitterCompleted(org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter)
      检查SseEmitter是否已完成
      Parameters:
      emitter - SSE发射器
      Returns:
      如果emitter已完成或关闭返回true,否则返回false
    • handleSseError

      protected void handleSseError(Throwable error, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter)
      处理SSE错误的通用方法
      Parameters:
      error - 发生的错误
      messageProtobufQuery - 查询消息
      messageProtobufReply - 回复消息
      emitter - SSE发射器
    • sendStreamStartMessage

      protected void sendStreamStartMessage(MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String initialContent)
      发送流式开始消息
      Parameters:
      messageProtobufReply - 回复消息对象
      emitter - SSE发射器
      initialContent - 初始内容,通常为"正在思考中..."
    • sendStreamMessage

      protected void sendStreamMessage(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String content)
      发送流式内容消息
      Parameters:
      messageProtobufQuery - 查询消息对象
      messageProtobufReply - 回复消息对象
      emitter - SSE发射器
      content - 消息内容
    • sendStreamEndMessage

      protected void sendStreamEndMessage(MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter)
      发送流式结束消息
      Parameters:
      messageProtobufQuery - 查询消息对象
      messageProtobufReply - 回复消息对象
      emitter - SSE发射器
    • createDynamicOptions

      protected <T> T createDynamicOptions(RobotLlm llm, Function<RobotLlm,T> optionBuilder)
      创建动态的聊天选项(通用方法,使用泛型)
      Type Parameters:
      T - 选项类型参数
      Parameters:
      llm - 机器人LLM配置
      optionBuilder - 选项构建器函数接口
      Returns:
      根据机器人配置创建的选项