| | |
| | | import io.modelcontextprotocol.client.McpSyncClient; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.ruoyi.chat.config.ChatConfig; |
| | | import org.ruoyi.chat.enums.ChatModeType; |
| | | import org.ruoyi.chat.listener.SSEEventSourceListener; |
| | | import org.ruoyi.chat.service.chat.IChatService; |
| | | import org.ruoyi.common.chat.entity.chat.ChatCompletion; |
| | |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * @author ageer |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class OpenAIServiceImpl implements IChatService { |
| | | |
| | | @Autowired |
| | | private IChatModelService chatModelService; |
| | | |
| | | private OpenAiStreamClient openAiStreamClient; |
| | | |
| | | |
| | | @Value("${spring.ai.mcp.client.enabled}") |
| | | private Boolean enabled; |
| | |
| | | @Override |
| | | public SseEmitter chat(ChatRequest chatRequest,SseEmitter emitter) { |
| | | ChatModelVo chatModelVo = chatModelService.selectModelByName(chatRequest.getModel()); |
| | | openAiStreamClient = ChatConfig.createOpenAiStreamClient(chatModelVo.getApiHost(), chatModelVo.getApiKey()); |
| | | OpenAiStreamClient openAiStreamClient = ChatConfig.createOpenAiStreamClient(chatModelVo.getApiHost(), chatModelVo.getApiKey()); |
| | | List<Message> messages = chatRequest.getMessages(); |
| | | if (enabled) { |
| | | String toolString = mcpChat(chatRequest.getPrompt()); |
| | |
| | | return this.chatClient.prompt(prompt).call().content(); |
| | | } |
| | | |
| | | @Override |
| | | public String getCategory() { |
| | | return ChatModeType.CHAT.getCode(); |
| | | } |
| | | |
| | | } |