package cn.temptation.web;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class ChatController {
private final ChatClient chatClient;
// 阻塞式交互
// 浏览器的地址栏输入:http://127.0.0.1/ai/chat1?prompt=你是谁
@RequestMapping("/chat1")
public String chat1(String prompt) {
return chatClient.prompt()
.user(prompt)
.call()
.content();
}
// 流式交互
// 浏览器的地址栏输入:http://127.0.0.1/ai/chat2?prompt=你是谁
@RequestMapping(value = "/chat2", produces = "text/html;charset=utf-8")
public Flux<String> chat2(String prompt) {
return chatClient.prompt()
.user(prompt)
.stream()
.content();
}
}
最近下载更多
sky丶小十 LV7
9月15日
lee123321 LV22
8月4日
jhkhk313 LV1
6月9日
kirito0721 LV1
6月8日
yigu123 LV6
6月4日
zhaixunfei LV8
5月30日
vincemokea LV9
5月11日
魏彪毅 LV1
5月7日
gshnlj LV15
5月6日
15838634741 LV18
4月7日

最近浏览