package com.mortals.xhx.webflux.controller;


import com.mortals.xhx.webflux.common.Result;
import com.mortals.xhx.webflux.dto.ChatBaseParam;
import com.mortals.xhx.webflux.dto.CreateSessionParam;
import com.mortals.xhx.webflux.dto.SessionBaseParam;
import com.mortals.xhx.webflux.dto.SessionVO;
import com.mortals.xhx.webflux.req.RobotTransReq;
import com.mortals.xhx.webflux.service.IChatMsgService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;

@RestController
@RequestMapping("/chat")
public class ChatMsgController {

    @Resource
    private IChatMsgService chatMsgService;

    /**
     * 创建会话
     */
    @PostMapping("/create_session")
    public Result<SessionVO> createSession( @RequestBody CreateSessionParam param) {
        return Result.ok(chatMsgService.createSession(param));
    }

    /**
     * 流式问答
     */
    @PostMapping(value = "/base", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> baseChat( @RequestBody RobotTransReq param) {
        return chatMsgService.baseChat(param);
    }

    /**
     * 停止流式问答
     */
    @PostMapping("/stop_chat")
    public Result<?> gptStopChat( @RequestBody SessionBaseParam param) {
        chatMsgService.stopChat(param);
        return Result.ok();
    }
}

