Package com.bytedesk.ai.zhipuai
Class ZhipuaiMultiModelService
java.lang.Object
com.bytedesk.ai.service.BaseSpringAIService
com.bytedesk.ai.zhipuai.ZhipuaiMultiModelService
- All Implemented Interfaces:
SpringAIService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate ai.z.openapi.ZhipuAiClientprivate LlmProviderRestServiceprivate TokenUsageHelperprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final StringFields inherited from class com.bytedesk.ai.service.BaseSpringAIService
applicationEventPublisher, chunkElasticService, chunkVectorService, faqElasticService, faqVectorService, knowledgeBaseSearchHelper, messagePersistCache, messagePersistenceHelper, messageRestService, messageSendService, promptHelper, robotMessageCache, robotRestService, sseMessageHelper, textElasticService, textVectorService, threadRestService, uidUtils, webpageElasticService, webpageVectorService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate List<ai.z.openapi.service.model.MessageContent>buildUserContents(String text) private List<ai.z.openapi.service.model.MessageContent>buildUserContentsFromMessage(MessageProtobuf messageProtobufQuery) private List<ai.z.openapi.service.model.ChatMessage>buildZaiMessagesFromPrompt(org.springframework.ai.chat.prompt.Prompt prompt) private ai.z.openapi.ZhipuAiClient根据机器人配置动态创建 ZhipuAiClient,优先使用 provider apiKey,失败则回退默认 Bean。private longestimateTokens(String text) private StringextractDeltaText(ai.z.openapi.service.model.Delta delta) private StringextractFinalTextFromResponse(ai.z.openapi.service.model.ChatCompletionResponse response) private StringgetModel(RobotProtobuf robot) processMultiModalSyncRequest(MessageProtobuf messageProtobuf, RobotProtobuf robot, boolean searchKnowledgeBase) 多模态同步请求处理,支持图片等媒体类型protected voidprocessPromptSse(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, List<RobotContent.SourceReference> sourceReferences, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) protected StringprocessPromptSync(String message, RobotProtobuf robot) protected voidprocessPromptWebsocket(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) private StringstripThinkTags(String text) Methods inherited from class com.bytedesk.ai.service.BaseSpringAIService
processSyncRequest, sendSseMessage, sendSyncMessage, sendWebsocketMessage
-
Field Details
-
llmProviderRestService
-
defaultClient
@Autowired(required=false) @Qualifier("zhipuAiClient") private ai.z.openapi.ZhipuAiClient defaultClient -
tokenUsageHelper
-
DEFAULT_MULTI_MODEL
- See Also:
-
ZAI_ROLE_SYSTEM
- See Also:
-
ZAI_THINKING_ENABLED
- See Also:
-
ZAI_THINKING_DISABLED
- See Also:
-
ZAI_TEXT
- See Also:
-
ZAI_IMAGE_URL
- See Also:
-
ZAI_VIDEO_URL
- See Also:
-
ZAI_FILE_URL
- See Also:
-
-
Constructor Details
-
ZhipuaiMultiModelService
public ZhipuaiMultiModelService()
-
-
Method Details
-
getModel
-
createDynamicClient
根据机器人配置动态创建 ZhipuAiClient,优先使用 provider apiKey,失败则回退默认 Bean。 -
buildZaiMessagesFromPrompt
private List<ai.z.openapi.service.model.ChatMessage> buildZaiMessagesFromPrompt(org.springframework.ai.chat.prompt.Prompt prompt) -
buildUserContentsFromMessage
private List<ai.z.openapi.service.model.MessageContent> buildUserContentsFromMessage(MessageProtobuf messageProtobufQuery) -
buildUserContents
-
extractFinalTextFromResponse
private String extractFinalTextFromResponse(ai.z.openapi.service.model.ChatCompletionResponse response) -
extractDeltaText
-
stripThinkTags
-
estimateTokens
-
processPromptWebsocket
protected void processPromptWebsocket(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply) - Specified by:
processPromptWebsocketin classBaseSpringAIService
-
processPromptSync
- Specified by:
processPromptSyncin classBaseSpringAIService
-
processMultiModalSyncRequest
public String processMultiModalSyncRequest(MessageProtobuf messageProtobuf, RobotProtobuf robot, boolean searchKnowledgeBase) 多模态同步请求处理,支持图片等媒体类型 -
processPromptSse
protected void processPromptSse(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, List<RobotContent.SourceReference> sourceReferences, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) - Specified by:
processPromptSsein classBaseSpringAIService
-