Spaces:
Paused
Paused
muxi feng
commited on
Commit
·
23796a3
1
Parent(s):
152ad49
修复模型错误
Browse files- app/requests.ts +59 -68
app/requests.ts
CHANGED
|
@@ -245,7 +245,7 @@ export async function requestChatStream(
|
|
| 245 |
if (Bot == "Lemur"){
|
| 246 |
const req = makeRevChatRequestParam(messages);
|
| 247 |
|
| 248 |
-
chatMessage(
|
| 249 |
console.log("[Request] ", req);
|
| 250 |
|
| 251 |
const controller = new AbortController();
|
|
@@ -319,7 +319,7 @@ export async function requestChatStream(
|
|
| 319 |
overrideModel: options?.overrideModel,
|
| 320 |
});
|
| 321 |
|
| 322 |
-
chatMessage(
|
| 323 |
console.log("[Request] ", req);
|
| 324 |
|
| 325 |
const controller = new AbortController();
|
|
@@ -516,76 +516,67 @@ export async function requestChatStream(
|
|
| 516 |
options?.onMessage("请换一个问题试试吧", true);
|
| 517 |
}
|
| 518 |
}else{
|
| 519 |
-
const req =
|
| 520 |
-
stream: true,
|
| 521 |
-
overrideModel: options?.overrideModel,
|
| 522 |
-
});
|
| 523 |
-
|
| 524 |
-
chatMessage(JSON.stringify(req.messages),"文字","user")
|
| 525 |
-
console.log("[Request] ", req);
|
| 526 |
-
|
| 527 |
-
const controller = new AbortController();
|
| 528 |
-
const reqTimeoutId = setTimeout(() => controller.abort(), TIME_OUT_MS);
|
| 529 |
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
|
|
|
| 575 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
}
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
options?.onError(new Error("Unauthorized"), res.status);
|
| 581 |
-
} else {
|
| 582 |
-
console.error("Stream Error", res.body);
|
| 583 |
-
options?.onError(new Error("Stream Error"), res.status);
|
| 584 |
}
|
| 585 |
-
} catch (err) {
|
| 586 |
-
console.error("NetWork Error", err);
|
| 587 |
-
options?.onError(err as Error);
|
| 588 |
-
}
|
| 589 |
}
|
| 590 |
}
|
| 591 |
|
|
|
|
| 245 |
if (Bot == "Lemur"){
|
| 246 |
const req = makeRevChatRequestParam(messages);
|
| 247 |
|
| 248 |
+
chatMessage(messages[messages.length - 1].content,"文字","user")
|
| 249 |
console.log("[Request] ", req);
|
| 250 |
|
| 251 |
const controller = new AbortController();
|
|
|
|
| 319 |
overrideModel: options?.overrideModel,
|
| 320 |
});
|
| 321 |
|
| 322 |
+
chatMessage(messages[messages.length - 1].content,"文字","user")
|
| 323 |
console.log("[Request] ", req);
|
| 324 |
|
| 325 |
const controller = new AbortController();
|
|
|
|
| 516 |
options?.onMessage("请换一个问题试试吧", true);
|
| 517 |
}
|
| 518 |
}else{
|
| 519 |
+
const req = makeRevChatRequestParam(messages);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
|
| 521 |
+
chatMessage(messages[messages.length - 1].content,"文字","user")
|
| 522 |
+
console.log("[Request] ", req);
|
| 523 |
+
|
| 524 |
+
const controller = new AbortController();
|
| 525 |
+
const reqTimeoutId = setTimeout(() => controller.abort(), TIME_OUT_MS);
|
| 526 |
+
|
| 527 |
+
try {
|
| 528 |
+
const res = await fetch("/api/lemur", {
|
| 529 |
+
method: "POST",
|
| 530 |
+
headers: {
|
| 531 |
+
"Content-Type": "application/json",
|
| 532 |
+
...getHeaders(),
|
| 533 |
+
},
|
| 534 |
+
body: JSON.stringify(req),
|
| 535 |
+
signal: controller.signal,
|
| 536 |
+
});
|
| 537 |
+
clearTimeout(reqTimeoutId);
|
| 538 |
+
|
| 539 |
+
let responseText = "";
|
| 540 |
+
|
| 541 |
+
const finish = () => {
|
| 542 |
+
options?.onMessage(responseText, true);
|
| 543 |
+
controller.abort();
|
| 544 |
+
chatMessage(responseText,"文字","system")
|
| 545 |
+
};
|
| 546 |
+
|
| 547 |
+
if (res.ok) {
|
| 548 |
+
const reader = res.body?.getReader();
|
| 549 |
+
const decoder = new TextDecoder();
|
| 550 |
+
|
| 551 |
+
options?.onController?.(controller);
|
| 552 |
+
|
| 553 |
+
while (true) {
|
| 554 |
+
// handle time out, will stop if no response in 10 secs
|
| 555 |
+
const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS);
|
| 556 |
+
const content = await reader?.read();
|
| 557 |
+
clearTimeout(resTimeoutId);
|
| 558 |
+
const text = decoder.decode(content?.value);
|
| 559 |
+
responseText += text;
|
| 560 |
+
|
| 561 |
+
const done = !content || content.done;
|
| 562 |
+
options?.onMessage(responseText, false);
|
| 563 |
+
|
| 564 |
+
if (done) {
|
| 565 |
+
break;
|
| 566 |
+
}
|
| 567 |
}
|
| 568 |
+
finish();
|
| 569 |
+
} else if (res.status === 401) {
|
| 570 |
+
console.error("Unauthorized");
|
| 571 |
+
options?.onError(new Error("Unauthorized"), res.status);
|
| 572 |
+
} else {
|
| 573 |
+
console.error("Stream Error", res.body);
|
| 574 |
+
options?.onError(new Error("Stream Error"), res.status);
|
| 575 |
}
|
| 576 |
+
} catch (err) {
|
| 577 |
+
console.error("NetWork Error", err);
|
| 578 |
+
options?.onError(err as Error);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
}
|
| 581 |
}
|
| 582 |
|