From e88eb48a1e467d57483313cc5b6cfd0b7604653e Mon Sep 17 00:00:00 2001 From: kwaroran Date: Tue, 16 May 2023 03:58:42 +0900 Subject: [PATCH] [feat] supaMemory modified --- src-tauri/tauri.conf.json | 2 +- src/ts/database.ts | 2 +- src/ts/process/supaMemory.ts | 58 +++++++++++++++++++++++------------- version.json | 2 +- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 33b965d2..5dfc673f 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "RisuAI", - "version": "0.9.4" + "version": "0.9.5" }, "tauri": { "allowlist": { diff --git a/src/ts/database.ts b/src/ts/database.ts index a82a2736..c5e41cbc 100644 --- a/src/ts/database.ts +++ b/src/ts/database.ts @@ -7,7 +7,7 @@ import { cloneDeep } from 'lodash'; export const DataBase = writable({} as any as Database) export const loadedStore = writable(false) -export let appVer = '0.9.4' +export let appVer = '0.9.5' export function setDatabase(data:Database){ diff --git a/src/ts/process/supaMemory.ts b/src/ts/process/supaMemory.ts index 7787f56f..cf48284a 100644 --- a/src/ts/process/supaMemory.ts +++ b/src/ts/process/supaMemory.ts @@ -87,35 +87,53 @@ export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxCont chunkSize += tokens } - const promptbody:OpenAIChat[] = [ - { - role: "user", - content: stringlizedChat - }, - { - role: "system", - content: db.supaMemoryPrompt === '' ? - "[Summarize the ongoing role story. It must also remove redundancy and unnecessary content from the prompt so that gpt3 and other sublanguage models]\n" - : db.supaMemoryPrompt - } - ] + const supaPrompt = db.supaMemoryPrompt === '' ? + "[Summarize the ongoing role story. It must also remove redundancy and unnecessary content from the prompt so that gpt3 and other sublanguage models]\n" + : db.supaMemoryPrompt - const da = await requestChatData({ - formated: promptbody, - bias: {} - }, 'submodel') + const promptbody = stringlizedChat + '\n\n' + supaPrompt + "\n\nOutput:" - if(da.type === 'fail'){ + const da = await fetch("https://api.openai.com/v1/completions",{ + headers: { + "Content-Type": "application/json", + "Authorization": "Bearer " + db.openAIKey + }, + method: "POST", + body: JSON.stringify({ + "model": "text-davinci-003", + "prompt": promptbody, + "max_tokens": 500, + "temperature": 0 + }) + }) + + // const promptbody:OpenAIChat[] = [ + // { + // role: "user", + // content: stringlizedChat + // }, + // { + // role: "system", + // content: supaPrompt + // } + // ] + // const da = await requestChatData({ + // formated: promptbody, + // bias: {} + // }, 'submodel') + + const result = (await da.json()).choices[0].text.trim() + if(da.status < 200 || da.status >= 300){ return { currentTokens: currentTokens, chats: chats, - error: "SupaMemory: HTTP: " + da.result + error: "SupaMemory: HTTP: " + await da.text() } } - const tokenz = await tokenize(da.result + '\n\n') + 5 + const tokenz = await tokenize(result + '\n\n') + 5 currentTokens += tokenz - supaMemory += da.result + '\n\n' + supaMemory += result + '\n\n' console.log(tokenz) } diff --git a/version.json b/version.json index 8ad6494a..53da5d66 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version":"0.9.4"} \ No newline at end of file +{"version":"0.9.5"} \ No newline at end of file