Closed Jeffrey2971 closed 11 months ago
` const eventSource = new EventSource('http://127.0.0.1/chat/sse?prompt=' + this.q);
eventSource.addEventListener('message', event => { console.log(event.data) });
`
@GetMapping("/chat/sse") @CrossOrigin public SseEmitter sseEmitter(String prompt) { Proxy proxy = Proxys.http("127.0.0.1", 1080); ChatGPTStream chatGPTStream = ChatGPTStream.builder() .timeout(600) .apiKey("") .proxy(proxy) .apiHost("https://api.openai.com/") .build() .init(); SseEmitter sseEmitter = new SseEmitter(-1L); SseStreamListener listener = new SseStreamListener(sseEmitter); Message message = Message.of(prompt); listener.setOnComplate(msg -> { //回答完成,可以做一些事情 }); chatGPTStream.streamChatCompletion(Arrays.asList(message), listener); return sseEmitter; }
有类似问题,翻一下前面的issue
` const eventSource = new EventSource('http://127.0.0.1/chat/sse?prompt=' + this.q);
`