Introduction to chatgpt-stream
Chatgpt-stream is an open-source project designed to seamlessly integrate OpenAI's conversational models, such as gpt-3.5-turbo and gpt-4, into business applications using Java. The project is noted for its simplicity, ease of integration with Spring Boot, and lack of third-party dependencies. It provides developers with the tools to build chat applications that support chat memory and image rendering while maintaining the benefits of a minimalistic setup. The project also supports syntax highlighting for code blocks and Markdown formatting, making it versatile for various development needs.
Key Features
- No Third-Party Dependencies: Chatgpt-stream simplifies deployment by eliminating the need for external libraries.
- Streamed Responses: Utilizes server-sent events (SSE) technology to deliver responses in a streaming format.
- Chat Memory: Retains conversation history for more contextual interactions.
- Image Rendering: Supports the integration of image-based queries and outputs.
Developers interested in expanding their knowledge can explore how SSE is implemented within the project.
Visual Outcomes
Although the project acknowledges that its frontend design may not be professional, it provides visual demonstrations of its latest and initial versions:
- Latest Version
- Early Demos
Development Timeline
- 2023-06-16: Enhanced robustness and standardized data return processes. Improved error handling within the SSE interface and introduced a POST request option in HTML, as illustrated in index_post.html.
- 2023-04-02: Switched to Vue for more straightforward rendering, with added support for code highlighting and Markdown table syntax.
- 2023-04-01: Improved styling and fixed bug related to chat memory.
- 2023-03-29: Enhanced concurrency capabilities with Netty.
- 2023-03-23 Afternoon: Introduced chat memory and image rendering features.
- 2023-03-23 Morning: Released the first simplified demo version, available in the
original-simplicity
branch.
Important Configuration
To get started, configure the following in your YAML file:
openai:
key-list:
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Your API key list, used in rotation
- xxxxx
API keys can be obtained from OpenAI's platform.
Overcoming Mainland China Access Issues
- Using VPN Proxy: The feature is implemented by configuring OpenAiWebClient.java with the correct proxy IP and port:
HttpClient httpClient = HttpClient.create() .secure(sslContextSpec -> sslContextSpec.sslContext(finalSslContext)) .tcpConfiguration(tcpClient -> tcpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP).host("127.0.0.1").port(7890)));
- Deploying Overseas: Simply remove the following configuration:
env: test
Starting the Application
Run the Spring Boot application and access it at http://127.0.0.1:8080/.
Integration with Business Systems
To integrate with business systems, extend the following interface to store messages and track interactions:
public interface CompletedCallBack {
/**
* Callback upon successful completion
*/
void completed(Message questions, String sessionId, String response);
/**
* Failure callback
*/
void fail(Message questions, String sessionId, String response);
}
Future Enhancements
- Streamed Responses
- Chat Memory
- Image Integration
- Additional features to be determined...
Community and Support
For any queries or to contribute ideas, submit an issue or a pull request on the project's GitHub. If you find the project helpful, stars on the repository are greatly appreciated!