big fixes

This commit is contained in:
Archeb
2024-06-05 02:34:13 +08:00
parent 185d887954
commit 8cf1304b5b
+12 -10
View File
@@ -123,16 +123,17 @@ app.post("/v1/messages", apiKeyAuth, (req, res) => {
// 试算用户消息长度
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) => {
return msg.content
})
.join("\n\n");
console.log("Using file upload mode");
// 试算最新一条human消息长度
if(encodeURIComponent(userQuery).length > 30000) userQuery = "Please view the document and reply.";
if (encodeURIComponent(userQuery).length > 30000) {
userQuery = "Please view the document and reply.";
}else{
// 删除最新一条human消息中的question
userMessage[userMessage.length - 1].question = "";
}
// user message to plaintext
let previousMessages = userMessage.map((msg) => msg.question + "\n" + msg.answer).join("\n");
userMessage = [];
// GET https://you.com/api/get_nonce to get nonce
@@ -245,7 +246,7 @@ app.post("/v1/messages", apiKeyAuth, (req, res) => {
}
try {
if (chunk.indexOf("event: youChatToken\n") != -1) {
if (chunk.indexOf("event: youChatToken\n") != -1 || chunk.indexOf(`data: {"youChatToken`) != -1) {
chunk.split("\n").forEach((line) => {
if (line.startsWith(`data: {"youChatToken"`)) {
let data = line.substring(6);
@@ -336,6 +337,7 @@ app.listen(port, () => {
if (!validApiKey) {
console.log(`Proxy is currently running with no authentication`)
}
console.log(`API Format: Anthropic; Custom mode: ${process.env.USE_CUSTOM_MODE == "true" ? "enabled" : "disabled"}`);
});
function apiKeyAuth(req, res, next) {