Skip to content

Commit

Permalink
refresh-gpt-chat v0.0.3
Browse files Browse the repository at this point in the history
1.新增打字机效果
  • Loading branch information
Yanyutin753 committed Feb 2, 2024
1 parent 9686ea6 commit 434be49
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 339 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.yyandywt99</groupId>
<artifactId>refresh-gpt-chat</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.1-SNAPSHOT</version>
<name>refresh-gpt-chat</name>
<description>refresh-gpt-chat</description>
<properties>
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/com/refresh/gptChat/controller/chatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,23 +317,39 @@ private void outPutChat(HttpServletResponse response, Response resp, Object conv
try {
JSONObject jsonObject = new JSONObject(com.alibaba.fastjson2.JSON.toJSONString(conversation));
boolean isStream = jsonObject.optBoolean("stream", false);
int one_messageByte;
int sleep_time;
if (isStream) {
if (!jsonObject.optString("model", "gpt-3.5-turbo").contains("gpt-4")) {
one_messageByte = 2048;
sleep_time = 0;
} else {
one_messageByte = 128;
sleep_time = 25;
}
response.setContentType("text/event-stream; charset=UTF-8");
} else {
one_messageByte = 8192;
sleep_time = 0;
response.setContentType("application/json; charset=utf-8");
}
OutputStream out = new BufferedOutputStream(response.getOutputStream());
InputStream in = new BufferedInputStream(resp.body().byteStream());
// 一次拿多少数据 迭代循环
byte[] buffer = new byte[8192];
byte[] buffer = new byte[one_messageByte];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
out.flush();
try {
if(sleep_time > 0){
Thread.sleep(sleep_time);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (JSONException e) {
} catch (IOException | JSONException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void main(String[] args) {
@PostConstruct
public void initialize() {
log.info("------------------------------------------------------");
log.info("----------原神refresh-gpt-chat启动成功------------");
log.info("----------原神refresh-gpt-chat v0.0.3启动成功------------");
log.info("URL地址:http://0.0.0.0:" + serverPort + contextPath +"");
log.info("------------------------------------------------------");
}
Expand Down
332 changes: 0 additions & 332 deletions target/classes/PandoraNext-tokensTool的docker命令.txt

This file was deleted.

Binary file modified target/classes/com/refresh/gptChat/controller/chatController.class
Binary file not shown.
Loading

0 comments on commit 434be49

Please sign in to comment.