Skip to content

Commit 9ecd54b

Browse files
committed
📝
1 parent 383a31c commit 9ecd54b

File tree

2 files changed

+106
-31
lines changed

2 files changed

+106
-31
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.0.1'
121121
.apiHost("https://api.openai.com/") //反向代理地址
122122
.build()
123123
.init();
124-
125-
Message message = Message.of("写一段七言绝句诗,题目是:火锅!");
126-
124+
127125
Message system = Message.ofSystem("你现在是一个诗人,专门写七言绝句");
128126
Message message = Message.of("写一段七言绝句诗,题目是:火锅!");
129127

@@ -261,7 +259,6 @@ https://juejin.cn/post/7173447848292253704
261259

262260
https://mirror.xyz/boxchen.eth/9O9CSqyKDj4BKUIil7NC1Sa1LJM-3hsPqaeW_QjfFBc
263261

264-
### 控制台直接使用测试
265262
#### 另外请看看我的另一个项目 [ChatGPT中文使用指南](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)
266263

267264
# 云服务器

README_en.md

Lines changed: 105 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,142 @@
99

1010
[简体中文文档](https://github.com/PlexPt/chatgpt-java/blob/main/README_zh.md).
1111

12-
Reverse Engineered ChatGPT by OpenAI. Extensible for chatbots etc.
12+
SDK for OpenAI ChatGPT. If you find it helpful, please give it a star in the upper right corner.
1313

14-
Thanks to [revChatGPT](https://github.com/acheong08/ChatGPT).
14+
# Features
1515

16+
| Feature | Support |
17+
| :--------------: | :---------: |
18+
| GPT 3.5 | Supported |
19+
| GPT 4.0 | Supported |
20+
| GPT 4.0-32k | Supported |
21+
| Streaming Dialog | Supported |
22+
| Blocking Dialog | Supported |
23+
| Front-end | None |
24+
| Context | Supported |
25+
| Token Compute | Coming Soon |
26+
| Multiple Keys | Supported |
27+
| Proxy | Supported |
28+
| Reverse Proxy | Supported |
1629

17-
# Features
1830
![image](https://user-images.githubusercontent.com/36258159/205534498-acc59484-c4b4-487d-89a7-d7b884af709b.png)
1931

2032
![image](https://user-images.githubusercontent.com/15922823/206353660-47d99158-a664-4ade-b2f1-e2cc8ac68b74.png)
2133

2234
## USE
2335

24-
maven
36+
#### maven
37+
2538
```
2639
<dependency>
2740
<groupId>com.github.plexpt</groupId>
2841
<artifactId>chatgpt</artifactId>
29-
<version>1.2.0</version>
42+
<version>4.0.1</version>
3043
</dependency>
3144
```
3245

33-
gradle
46+
#### gradle
47+
3448
```
35-
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '1.2.0'
49+
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.0.1'
3650
```
3751

52+
### Quick Start
3853

39-
then
4054
```
41-
Chatbot chatbot = new Chatbot("sessionToken");
42-
Map<String, Object> chatResponse = chatbot.getChatResponse("hello");
43-
System.out.println(chatResponse.get("message"));
55+
56+
ChatGPT chatGPT = ChatGPT.builder()
57+
.apiKey("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")
58+
.build()
59+
.init();
60+
61+
String res = chatGPT.chat("hello!");
62+
System.out.println(res);
63+
```
64+
### Advanced Usage
65+
66+
```java
67+
//Proxy is required in some contry
68+
Proxy proxy = Proxys.http("127.0.0.1", 1080);
69+
70+
ChatGPT chatGPT = ChatGPT.builder()
71+
.apiKey("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")
72+
.proxy(proxy)
73+
.timeout(900)
74+
.apiHost("https://api.openai.com/") //Reverse proxy address
75+
.build()
76+
.init();
77+
78+
Message system = Message.ofSystem("You are now a poet, specializing in writing seven character quatrains");
79+
Message message = Message.of("Write a seven-character quatrain poem titled: Future!");
80+
81+
ChatCompletion chatCompletion = ChatCompletion.builder()
82+
.model(ChatCompletion.Model.GPT_3_5_TURBO.getName())
83+
.messages(Arrays.asList(system, message))
84+
.maxTokens(3000)
85+
.temperature(0.9)
86+
.build();
87+
ChatCompletionResponse response = chatGPT.chatCompletion(chatCompletion);
88+
Message res = response.getChoices().get(0).getMessage();
89+
System.out.println(res);
90+
```
91+
92+
### Streaming Usage
93+
94+
```java
95+
96+
97+
ChatGPTStream chatGPTStream = ChatGPTStream.builder()
98+
.timeout(600)
99+
.apiKey("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")
100+
.build()
101+
.init();
102+
103+
104+
ConsoleStreamListener listener = new ConsoleStreamListener();
105+
Message message = Message.of("Write a seven-character quatrain poem titled: Future!");
106+
ChatCompletion chatCompletion = ChatCompletion.builder()
107+
.messages(Arrays.asList(message))
108+
.build();
109+
chatGPTStream.streamChatCompletion(chatCompletion, listener);
110+
44111
```
45-
### Get sessionToken
46-
https://github.com/acheong08/ChatGPT/wiki/Setup#token-authentication
47112

113+
### Using Spring SseEmitter with Streaming
48114

49-
### CLI use
50-
1. download from release
51-
2. edit config.json
52-
3. run
115+
Refer to [SseStreamListener](https://chat.plexpt.com/src/main/java/com/plexpt/chatgpt/listener/SseStreamListener.java)
53116

117+
```java
54118

55-
# Awesome ChatGPT
56-
[My list](https://github.com/stars/acheong08/lists/awesome-chatgpt)
119+
@GetMapping("/chat/sse")
120+
@CrossOrigin
121+
public SseEmitter sseEmitter(String prompt) {
122+
57123

58-
If you have a cool project you want added to the list, open an issue.
124+
ChatGPTStream chatGPTStream = ChatGPTStream.builder()
125+
.timeout(600)
126+
.apiKey("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")
127+
.apiHost("https://api.openai.com/")
128+
.build()
129+
.init();
130+
131+
SseEmitter sseEmitter = new SseEmitter(-1L);
59132

60-
# Disclaimers
61-
This is not an official OpenAI product. This is a personal project and is not affiliated with OpenAI in any way. Don't sue me
133+
SseStreamListener listener = new SseStreamListener(sseEmitter);
134+
Message message = Message.of(prompt);
62135

63-
### This is a library and not intended for direct CLI use
64-
The CLI functionality is for demo and testing only. Captcha is not supported (For unclean IP addresses)
136+
listener.setOnComplate(msg -> {
137+
//The answer is complete, do something
138+
});
139+
chatGPTStream.streamChatCompletion(Arrays.asList(message), listener);
140+
141+
142+
return sseEmitter;
143+
}
144+
145+
```
65146

66-
### CLI use
67-
[@rawandahmad698](https://github.com/rawandahmad698) has a much better CLI tool at
68147

69-
**[PyChatGPT](https://github.com/rawandahmad698/PyChatGPT)** supports captcha!
70148

71149
# Star History
72150

0 commit comments

Comments
 (0)