[feat] added streaming partly

This commit is contained in:
kwaroran
2023-05-17 03:11:34 +09:00
parent 502ffa7314
commit 7ea4945088
5 changed files with 29 additions and 5 deletions

View File

@@ -19,6 +19,9 @@ interface requestDataArgument{
type requestDataResponse = {
type: 'success'|'fail'
result: string
}|{
type: "streaming",
result: ReadableStreamDefaultReader<Uint8Array>
}
export async function requestChatData(arg:requestDataArgument, model:'model'|'submodel'):Promise<requestDataResponse> {
@@ -68,6 +71,22 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
replacerURL += 'chat/completions'
}
if(db.useStreaming){
const da = await fetch(replacerURL, {
body: JSON.stringify(body),
headers: {
"Authorization": "Bearer " + db.openAIKey
},
})
const reader = da.body.getReader()
return {
type: 'streaming',
result: reader
}
}
const res = await globalFetch(replacerURL, {
body: body,
headers: {