ChatGPT stream output example
Top 65.9% on sourcepulse
This project provides a Java-based example for implementing streaming output from OpenAI's ChatGPT, specifically targeting developers who need to integrate this functionality into their applications. It demonstrates how to achieve real-time, token-by-token responses, enhancing user experience for chat interfaces.
How It Works
The project leverages the chatgpt-java
SDK to interact with OpenAI's API. It implements two primary streaming methods: Server-Sent Events (SSE) and WebSockets. SSE is achieved via OpenAISSEEventSourceListener
, while WebSockets use OpenAIWebSocketEventSourceListener
. Both methods enable the API to return responses over long-lived HTTP connections when the stream
parameter is set to true
in completion requests.
Quick Start & Requirements
com.unfbx.chatgptsteamoutput.ChatgptSteamOutputApplication
. Access SSE at http://localhost:8000/
and WebSocket at http://localhost:8000/websocket
.com.unfbx:chatgpt-java
(version 1.0.12).application.properties
to set server.port
, chatgpt.apiKey
, and chatgpt.apiHost
.Highlighted Details
chatgpt-java
SDK.Maintenance & Community
The project is maintained by Grt1228. Community support and discussion are available via a WeChat group, with contact information provided in the README.
Licensing & Compatibility
The licensing is not explicitly stated in the README. Compatibility for commercial use or closed-source linking is not specified.
Limitations & Caveats
The project is presented as a simple example for reference, and users are encouraged to build their own implementations based on the SDK. SSE is not supported on Mini Programs.
2 years ago
1 week