custom mode switch

This commit is contained in:
Archeb
2024-06-02 02:24:58 +08:00
parent 9a81ee8fee
commit 185d887954
3 changed files with 33 additions and 22 deletions
+7 -1
View File
@@ -91,6 +91,7 @@ app.post("/v1/messages", apiKeyAuth, (req, res) => {
});
var proxyModel = process.env.AI_MODEL || "claude_3_opus";
// 检查该session是否已经创建对应模型的对应user chat mode
if(process.env.USE_CUSTOM_MODE == "true") {
if (session.user_chat_mode_id && session.user_chat_mode_id[proxyModel]) {
console.log("Using existing user chat mode");
} else {
@@ -113,11 +114,16 @@ app.post("/v1/messages", apiKeyAuth, (req, res) => {
fs.writeFileSync("./config.js", "module.exports = " + JSON.stringify(config, null, 4));
}
var userChatModeId = session?.user_chat_mode_id?.[proxyModel] ? session.user_chat_mode_id[proxyModel] : "custom";
}else{
console.log("Custom mode is disabled, using default mode.");
var userChatModeId = "custom";
}
// 试算用户消息长度
if(encodeURIComponent(JSON.stringify(userMessage)).length + encodeURIComponent(userQuery).length > 32000) {
//太长了,需要上传
console.log("User message too long, uploading to server.")
// user message to plaintext
let previousMessages = jsonBody.messages
.map((msg) => {
+1
View File
@@ -3,5 +3,6 @@ set PASSWORD=
set https_proxy=
set PORT=8080
set AI_MODEL=claude_3_opus
set USE_CUSTOM_MODE=false
node index
pause
+4
View File
@@ -39,6 +39,8 @@ module.exports = {
(可选)如果需要,可以修改使用的模型。但是仍然建议使用opus,因为其他未经测试。
(可选)如果需要,可以启用自定义会话模式(`USE_CUSTOM_MODE`设置为`true`)。可以缩短原系统消息长度、禁用联网、减缓等待时间,可能有助于破限。但有可能导致更容易出现 unusual query volume。
8. 启动 start.bat
9. 酒馆中选择 Claude,反向代理地址填 http://127.0.0.1:8080/v1 **反代密码必须填, 同时打开流式传输**,随便什么都可以(除非你在第7步设置了PASSWORD)。
@@ -120,6 +122,8 @@ module.exports = {
(Optional) You may change the model to use, but only claude_3_opus is tested.
(Optional) You may turn on the custom chat mode by setting `USE_CUSTOM_MODE` env to `true`
8. Start start.bat
9. Select Claude in the Tavern and put http://127.0.0.1:8080/v1 as the address of the reverse proxy. **Use any random string for password, also turn on Streaming** (unless you set PASSWORD in step 7).