fix: #289 #367 #353 #369 provide more error message info

This commit is contained in:
Yifei Zhang
2023-04-02 19:14:53 +00:00
parent 8d60a414f0
commit b44caeeefb
5 changed files with 25 additions and 6 deletions

View File

@@ -8,6 +8,15 @@ async function createStream(req: NextRequest) {
const res = await requestOpenai(req);
const contentType = res.headers.get("Content-Type") ?? "";
if (!contentType.includes("stream")) {
const content = await (
await res.text()
).replace(/provided:.*. You/, "provided: ***. You");
console.log("[Stream] error ", content);
return "```json\n" + content + "```";
}
const stream = new ReadableStream({
async start(controller) {
function onParse(event: any) {