修改报错处理

This commit is contained in:
Yanyutin753
2024-04-22 21:57:05 +08:00
parent 91a8b21fa8
commit 5b114a339b
12 changed files with 32 additions and 21 deletions

View File

@@ -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

View File

@@ -10,7 +10,7 @@
</parent>
<groupId>com.gpt4.copilot</groupId>
<artifactId>gpt-4-copilot</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<name>native</name>
<description>Demo project for Spring Boot with GraalVM Native Image</description>
<properties>

View File

@@ -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) {

View File

@@ -25,7 +25,7 @@ public class CustomErrorController implements ErrorController {
" <title>Document</title>\n" +
"</head>\n" +
"<body>\n" +
" <p>Thanks you use gpt4-copilot-java-0.2.2</p>\n" +
" <p>Thanks you use gpt4-copilot-java-0.2.3</p>\n" +
" <p><a href=\"https://apifox.com/apidoc/shared-4301e565-a8df-48a0-85a5-bda2c4c3965a\">详细使用文档</a></p>\n" +
" <p><a href=\"https://github.com/Yanyutin753/unofficial-gpt4-api\">项目地址</a></p>\n" +
"</body>\n" +

View File

@@ -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重试机制");

Binary file not shown.

View File

@@ -1,3 +1,3 @@
artifactId=gpt-4-copilot
groupId=com.gpt4.copilot
version=0.2.2
version=0.2.3