PlexPt / chatgpt-java

ChatGPT Java SDK。支持 GPT-4o、 GPT4 API。开箱即用。An unofficial Java SDK for seamless integration with ChatGPT's GPT-3.5 and GPT-4 APIs. Ready-to-use, simple setup, and efficient for building AI-powered applications.
https://chat.plexpt.com/
GNU General Public License v3.0
3.58k stars 704 forks source link

我在前端收到的数据流没有收到换行符,但是debug的是否发现gpt确实是返回了换行的 #207

Closed Jeffrey2971 closed 11 months ago

Jeffrey2971 commented 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;
}
PlexPt commented 11 months ago

有类似问题,翻一下前面的issue