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