package com.ruoyi.web.llm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.web.llm.service.ILangChainMilvusService;
import org.noear.solon.ai.chat.message.AssistantMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.io.IOException;

/**
 * session对话Controller
 * 
 * @author cmc
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/llm/session")
public class SessionController extends BaseController
{
    @Autowired
    private ILangChainMilvusService langChainMilvusService;

    /**
     * 生成回答
     */
    @GetMapping("/answer")
    public Flux<AssistantMessage> answer(String topicId, String question) {
        return langChainMilvusService.generateAnswer(topicId, question, "http://192.168.28.188:8000/v1/chat/completions");
    }

    /**
     * 调用LLM+RAG（外部文件）生成回答
     */
    @GetMapping("/answerWithDocument")
    public Flux<AssistantMessage> answerWithDocument(String topicId, String chatId, String question) throws IOException
    {
        return langChainMilvusService.generateAnswerWithDocument(topicId, chatId, question, "http://192.168.28.188:8000/v1/chat/completions");
    }

}
