Class SpringAIN8nService
java.lang.Object
com.bytedesk.ai.springai.service.BaseSpringAIService
com.bytedesk.ai.springai.providers.n8n.SpringAIN8nService
- All Implemented Interfaces:
SpringAIService
@Service
@ConditionalOnProperty(name="bytedesk.n8n.enabled",
havingValue="true",
matchIfMissing=false)
public class SpringAIN8nService
extends BaseSpringAIService
SpringAI N8N Service - 基于 N8N API 的SpringAI服务实现
继承BaseSpringAIService,提供统一的AI服务接口
-
Nested Class Summary
Nested classes/interfaces inherited from class com.bytedesk.ai.springai.service.BaseSpringAIService
BaseSpringAIService.PromptResult -
Field Summary
FieldsFields inherited from class com.bytedesk.ai.springai.service.BaseSpringAIService
applicationEventPublisher, chunkElasticService, chunkVectorService, faqElasticService, faqVectorService, messagePersistCache, messageRestService, messageSendService, robotMessageCache, robotRestService, textElasticService, textVectorService, threadRestService, uidUtils -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringgetChatId(RobotProtobuf robot, MessageProtobuf messageProtobuf) 获取聊天ID 可以从robot配置中获取,或者使用默认值protected voidprocessPromptSse(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter, String fullPromptContent) protected StringprocessPromptSync(String message, RobotProtobuf robot, String fullPromptContent) protected voidprocessPromptWebsocket(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, String fullPromptContent) Token usage data classprivate voidrecordTokenUsage(RobotProtobuf robot, String response, int inputLength, int outputLength) 记录token使用情况Methods inherited from class com.bytedesk.ai.springai.service.BaseSpringAIService
createDynamicOptions, extractFullPromptContent, extractTextFromResponse, extractTokenUsage, getTokenUnitPrice, handleSseError, isEmitterCompleted, persistMessage, persistMessage, persistMessage, persistMessage, processDirectLlmRequest, processLlmResponseWebsocket, publishAiTokenUsageEvent, recordAiTokenUsage, searchKnowledgeBase, sendMessageWebsocket, sendSseMessage, sendStreamEndMessage, sendStreamMessage, sendStreamStartMessage, sendSyncMessage, sendWebsocketMessage
-
Field Details
-
n8nChatService
-
-
Constructor Details
-
SpringAIN8nService
public SpringAIN8nService()
-
-
Method Details
-
processPromptWebsocket
protected void processPromptWebsocket(org.springframework.ai.chat.prompt.Prompt prompt, RobotProtobuf robot, MessageProtobuf messageProtobufQuery, MessageProtobuf messageProtobufReply, String fullPromptContent) Description copied from class:BaseSpringAIServiceToken usage data class- Specified by:
processPromptWebsocketin classBaseSpringAIService
-
processPromptSync
- Specified by:
processPromptSyncin classBaseSpringAIService
-
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) - Specified by:
processPromptSsein classBaseSpringAIService
-
getChatId
获取聊天ID 可以从robot配置中获取,或者使用默认值- Parameters:
robot- 机器人信息messageProtobuf- 消息信息- Returns:
- 聊天ID
-
recordTokenUsage
private void recordTokenUsage(RobotProtobuf robot, String response, int inputLength, int outputLength) 记录token使用情况- Parameters:
robot- 机器人信息response- API响应inputLength- 输入长度outputLength- 输出长度
-