chatgpt-steam-output  by Grt1228

ChatGPT stream output example

created 2 years ago
468 stars

Top 65.9% on sourcepulse

GitHubView on GitHub
Project Summary

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

  • Install: Clone the repository and build using Maven.
  • Prerequisites: Java Development Kit (JDK), Maven, OpenAI API key, and optionally an OpenAI API Host address.
  • Run: Execute com.unfbx.chatgptsteamoutput.ChatgptSteamOutputApplication. Access SSE at http://localhost:8000/ and WebSocket at http://localhost:8000/websocket.
  • Dependencies: com.unfbx:chatgpt-java (version 1.0.12).
  • Configuration: Modify application.properties to set server.port, chatgpt.apiKey, and chatgpt.apiHost.

Highlighted Details

  • Supports both SSE and WebSocket streaming output methods.
  • Includes token calculation functionality.
  • Demonstrates integration with the chatgpt-java SDK.
  • Provides example HTML interfaces for testing SSE and WebSocket endpoints.

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.

Health Check
Last commit

2 years ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
0
Star History
2 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.