mirror of
https://github.com/YuWanTingbb/unofficial-gpt4.git
synced 2025-10-17 07:24:06 +00:00
增加新变量max_tokens以限制最大请求max_tokens
This commit is contained in:
@@ -11,5 +11,6 @@
|
|||||||
"one_coCopilot_limit":30,
|
"one_coCopilot_limit":30,
|
||||||
"one_selfCopilot_limit":30,
|
"one_selfCopilot_limit":30,
|
||||||
"serverPort":8080,
|
"serverPort":8080,
|
||||||
|
"max_tokens":32,
|
||||||
"prefix":"/"
|
"prefix":"/"
|
||||||
}
|
}
|
@@ -145,7 +145,7 @@ public class ChatController {
|
|||||||
machineIdList = new ConcurrentHashMap<>();
|
machineIdList = new ConcurrentHashMap<>();
|
||||||
setSystemSetting(selectSetting());
|
setSystemSetting(selectSetting());
|
||||||
setExecutor(systemSetting.getMaxPoolSize());
|
setExecutor(systemSetting.getMaxPoolSize());
|
||||||
log.info("服务启动了最大线程数为"+systemSetting.getMaxPoolSize()+"的线程池");
|
log.info("服务启动了最大线程数为" + systemSetting.getMaxPoolSize() + "的线程池");
|
||||||
log.info(loadData());
|
log.info(loadData());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -277,7 +277,7 @@ public class ChatController {
|
|||||||
Integer oneCopilotLimit = getValueOrDefault(jsonObject, "one_copilot_limit", 30, "config.json没有新增one_copilot_limit参数,现已增加!");
|
Integer oneCopilotLimit = getValueOrDefault(jsonObject, "one_copilot_limit", 30, "config.json没有新增one_copilot_limit参数,现已增加!");
|
||||||
Integer oneCoCopilotLimit = getValueOrDefault(jsonObject, "one_coCopilot_limit", 30, "config.json没有新增one_coCopilot_limit参数,现已增加!");
|
Integer oneCoCopilotLimit = getValueOrDefault(jsonObject, "one_coCopilot_limit", 30, "config.json没有新增one_coCopilot_limit参数,现已增加!");
|
||||||
Integer oneSelfCopilotLimit = getValueOrDefault(jsonObject, "one_selfCopilot_limit", 30, "config.json没有新增one_selfCopilot_limit参数,现已增加!");
|
Integer oneSelfCopilotLimit = getValueOrDefault(jsonObject, "one_selfCopilot_limit", 30, "config.json没有新增one_selfCopilot_limit参数,现已增加!");
|
||||||
|
Integer max_tokens = getValueOrDefault(jsonObject, "max_tokens", 32, "config.json没有新增max_tokens参数,现已增加!");
|
||||||
// 将修改后的 JSONObject 转换为格式化的 JSON 字符串
|
// 将修改后的 JSONObject 转换为格式化的 JSON 字符串
|
||||||
String updatedJson = com.alibaba.fastjson.JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat);
|
String updatedJson = com.alibaba.fastjson.JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat);
|
||||||
Files.write(Paths.get(parent), updatedJson.getBytes());
|
Files.write(Paths.get(parent), updatedJson.getBytes());
|
||||||
@@ -295,6 +295,7 @@ public class ChatController {
|
|||||||
config.setOne_coCopilot_limit(oneCoCopilotLimit);
|
config.setOne_coCopilot_limit(oneCoCopilotLimit);
|
||||||
config.setOne_selfCopilot_limit(oneSelfCopilotLimit);
|
config.setOne_selfCopilot_limit(oneSelfCopilotLimit);
|
||||||
config.setGpt4_prompt(gpt4Prompt);
|
config.setGpt4_prompt(gpt4Prompt);
|
||||||
|
config.setMax_tokens(max_tokens);
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -687,7 +688,7 @@ public class ChatController {
|
|||||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Request body is missing or not in JSON format");
|
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Request body is missing or not in JSON format");
|
||||||
}
|
}
|
||||||
long tokens = conversation.tokens();
|
long tokens = conversation.tokens();
|
||||||
if (tokens > 32 * 1024) {
|
if (tokens > systemSetting.getMax_tokens() * 1024) {
|
||||||
log.error("Thread ID: " + Thread.currentThread().getId() + "请求密钥:" + apiKey + ",本次请求tokens is too long and over 32K: " + tokens);
|
log.error("Thread ID: " + Thread.currentThread().getId() + "请求密钥:" + apiKey + ",本次请求tokens is too long and over 32K: " + tokens);
|
||||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Message is too long and over 32K");
|
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Message is too long and over 32K");
|
||||||
} else if (tokens <= 0) {
|
} else if (tokens <= 0) {
|
||||||
@@ -1401,11 +1402,9 @@ public class ChatController {
|
|||||||
// 使用stream形式适应List
|
// 使用stream形式适应List
|
||||||
List<StreamResponse.Choice> choices = Stream.of(new StreamResponse.Choice(0, new StreamResponse.Delta(content), null)).collect(Collectors.toList());
|
List<StreamResponse.Choice> choices = Stream.of(new StreamResponse.Choice(0, new StreamResponse.Delta(content), null)).collect(Collectors.toList());
|
||||||
StreamResponse streamResponse = new StreamResponse(chat_message_id, model, "chat.completion.chunk", choices, timestamp);
|
StreamResponse streamResponse = new StreamResponse(chat_message_id, model, "chat.completion.chunk", choices, timestamp);
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
String tmpRes = "data: " +
|
||||||
stringBuilder.append("data: ");
|
com.alibaba.fastjson.JSONObject.toJSONString(streamResponse) +
|
||||||
stringBuilder.append(com.alibaba.fastjson.JSONObject.toJSONString(streamResponse));
|
"\n\n";
|
||||||
stringBuilder.append("\n\n");
|
|
||||||
String tmpRes = stringBuilder.toString();
|
|
||||||
|
|
||||||
out.print(tmpRes);
|
out.print(tmpRes);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
@@ -92,6 +92,7 @@ public class copilotApplication {
|
|||||||
getValueOrDefault(jsonObject, "one_copilot_limit", 30, "config.json没有新增one_copilot_limit参数,现已增加!");
|
getValueOrDefault(jsonObject, "one_copilot_limit", 30, "config.json没有新增one_copilot_limit参数,现已增加!");
|
||||||
getValueOrDefault(jsonObject, "one_coCopilot_limit", 30, "config.json没有新增one_coCopilot_limit参数,现已增加!");
|
getValueOrDefault(jsonObject, "one_coCopilot_limit", 30, "config.json没有新增one_coCopilot_limit参数,现已增加!");
|
||||||
getValueOrDefault(jsonObject, "one_selfCopilot_limit", 30, "config.json没有新增one_selfCopilot_limit参数,现已增加!");
|
getValueOrDefault(jsonObject, "one_selfCopilot_limit", 30, "config.json没有新增one_selfCopilot_limit参数,现已增加!");
|
||||||
|
getValueOrDefault(jsonObject, "max_tokens", 32, "config.json没有新增max_tokens参数,现已增加!");
|
||||||
|
|
||||||
// 将修改后的 JSONObject 转换为格式化的 JSON 字符串
|
// 将修改后的 JSONObject 转换为格式化的 JSON 字符串
|
||||||
String updatedJson = com.alibaba.fastjson.JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat);
|
String updatedJson = com.alibaba.fastjson.JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat);
|
||||||
@@ -296,6 +297,7 @@ public class copilotApplication {
|
|||||||
System.out.println("one_copilot_limit:" + ChatController.getSystemSetting().getOne_copilot_limit());
|
System.out.println("one_copilot_limit:" + ChatController.getSystemSetting().getOne_copilot_limit());
|
||||||
System.out.println("one_coCopilot_limit:" + ChatController.getSystemSetting().getOne_coCopilot_limit());
|
System.out.println("one_coCopilot_limit:" + ChatController.getSystemSetting().getOne_coCopilot_limit());
|
||||||
System.out.println("one_selfCopilot_limit:" + ChatController.getSystemSetting().getOne_selfCopilot_limit());
|
System.out.println("one_selfCopilot_limit:" + ChatController.getSystemSetting().getOne_selfCopilot_limit());
|
||||||
|
System.out.println("max_tokens:" + ChatController.getSystemSetting().getMax_tokens());
|
||||||
System.out.println("gpt4-copilot-java 初始化接口成功!");
|
System.out.println("gpt4-copilot-java 初始化接口成功!");
|
||||||
System.out.println("======================================================");
|
System.out.println("======================================================");
|
||||||
System.out.println("******原神gpt4-copilot-java v0.2.7启动成功******");
|
System.out.println("******原神gpt4-copilot-java v0.2.7启动成功******");
|
||||||
|
@@ -66,6 +66,7 @@ public class Conversation implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private List<Message> messages;
|
private List<Message> messages;
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private String model = "gpt-3.5-turbo";
|
private String model = "gpt-3.5-turbo";
|
||||||
|
|
||||||
|
@@ -75,4 +75,9 @@ public class SystemSetting {
|
|||||||
*/
|
*/
|
||||||
private Integer one_selfCopilot_limit;
|
private Integer one_selfCopilot_limit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* max_tokens
|
||||||
|
*/
|
||||||
|
private Integer max_tokens;
|
||||||
|
|
||||||
}
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user