44 lines
1.6 KiB
Java
44 lines
1.6 KiB
Java
package com.example.springaidemo.controller;
|
|
|
|
|
|
import com.example.springaidemo.bean.ChatRequest;
|
|
import com.example.springaidemo.service.DeepseekChatService;
|
|
import org.springframework.ai.chat.client.ChatClientRequest;
|
|
import org.springframework.ai.chat.model.ChatResponse;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
import reactor.core.publisher.Flux;
|
|
|
|
import java.util.Map;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
@RestController
|
|
@RequestMapping("/chatController")
|
|
public class ChatController {
|
|
|
|
@Autowired
|
|
private DeepseekChatService deepseekChatService;
|
|
|
|
@GetMapping("/ai/chat")
|
|
public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
|
|
return deepseekChatService.chat(message);
|
|
}
|
|
|
|
@GetMapping("/ai/generateStream")
|
|
public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
|
|
return deepseekChatService.streamChat(message);
|
|
}
|
|
|
|
@PostMapping(value = "/ai/sseChat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
public SseEmitter streamChat(@RequestBody ChatRequest chatRequest) {
|
|
return deepseekChatService.sseChat(chatRequest.getMessage());
|
|
}
|
|
|
|
@PostMapping(value = "/ai/thinkChat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
public SseEmitter thinkChat(@RequestBody ChatRequest chatRequest) {
|
|
return deepseekChatService.thinkChat(chatRequest.getMessage());
|
|
}
|
|
|
|
} |