[feat] added streaming partly
This commit is contained in:
@@ -247,5 +247,6 @@ export const languageEnglish = {
|
||||
SuperMemory:"SupaMemory",
|
||||
useExperimental: "Able Experimental Features",
|
||||
showMemoryLimit: "Show Memory Limit",
|
||||
roundIcons: "Round Icons"
|
||||
roundIcons: "Round Icons",
|
||||
useStreaming: "Use Streaming"
|
||||
}
|
||||
|
||||
@@ -407,6 +407,7 @@ export interface Database{
|
||||
useExperimental:boolean
|
||||
showMemoryLimit:boolean
|
||||
roundIcons:boolean
|
||||
useStreaming:boolean
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -337,6 +337,9 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
||||
if(req.type === 'fail'){
|
||||
alertError(req.result)
|
||||
return false
|
||||
}
|
||||
else if(req.type === 'streaming'){
|
||||
|
||||
}
|
||||
else{
|
||||
const result2 = processScriptFull(currentChar, reformatContent(req.result), 'editoutput')
|
||||
@@ -429,8 +432,8 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
||||
maxTokens: 30,
|
||||
}, 'submodel')
|
||||
|
||||
if(rq.type === 'fail'){
|
||||
alertError(rq.result)
|
||||
if(rq.type === 'fail' || rq.type === 'streaming'){
|
||||
alertError(`${rq.result}`)
|
||||
return true
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -80,8 +80,8 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
}, 'submodel')
|
||||
|
||||
|
||||
if(rq.type === 'fail'){
|
||||
alertError(rq.result)
|
||||
if(rq.type === 'fail' || rq.type === 'streaming'){
|
||||
alertError(`${rq.result}`)
|
||||
return false
|
||||
}
|
||||
else{
|
||||
|
||||
Reference in New Issue
Block a user