Class SpringAIFastGptService
java.lang.Object
com.bytedesk.ai.service.BaseSpringAIService
com.bytedesk.ai.springai.providers.fastgpt.SpringAIFastGptService
- All Implemented Interfaces:
SpringAIService
SpringAI FastGPT Service - 基于 FastGPT API 的SpringAI服务实现
继承BaseSpringAIService,提供统一的AI服务接口
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LlmProviderRestServiceprivate com.fasterxml.jackson.databind.ObjectMapperprivate org.springframework.web.client.RestTemplateprivate TokenUsageHelperFields 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 StringextractMessageContent(String response) 从响应中提取消息内容extractUsage(String response) 解析响应中的使用情况private StringgetChatId(RobotProtobuf robot, MessageProtobuf messageProtobuf) 获取聊天ID 可以从robot配置中获取,或者使用默认值private String[]根据机器人配置获取动态的FastGPT配置信息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 voidrecordTokenUsage(RobotProtobuf robot, String response, int inputLength, int outputLength) 记录token使用情况private String直接调用FastGPT API发送聊天消息private StringsendMessageWithDynamicConfig(String chatId, String content, Boolean stream, RobotLlm llm) 使用动态配置发送聊天消息Methods inherited from class com.bytedesk.ai.service.BaseSpringAIService
processSyncRequest, sendSseMessage, sendSyncMessage, sendWebsocketMessage
-
Field Details
-
tokenUsageHelper
-
llmProviderRestService
-
restTemplate
@Autowired private org.springframework.web.client.RestTemplate restTemplate -
objectMapper
@Autowired private com.fasterxml.jackson.databind.ObjectMapper objectMapper
-
-
Constructor Details
-
SpringAIFastGptService
public SpringAIFastGptService()
-
-
Method Details
-
getDynamicFastGptConfig
根据机器人配置获取动态的FastGPT配置信息- Parameters:
llm- 机器人LLM配置- Returns:
- 包含API配置的数组 [baseUrl, apiKey],如果获取失败返回null
-
sendMessageWithDynamicConfig
private String sendMessageWithDynamicConfig(String chatId, String content, Boolean stream, RobotLlm llm) 使用动态配置发送聊天消息- Parameters:
chatId- 聊天IDcontent- 消息内容stream- 是否流式响应llm- 机器人LLM配置(用于获取动态配置)- Returns:
- API响应
-
sendMessageDirect
private String sendMessageDirect(String baseUrl, String apiKey, String chatId, String content, Boolean stream) 直接调用FastGPT API发送聊天消息 -
extractMessageContent
从响应中提取消息内容 -
extractUsage
解析响应中的使用情况 -
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
-
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
-
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- 输出长度
-