spring boot 3.0.4
I am working on a chatgpt client and need to stop the generation function. Axios uses signal: abortController.signal. How do I listen to the cancellation event in the spring webflux api and stop the call of the chatgpt interface? Below is my code
Controller
@PostMapping(path = "/{conversationId}/completions", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<DataResult<ChatProcessResponse>> completions(@PathVariable Long conversationId,
@RequestParam Long parentMessageId) {
Flux<ChatProcessResponse> flux = chatService.completions(conversationId, parentMessageId);
return flux
.map(DataResult::success);
}
Service
public Flux<ChatProcessResponse> completions(Long conversationId, Long parentMessageId) {
ChatCompletionsRequest chatCompletionsRequest = new ChatCompletionsRequest ();
// chatCompletionsRequest .setXXX
return openaiAgent.chatCompletions(chatCompletionsRequest).mapNotNull(jsonStr->{
ChatProcessResponse dtoData = new ChatProcessResponse ();
// convert data
return dtoData;
});
}
Agent
@HttpExchange
public interface OpenaiAgent {
@PostExchange("/v1/chat/completions")
Flux<String> chatCompletions(@RequestBody ChatCompletionsRequest chatCompletionsRequest);
}
ts axios
const controller = new AbortController()
axios.get('/api/chat', {
signal: controller.signal
})
How can I modify the code?
Comment From: sbrannen
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.