Add native rust streamed fetch implementation

This commit is contained in:
kwaroran
2024-03-06 21:49:32 +09:00
parent 0117fab49c
commit 826eac60d1
5 changed files with 410 additions and 22 deletions

View File

@@ -4,7 +4,7 @@ import { DataBase, setDatabase, type character } from "../storage/database";
import { pluginProcess } from "../plugins/plugins";
import { language } from "../../lang";
import { stringlizeAINChat, stringlizeChat, stringlizeChatOba, getStopStrings, unstringlizeAIN, unstringlizeChat } from "./stringlize";
import { addFetchLog, globalFetch, isNodeServer, isTauri } from "../storage/globalApi";
import { addFetchLog, fetchNative, globalFetch, isNodeServer, isTauri, textifyReadableStream } from "../storage/globalApi";
import { sleep } from "../util";
import { createDeep } from "./deepai";
import { hubURL } from "../characterCards";
@@ -526,36 +526,24 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
}
}
}
const da = (throughProxi)
? await fetch(hubURL + `/proxy2`, {
body: JSON.stringify(body),
headers: {
"risu-header": encodeURIComponent(JSON.stringify(headers)),
"risu-url": encodeURIComponent(replacerURL),
"Content-Type": "application/json",
"x-risu-tk": "use"
},
method: "POST",
signal: abortSignal
})
: await fetch(replacerURL, {
body: JSON.stringify(body),
method: "POST",
headers: headers,
signal: abortSignal
})
const da = await fetchNative(replacerURL, {
body: JSON.stringify(body),
method: "POST",
headers: headers,
signal: abortSignal
})
if(da.status !== 200){
return {
type: "fail",
result: await da.text()
result: await textifyReadableStream(da.body)
}
}
if (!da.headers.get('Content-Type').includes('text/event-stream')){
return {
type: "fail",
result: await da.text()
result: await textifyReadableStream(da.body)
}
}