Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
PandoraNext-tokensTool v 0.6.8版本
Browse files Browse the repository at this point in the history
PandoraNext-tokensTool v 0.6.8版本
1.新增pool_token传入oneapi的自定义模型,自定义重定向
2.优化copilot,cocopilot的chat,embeddings接口,流畅且支持高并发
3.修复历史问题bug,优化代码,优化前端
Yanyutin753 committed Jan 18, 2024
1 parent 389a4b0 commit fad0096
Showing 50 changed files with 109 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -45,9 +45,14 @@ public class poolToken {
private boolean intoOneApi;

/**
* 接入oneAPI是否开启gpt4模型
* 接入oneApi自定义PandoraNext模型
*/
private boolean pandoraNextGpt4;
private String poolOneApi_models;

/**
* 模型重定向
*/
private String poolModel_mapping;

/**
* 接入oneApi自定义PandoraNext地址
Original file line number Diff line number Diff line change
@@ -125,10 +125,18 @@ public String initializeCheckPool() {
log.info("为节点 " + nodeName + " 添加 intoOneApi 变量成功!");
}
// 初始化pandoraNextGpt4的值为false
if (!nodeToModifyInNew.has("pandoraNextGpt4")) {
nodeToModifyInNew.put("pandoraNextGpt4", false);
log.info("为节点 " + nodeName + " 添加 pandoraNextGpt4 变量成功!");
if (nodeToModifyInNew.has("pandoraNextGpt4")) {
if(nodeToModifyInNew.get("pandoraNextGpt4").asBoolean()){
nodeToModifyInNew.put("poolOneApi_models",gpt4Models);
}
else{
nodeToModifyInNew.put("poolOneApi_models",gpt3Models);
}
nodeToModifyInNew.put("poolModel_mapping","{}");
nodeToModifyInNew.remove("pandoraNextGpt4");
log.info("为节点 " + nodeName + " 删除 pandoraNextGpt4 变量成功!");
}

// 初始化oneApi_pandoraUrl的值为""
if (!nodeToModifyInNew.has("oneApi_pandoraUrl")) {
nodeToModifyInNew.put("oneApi_pandoraUrl", "");
@@ -182,7 +190,8 @@ public List<poolToken> selectPoolToken(String name) {
temRes.setCheckPool(!temNode.has("checkPool") || temNode.get("checkPool").asBoolean());
//0.5.0
temRes.setIntoOneApi(temNode.has("intoOneApi") && temNode.get("intoOneApi").asBoolean());
temRes.setPandoraNextGpt4(temNode.has("pandoraNextGpt4") && temNode.get("pandoraNextGpt4").asBoolean());
temRes.setPoolOneApi_models(temNode.has("poolOneApi_models") ? temNode.get("poolOneApi_models").asText() : "");
temRes.setPoolModel_mapping(temNode.has("poolModel_mapping") ? temNode.get("poolModel_mapping").asText() : "{}");
temRes.setOneApi_pandoraUrl(temNode.has("oneApi_pandoraUrl") ? temNode.get("oneApi_pandoraUrl").asText() : "");
temRes.setGroupChecked(temNode.has("groupChecked") ? temNode.get("groupChecked").asText() : "");
temRes.setPriority(temNode.has("priority") ? temNode.get("priority").asInt() : 0);
@@ -314,6 +323,36 @@ public String addPoolToken(poolToken poolToken) {
return "pool_token添加进one-api失败!";
}
}
String parent = selectFile();
File jsonFile = new File(parent);
Path jsonFilePath = Paths.get(parent);
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode rootNode;
// 如果 JSON 文件不存在,创建一个新的 JSON 对象
if (!jsonFile.exists()) {
// 创建文件
Files.createFile(jsonFilePath);
System.out.println("pool.json创建完成: " + jsonFilePath);
rootNode = objectMapper.createObjectNode();
} else {
if (Files.exists(jsonFilePath) && Files.size(jsonFilePath) > 0) {
rootNode = objectMapper.readTree(jsonFile).deepCopy();
} else {
rootNode = objectMapper.createObjectNode();
}
}
return addPoolJson(poolToken,resPoolToken) ? "pool_token数据添加成功" : "添加失败!";
} catch (IOException e) {
e.printStackTrace();
return "添加失败!";
}
}

/**
*
*/
private boolean addPoolJson(poolToken poolToken,String resPoolToken){
try {
String parent = selectFile();
File jsonFile = new File(parent);
Path jsonFilePath = Paths.get(parent);
@@ -344,7 +383,8 @@ public String addPoolToken(poolToken poolToken) {
//0.5.0
newData.put("checkPool", true);
newData.put("intoOneApi", poolToken.isIntoOneApi());
newData.put("pandoraNextGpt4", poolToken.isPandoraNextGpt4());
newData.put("poolOneApi_models", poolToken.getPoolOneApi_models());
newData.put("poolModel_mapping", poolToken.getPoolModel_mapping());
newData.put("oneApi_pandoraUrl", poolToken.getOneApi_pandoraUrl());
newData.put("groupChecked", poolToken.getGroupChecked());
LocalDateTime now = LocalDateTime.now();
@@ -354,11 +394,11 @@ public String addPoolToken(poolToken poolToken) {
// 将修改后的数据写回到文件
objectMapper.writerWithDefaultPrettyPrinter().writeValue(jsonFile, rootNode);
log.info("数据成功添加到 JSON 文件中。");
return "pool_token数据添加成功";
return true;
} catch (IOException e) {
e.printStackTrace();
return "添加失败!";
}
return false;
}

/**
@@ -402,7 +442,7 @@ public String deletePoolToken(poolToken poolToken) {
log.error("删除成功");
return "删除成功!";
} else {
System.out.println("Node not found: " + name);
log.error("节点未找到: " + name);
return "节点未找到!";
}
} catch (IOException e) {
@@ -614,14 +654,10 @@ private boolean requireKeyId(poolToken addKeyPojo, String[] systemSetting,int ke
jsonObject.put("name", addKeyPojo.getPoolName());
jsonObject.put("base_url", addKeyPojo.getOneApi_pandoraUrl());
jsonObject.put("other", "");
if (addKeyPojo.isPandoraNextGpt4()) {
jsonObject.put("models", gpt4Models);
} else {
jsonObject.put("models", gpt3Models);
}
jsonObject.put("models", addKeyPojo.getPoolOneApi_models());
String group = addKeyPojo.getGroupChecked();
jsonObject.put("group", group);
jsonObject.put("model_mapping", "");
jsonObject.put("model_mapping", addKeyPojo.getPoolModel_mapping());
jsonObject.put("groups", new JSONArray().put(group));
jsonObject.put("priority", addKeyPojo.getPriority());
// 将JSON对象转换为字符串
@@ -680,20 +716,20 @@ public String verifyAllPoolToken() {

@Override
public String toRequirePoolToken(poolToken poolToken) {
String[] strings = systemService.selectOneAPi();
String resPoolToken;
try {
String shareTokens = getShareTokens(poolToken.getShareTokens());
String temPoolToken = poolToken.getPoolToken();
if (temPoolToken != null && temPoolToken.contains("pk")) {
resPoolToken = apiService.getPoolToken(temPoolToken, shareTokens);
} else {
resPoolToken = apiService.getPoolToken("", shareTokens);
String[] strings = systemService.selectOneAPi();
String resPoolToken;
try {
String shareTokens = getShareTokens(poolToken.getShareTokens());
String temPoolToken = poolToken.getPoolToken();
if (temPoolToken != null && temPoolToken.contains("pk")) {
resPoolToken = apiService.getPoolToken(temPoolToken, shareTokens);
} else {
resPoolToken = apiService.getPoolToken("", shareTokens);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
try {
if (resPoolToken == null) {
return "pool_token数据添加失败,请先按全部选择并生成,并确保url配对正确!";
}
@@ -706,51 +742,9 @@ public String toRequirePoolToken(poolToken poolToken) {
return "pool_token修改进one-api失败!";
}
}
String parent = selectFile();
File jsonFile = new File(parent);
Path jsonFilePath = Paths.get(parent);
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode rootNode;
// 如果 JSON 文件不存在,创建一个新的 JSON 对象
if (!jsonFile.exists()) {
// 创建文件
Files.createFile(jsonFilePath);
System.out.println("pool.json创建完成: " + jsonFilePath);
rootNode = objectMapper.createObjectNode();
} else {
if (Files.exists(jsonFilePath) && Files.size(jsonFilePath) > 0) {
rootNode = objectMapper.readTree(jsonFile).deepCopy();
} else {
rootNode = objectMapper.createObjectNode();
}
}
// 创建要添加的新数据
ObjectNode newData = objectMapper.createObjectNode();
newData.put("poolToken", resPoolToken);
List<String> shareTokensList = poolToken.getShareTokens();
ArrayNode arrayNode = objectMapper.createArrayNode();
for (String value : shareTokensList) {
arrayNode.add(value);
}
newData.set("shareTokens", arrayNode);
//0.5.0
newData.put("checkPool", true);
newData.put("intoOneApi", poolToken.isIntoOneApi());
newData.put("pandoraNextGpt4", poolToken.isPandoraNextGpt4());
newData.put("oneApi_pandoraUrl", poolToken.getOneApi_pandoraUrl());
newData.put("groupChecked", poolToken.getGroupChecked());
newData.put("priority", poolToken.getPriority());
LocalDateTime now = LocalDateTime.now();
newData.put("poolTime", now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
// 将新数据添加到 JSON 树中
rootNode.put(poolToken.getPoolName(), newData);
// 将修改后的数据写回到文件
objectMapper.writerWithDefaultPrettyPrinter().writeValue(jsonFile, rootNode);
log.info("数据成功添加到 JSON 文件中。");
return "pool_token数据修改成功";
} catch (IOException e) {
e.printStackTrace();
return "修改失败!";
return addPoolJson(poolToken,resPoolToken) ? "pool_token数据修改成功" : "修改失败!";
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}

@@ -858,14 +852,10 @@ public boolean addKey(poolToken addKeyPojo, String[] systemSetting) {
jsonObject.put("name", addKeyPojo.getPoolName());
jsonObject.put("base_url", addKeyPojo.getOneApi_pandoraUrl());
jsonObject.put("other", "");
if (addKeyPojo.isPandoraNextGpt4()) {
jsonObject.put("models", gpt4Models);
} else {
jsonObject.put("models", gpt3Models);
}
jsonObject.put("models", addKeyPojo.getPoolOneApi_models());
String group = addKeyPojo.getGroupChecked();
jsonObject.put("group", group);
jsonObject.put("model_mapping", "");
jsonObject.put("model_mapping", addKeyPojo.getPoolModel_mapping());
jsonObject.put("groups", new JSONArray().put(group));
// 将JSON对象转换为字符串
String json = jsonObject.toString();
Original file line number Diff line number Diff line change
@@ -44,9 +44,9 @@ public class tokensToolApplication {

public static void main(String[] args) {
log.info("\n--------------------------------------------------------------\n" +
"PandoraNext-tokensTool v 0.6.7版本\n" +
"1.优化添加进one-api的代码,使得id不一直增加\n" +
"2.优化copilot,cocopilot的chat,embeddings接口,接受高并发\n" +
"PandoraNext-tokensTool v 0.6.8版本\n" +
"1.新增pool_token传入oneapi的自定义模型,自定义重定向\n" +
"2.优化copilot,cocopilot的chat,embeddings接口,流畅且支持高并发\n" +
"3.修复历史问题bug,优化代码,优化前端\n" +
"--------------------------------------------------------------\n");
// 启动
1 change: 1 addition & 0 deletions rearServer/src/main/resources/static/css/19.39f94e5d.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rearServer/src/main/resources/static/css/673.d935196a.css

This file was deleted.

2 changes: 1 addition & 1 deletion rearServer/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Welcome to PandoraNext-TokensTool</title><script defer="defer" src="js/chunk-vendors.612ab552.js"></script><script defer="defer" src="js/app.f4a0ed5a.js"></script><link href="css/chunk-vendors.8a308144.css" rel="stylesheet"></head><body><div id="app"></div></body></html>
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Welcome to PandoraNext-TokensTool</title><script defer="defer" src="js/chunk-vendors.612ab552.js"></script><script defer="defer" src="js/app.8554aeb1.js"></script><link href="css/chunk-vendors.8a308144.css" rel="stylesheet"></head><body><div id="app"></div></body></html>
2 changes: 2 additions & 0 deletions rearServer/src/main/resources/static/js/19.3ae9a73d.js
1 change: 1 addition & 0 deletions rearServer/src/main/resources/static/js/19.3ae9a73d.js.map
2 changes: 2 additions & 0 deletions rearServer/src/main/resources/static/js/237.72660b35.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions rearServer/src/main/resources/static/js/378.ae561728.js

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions rearServer/src/main/resources/static/js/673.f867f655.js

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions rearServer/src/main/resources/static/js/86.84ae0fd7.js

This file was deleted.

1 change: 0 additions & 1 deletion rearServer/src/main/resources/static/js/86.84ae0fd7.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions rearServer/src/main/resources/static/js/888.e76ae9e7.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions rearServer/src/main/resources/static/js/app.8554aeb1.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions rearServer/src/main/resources/static/js/app.f4a0ed5a.js

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions rearServer/target/classes/static/css/19.39f94e5d.css
1 change: 0 additions & 1 deletion rearServer/target/classes/static/css/673.d935196a.css

This file was deleted.

Loading

0 comments on commit fad0096

Please sign in to comment.