Class SpringAIZhipuaiChatService

java.lang.Object
com.bytedesk.ai.springai.service.BaseSpringAIService
com.bytedesk.ai.springai.providers.zhipuai.SpringAIZhipuaiChatService
All Implemented Interfaces:
SpringAIService

@Service @ConditionalOnProperty(prefix="spring.ai.zhipuai.chat", name="enabled", havingValue="true", matchIfMissing=false) public class SpringAIZhipuaiChatService extends BaseSpringAIService
Spring AI ZhiPuAI聊天服务
  • Field Details

    • bytedeskZhipuaiChatModel

      @Autowired @Qualifier("bytedeskZhipuaiChatModel") private org.springframework.ai.zhipuai.ZhiPuAiChatModel bytedeskZhipuaiChatModel
    • bytedeskZhipuaiApi

      @Autowired @Qualifier("bytedeskZhipuaiApi") private org.springframework.ai.zhipuai.api.ZhiPuAiApi bytedeskZhipuaiApi
  • Constructor Details

    • SpringAIZhipuaiChatService

      public SpringAIZhipuaiChatService()
  • Method Details

    • createDynamicOptions

      private org.springframework.ai.zhipuai.ZhiPuAiChatOptions createDynamicOptions(RobotLlm llm)
      根据机器人配置创建动态的ZhiPuAiChatOptions
      Parameters:
      llm - 机器人LLM配置
      Returns:
      根据机器人配置创建的选项
    • createDynamicChatModel

      private org.springframework.ai.zhipuai.ZhiPuAiChatModel createDynamicChatModel(RobotLlm llm)
      根据机器人配置创建动态的ZhiPuAiChatModel
      Parameters:
      llm - 机器人LLM配置
      Returns:
      配置了特定模型的ZhiPuAiChatModel
    • processPromptWebsocket

      protected void processPromptWebsocket(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, String fullPromptContent)
      方式1:异步流式调用(带prompt参数)
      Specified by:
      processPromptWebsocket in class BaseSpringAIService
    • processPromptSync

      protected String processPromptSync(String message, RobotProtobuf robot, String fullPromptContent)
      方式2:同步调用(带prompt参数)
      Specified by:
      processPromptSync in class BaseSpringAIService
    • processPromptSse

      protected void processPromptSse(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String fullPromptContent)
      方式3:SSE方式调用(带prompt参数)
      Specified by:
      processPromptSse in class BaseSpringAIService
    • extractZhipuaiTokenUsage

      private ChatTokenUsage extractZhipuaiTokenUsage(org.springframework.ai.chat.model.ChatResponse response)
      手动提取智谱AI的token使用情况 由于Spring AI ZhiPuAI集成可能无法正确解析token使用情况,我们手动提取
      Parameters:
      response - ChatResponse对象
      Returns:
      TokenUsage对象
    • estimateTokenUsageFromResponse

      private ChatTokenUsage estimateTokenUsageFromResponse(org.springframework.ai.chat.model.ChatResponse response)
      估算token使用量(当无法从API获取实际token信息时使用)
      Parameters:
      response - ChatResponse对象
      Returns:
      估算的TokenUsage对象
    • estimateTokens

      private long estimateTokens(String text)
      估算文本的token数量
      Parameters:
      text - 输入文本
      Returns:
      估算的token数量
    • testTokenExtraction

      public void testTokenExtraction()
      测试token提取功能 用于调试token计数问题
    • isServiceHealthy

      public Boolean isServiceHealthy()