diff --git a/Dockerfiles/Dockerfile.jar b/Dockerfiles/Dockerfile.jar index 4398384..f1058e9 100644 --- a/Dockerfiles/Dockerfile.jar +++ b/Dockerfiles/Dockerfile.jar @@ -8,7 +8,7 @@ LABEL maintainer="Yanyutin753" USER root # 复制JAR文件到容器的/app目录下 -COPY /target/gpt-4-copilot-0.2.2.jar app.jar +COPY /target/gpt-4-copilot-0.2.3.jar app.jar # 声明服务运行在8081端口 EXPOSE 8081 diff --git a/pom.xml b/pom.xml index 8a5b6d2..5f6dd92 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.gpt4.copilot gpt-4-copilot - 0.2.2 + 0.2.3 native Demo project for Spring Boot with GraalVM Native Image diff --git a/src/main/java/com/gpt4/copilot/controller/ChatController.java b/src/main/java/com/gpt4/copilot/controller/ChatController.java index df40048..06dcd70 100644 --- a/src/main/java/com/gpt4/copilot/controller/ChatController.java +++ b/src/main/java/com/gpt4/copilot/controller/ChatController.java @@ -519,6 +519,7 @@ public class ChatController { log.info("token过期,Github CopilotToken重置化成功!"); return againConversation(response, conversation, token, apiKey, model); } else { + log.info("接口返回" + resp.code() + ",已500返回报错提醒..............."); return new ResponseEntity<>(Result.error("HUm... A error occur......"), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -624,13 +625,18 @@ public class ChatController { } else if (resp.code() == 400) { return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { - String token = getCoCoToken(apiKey); - if (token == null) { - return new ResponseEntity<>(Result.error("cocopilot APIKey is wrong"), HttpStatus.UNAUTHORIZED); + if (resp.code() == 403) { + String token = getCoCoToken(apiKey); + if (token == null) { + return new ResponseEntity<>(Result.error("cocopilot APIKey is wrong"), HttpStatus.UNAUTHORIZED); + } + coCopilotTokenList.put(apiKey, token); + log.info("token过期,coCopilotToken重置化成功!"); + return againConversation(response, conversation, token, apiKey, model); + } else { + log.info("接口返回" + resp.code() + "已500返回报错提醒..............."); + return new ResponseEntity<>(Result.error("HUm... A error occur......"), HttpStatus.INTERNAL_SERVER_ERROR); } - coCopilotTokenList.put(apiKey, token); - log.info("token过期,coCopilotToken重置化成功!"); - return againConversation(response, conversation, token, apiKey, model); } } else { // 流式和非流式输出 @@ -787,13 +793,18 @@ public class ChatController { } else if (resp.code() == 400) { return new ResponseEntity<>(Result.error("messages is none or too long and over 32K"), HttpStatus.INTERNAL_SERVER_ERROR); } else { - String token = getSelfToken(apiKey, requestUrl); - if (token == null) { - return new ResponseEntity<>(Result.error("自定义self APIKey is wrong"), HttpStatus.UNAUTHORIZED); + if (resp.code() == 403) { + String token = getSelfToken(apiKey, requestUrl); + if (token == null) { + return new ResponseEntity<>(Result.error("自定义self APIKey is wrong"), HttpStatus.UNAUTHORIZED); + } + selfTokenList.put(apiKey, token); + log.info("token过期,自定义selfToken重置化成功!"); + return againConversation(response, conversation, token, apiKey, model); + } else { + log.info("接口返回" + resp.code() + "已500返回报错提醒..............."); + return new ResponseEntity<>(Result.error("HUm... A error occur......"), HttpStatus.INTERNAL_SERVER_ERROR); } - selfTokenList.put(apiKey, token); - log.info("token过期,自定义selfToken重置化成功!"); - return againConversation(response, conversation, token, apiKey, model); } } else { // 流式和非流式输出 @@ -801,7 +812,7 @@ public class ChatController { } } } catch (Exception e) { - return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(Result.error(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR); } }, executor); @@ -829,7 +840,7 @@ public class ChatController { Request streamRequest = getPrompt(conversation, model, headersMap); try (Response resp = client.newCall(streamRequest).execute()) { if (!resp.isSuccessful()) { - return new ResponseEntity<>("APIKey is wrong!", HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(Result.error("APIKey is wrong!"), HttpStatus.UNAUTHORIZED); } else { // 流式和非流式输出 return outPutChat(response, resp, conversation, model); @@ -837,7 +848,7 @@ public class ChatController { } } catch (Exception e) { log.info("Exception " + e.getMessage()); - return new ResponseEntity<>(Result.error("HUm... A error occur......"), HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(Result.error("HUm...A error occur......"), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -1376,7 +1387,7 @@ public class ChatController { } - /** + /** * chat接口的每个字的睡眠时间 */ private int calculateSleepTime(String model, boolean isStream) { diff --git a/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java b/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java index 61660da..37c3d78 100644 --- a/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java +++ b/src/main/java/com/gpt4/copilot/controller/CustomErrorController.java @@ -25,7 +25,7 @@ public class CustomErrorController implements ErrorController { " Document\n" + "\n" + "\n" + - "

