big fixes
This commit is contained in:
@@ -123,16 +123,17 @@ app.post("/v1/messages", apiKeyAuth, (req, res) => {
|
|||||||
// 试算用户消息长度
|
// 试算用户消息长度
|
||||||
if(encodeURIComponent(JSON.stringify(userMessage)).length + encodeURIComponent(userQuery).length > 32000) {
|
if(encodeURIComponent(JSON.stringify(userMessage)).length + encodeURIComponent(userQuery).length > 32000) {
|
||||||
//太长了,需要上传
|
//太长了,需要上传
|
||||||
console.log("User message too long, uploading to server.")
|
console.log("Using file upload mode");
|
||||||
// user message to plaintext
|
|
||||||
let previousMessages = jsonBody.messages
|
|
||||||
.map((msg) => {
|
|
||||||
return msg.content
|
|
||||||
})
|
|
||||||
.join("\n\n");
|
|
||||||
|
|
||||||
// 试算最新一条human消息长度
|
// 试算最新一条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 = [];
|
userMessage = [];
|
||||||
|
|
||||||
// GET https://you.com/api/get_nonce to get nonce
|
// GET https://you.com/api/get_nonce to get nonce
|
||||||
@@ -245,7 +246,7 @@ app.post("/v1/messages", apiKeyAuth, (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) => {
|
chunk.split("\n").forEach((line) => {
|
||||||
if (line.startsWith(`data: {"youChatToken"`)) {
|
if (line.startsWith(`data: {"youChatToken"`)) {
|
||||||
let data = line.substring(6);
|
let data = line.substring(6);
|
||||||
@@ -336,6 +337,7 @@ app.listen(port, () => {
|
|||||||
if (!validApiKey) {
|
if (!validApiKey) {
|
||||||
console.log(`Proxy is currently running with no authentication`)
|
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) {
|
function apiKeyAuth(req, res, next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user