package com.ruoyi.ai.controller;
|
|
import com.ruoyi.ai.assistant.ApproveTodoAgent;
|
import com.ruoyi.ai.assistant.ApproveTodoIntentExecutor;
|
import com.ruoyi.ai.bean.ChatForm;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
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;
|
|
@Tag(name = "协同办公助手")
|
@RestController
|
@RequestMapping("/xiaozhi")
|
public class XiaozhiController {
|
|
private final ApproveTodoAgent approveTodoAgent;
|
private final ApproveTodoIntentExecutor approveTodoIntentExecutor;
|
|
public XiaozhiController(ApproveTodoAgent approveTodoAgent, ApproveTodoIntentExecutor approveTodoIntentExecutor) {
|
this.approveTodoAgent = approveTodoAgent;
|
this.approveTodoIntentExecutor = approveTodoIntentExecutor;
|
}
|
|
@Operation(summary = "对话")
|
@PostMapping(value = "/chat", produces = "text/stream;charset=utf-8")
|
public Flux<String> chat(@RequestBody ChatForm chatForm) {
|
String directResponse = approveTodoIntentExecutor.tryExecute(chatForm.getMessage());
|
if (directResponse != null) {
|
return Flux.just(directResponse);
|
}
|
return approveTodoAgent.chat(chatForm.getMemoryId(), chatForm.getMessage());
|
}
|
}
|