Thanks you use gpt4-copilot-java-0.2.2

\n" + + "

Thanks you use gpt4-copilot-java-0.2.3

\n" + "

详细使用文档

\n" + "

项目地址

\n" + "\n" + diff --git a/src/main/java/com/gpt4/copilot/copilotApplication.java b/src/main/java/com/gpt4/copilot/copilotApplication.java index e644f07..232fc8c 100644 --- a/src/main/java/com/gpt4/copilot/copilotApplication.java +++ b/src/main/java/com/gpt4/copilot/copilotApplication.java @@ -298,7 +298,7 @@ public class copilotApplication { System.out.println("one_selfCopilot_limit:" + ChatController.getSystemSetting().getOne_selfCopilot_limit()); System.out.println("gpt4-copilot-java 初始化接口成功!"); System.out.println("======================================================"); - System.out.println("******原神gpt4-copilot-java v0.2.2启动成功******"); + System.out.println("******原神gpt4-copilot-java v0.2.3启动成功******"); System.out.println("* 由于本人略菜,graalvm依赖问题无法解决,之后代码将只通过jar和docker的形式运行"); System.out.println("* 修复部分bug,优化读取config.json代码,提升稳定性"); System.out.println("* 新增token计算,优化报错,支持one_api重试机制"); diff --git a/target/classes/com/gpt4/copilot/controller/ChatController.class b/target/classes/com/gpt4/copilot/controller/ChatController.class index 06b0d7a..11c3f5b 100644 Binary files a/target/classes/com/gpt4/copilot/controller/ChatController.class and b/target/classes/com/gpt4/copilot/controller/ChatController.class differ diff --git a/target/classes/com/gpt4/copilot/controller/CustomErrorController.class b/target/classes/com/gpt4/copilot/controller/CustomErrorController.class index ad1c96b..dd7e3ed 100644 Binary files a/target/classes/com/gpt4/copilot/controller/CustomErrorController.class and b/target/classes/com/gpt4/copilot/controller/CustomErrorController.class differ diff --git a/target/classes/com/gpt4/copilot/copilotApplication.class b/target/classes/com/gpt4/copilot/copilotApplication.class index 304c92e..b83f914 100644 Binary files a/target/classes/com/gpt4/copilot/copilotApplication.class and b/target/classes/com/gpt4/copilot/copilotApplication.class differ diff --git a/target/gpt-4-copilot-0.2.2.jar.original b/target/gpt-4-copilot-0.2.2.jar.original deleted file mode 100644 index 23c90a2..0000000 Binary files a/target/gpt-4-copilot-0.2.2.jar.original and /dev/null differ diff --git a/target/gpt-4-copilot-0.2.2.jar b/target/gpt-4-copilot-0.2.3.jar similarity index 99% rename from target/gpt-4-copilot-0.2.2.jar rename to target/gpt-4-copilot-0.2.3.jar index d6c755f..e6daf71 100644 Binary files a/target/gpt-4-copilot-0.2.2.jar and b/target/gpt-4-copilot-0.2.3.jar differ diff --git a/target/gpt-4-copilot-0.2.3.jar.original b/target/gpt-4-copilot-0.2.3.jar.original new file mode 100644 index 0000000..06b1f74 Binary files /dev/null and b/target/gpt-4-copilot-0.2.3.jar.original differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index cbc4ed1..4d34fb5 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,3 +1,3 @@ artifactId=gpt-4-copilot groupId=com.gpt4.copilot -version=0.2.2 +version=0.2.3