Update to 1.10.0 (#65)
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "RisuAI",
|
"productName": "RisuAI",
|
||||||
"version": "0.9.6"
|
"version": "1.10.0"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
|
|||||||
@@ -245,5 +245,8 @@ export const languageEnglish = {
|
|||||||
Speech: "Speech",
|
Speech: "Speech",
|
||||||
ToggleSuperMemory: "Toggle SupaMemory",
|
ToggleSuperMemory: "Toggle SupaMemory",
|
||||||
SuperMemory:"SupaMemory",
|
SuperMemory:"SupaMemory",
|
||||||
useExperimental: "Able Experimental Features"
|
useExperimental: "Able Experimental Features",
|
||||||
|
showMemoryLimit: "Show Memory Limit",
|
||||||
|
roundIcons: "Round Icons",
|
||||||
|
useStreaming: "Use Streaming"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
import { replacePlaceholders } from "../../ts/util";
|
import { replacePlaceholders } from "../../ts/util";
|
||||||
export let message = ''
|
export let message = ''
|
||||||
export let name = ''
|
export let name = ''
|
||||||
|
export let isLastMemory:boolean
|
||||||
export let img:string|Promise<string> = ''
|
export let img:string|Promise<string> = ''
|
||||||
export let idx = -1
|
export let idx = -1
|
||||||
export let rerollIcon = false
|
export let rerollIcon = false
|
||||||
@@ -61,12 +62,14 @@
|
|||||||
|
|
||||||
$: displaya(message)
|
$: displaya(message)
|
||||||
</script>
|
</script>
|
||||||
<div class="flex max-w-full">
|
<div class="flex max-w-full justify-center" class:bgc={isLastMemory}>
|
||||||
<div class="text-neutral-200 mt-2 p-2 bg-transparent flex-grow ml-4 mr-4 border-t-gray-900 border-opacity-30 border-transparent flexium items-start">
|
<div class="text-neutral-200 mt-1 mb-1 p-2 bg-transparent flex-grow ml-4 mr-4 border-t-gray-900 border-opacity-30 border-transparent flexium items-start">
|
||||||
{#await img}
|
{#await img}
|
||||||
<div class="rounded-md shadow-lg bg-gray-500 mt-2" style={`height:${$DataBase.iconsize * 3.5 / 100}rem;width:${$DataBase.iconsize * 3.5 / 100}rem`} />
|
<div class="shadow-lg bg-gray-500 mt-2" style={`height:${$DataBase.iconsize * 3.5 / 100}rem;width:${$DataBase.iconsize * 3.5 / 100}rem`}
|
||||||
|
class:rounded-md={!$DataBase.roundIcons} class:rounded-full={$DataBase.roundIcons} />
|
||||||
{:then m}
|
{:then m}
|
||||||
<div class="rounded-md shadow-lg bg-gray-500 mt-2" style={m + `height:${$DataBase.iconsize * 3.5 / 100}rem;width:${$DataBase.iconsize * 3.5 / 100}rem`} />
|
<div class="shadow-lg bg-gray-500 mt-2" style={m + `height:${$DataBase.iconsize * 3.5 / 100}rem;width:${$DataBase.iconsize * 3.5 / 100}rem`}
|
||||||
|
class:rounded-md={!$DataBase.roundIcons} class:rounded-full={$DataBase.roundIcons} />
|
||||||
{/await}
|
{/await}
|
||||||
<span class="flex flex-col ml-4 w-full">
|
<span class="flex flex-col ml-4 w-full">
|
||||||
<div class="flexium items-center chat">
|
<div class="flexium items-center chat">
|
||||||
@@ -142,7 +145,7 @@
|
|||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
.chat{
|
.chat{
|
||||||
max-width: calc(95% - 0.5rem);
|
max-width: calc(100% - 0.5rem);
|
||||||
word-break: normal;
|
word-break: normal;
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,6 +246,7 @@
|
|||||||
rerollIcon={i === 0}
|
rerollIcon={i === 0}
|
||||||
onReroll={reroll}
|
onReroll={reroll}
|
||||||
unReroll={unReroll}
|
unReroll={unReroll}
|
||||||
|
isLastMemory={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<Chat
|
<Chat
|
||||||
@@ -256,6 +257,7 @@
|
|||||||
onReroll={reroll}
|
onReroll={reroll}
|
||||||
unReroll={unReroll}
|
unReroll={unReroll}
|
||||||
img={getCharImage(findCharacterbyId(chat.saying).image, 'css')}
|
img={getCharImage(findCharacterbyId(chat.saying).image, 'css')}
|
||||||
|
isLastMemory={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
@@ -264,6 +266,7 @@
|
|||||||
name={$DataBase.username}
|
name={$DataBase.username}
|
||||||
message={chat.data}
|
message={chat.data}
|
||||||
img={getCharImage($DataBase.userIcon, 'css')}
|
img={getCharImage($DataBase.userIcon, 'css')}
|
||||||
|
isLastMemory={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
@@ -300,6 +303,8 @@
|
|||||||
}
|
}
|
||||||
$DataBase.characters[$selectedCharID] = cha
|
$DataBase.characters[$selectedCharID] = cha
|
||||||
}}
|
}}
|
||||||
|
isLastMemory={false}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
{#if !$DataBase.characters[$selectedCharID].removedQuotes && $DataBase.characters[$selectedCharID].creatorNotes.length >= 2}
|
{#if !$DataBase.characters[$selectedCharID].removedQuotes && $DataBase.characters[$selectedCharID].creatorNotes.length >= 2}
|
||||||
<CreatorQuote quote={$DataBase.characters[$selectedCharID].creatorNotes} onRemove={() => {
|
<CreatorQuote quote={$DataBase.characters[$selectedCharID].creatorNotes} onRemove={() => {
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
<option value="gpt35" class="bg-darkbg appearance-none">OpenAI GPT-3.5</option>
|
<option value="gpt35" class="bg-darkbg appearance-none">OpenAI GPT-3.5</option>
|
||||||
<option value="gpt4" class="bg-darkbg appearance-none">OpenAI GPT-4</option>
|
<option value="gpt4" class="bg-darkbg appearance-none">OpenAI GPT-4</option>
|
||||||
<option value="textgen_webui" class="bg-darkbg appearance-none">Text Generation WebUI</option>
|
<option value="textgen_webui" class="bg-darkbg appearance-none">Text Generation WebUI</option>
|
||||||
|
<option value="palm2" class="bg-darkbg appearance-none">Google Palm2</option>
|
||||||
{#if $DataBase.plugins.length > 0}
|
{#if $DataBase.plugins.length > 0}
|
||||||
<option value="custom" class="bg-darkbg appearance-none">Plugin</option>
|
<option value="custom" class="bg-darkbg appearance-none">Plugin</option>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -107,12 +108,17 @@
|
|||||||
<select class="bg-transparent input-text mt-2 mb-4 text-gray-200 appearance-none text-sm" bind:value={$DataBase.subModel}>
|
<select class="bg-transparent input-text mt-2 mb-4 text-gray-200 appearance-none text-sm" bind:value={$DataBase.subModel}>
|
||||||
<option value="gpt35" class="bg-darkbg appearance-none">OpenAI GPT-3.5</option>
|
<option value="gpt35" class="bg-darkbg appearance-none">OpenAI GPT-3.5</option>
|
||||||
<option value="gpt4" class="bg-darkbg appearance-none">OpenAI GPT-4</option>
|
<option value="gpt4" class="bg-darkbg appearance-none">OpenAI GPT-4</option>
|
||||||
|
<option value="palm2" class="bg-darkbg appearance-none">Google Palm2</option>
|
||||||
<option value="textgen_webui" class="bg-darkbg appearance-none">Text Generation WebUI</option>
|
<option value="textgen_webui" class="bg-darkbg appearance-none">Text Generation WebUI</option>
|
||||||
{#if $customProviderStore.length > 0}
|
{#if $customProviderStore.length > 0}
|
||||||
<option value="custom" class="bg-darkbg appearance-none">Plugin</option>
|
<option value="custom" class="bg-darkbg appearance-none">Plugin</option>
|
||||||
{/if}
|
{/if}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
{#if $DataBase.aiModel === 'palm2' || $DataBase.subModel === 'palm2'}
|
||||||
|
<span class="text-neutral-200">Palm2 {language.apiKey}</span>
|
||||||
|
<input class="text-neutral-200 mb-4 p-2 bg-transparent input-text focus:bg-selected text-sm" placeholder="..." bind:value={$DataBase.palmAPI}>
|
||||||
|
{/if}
|
||||||
{#if $DataBase.aiModel === 'gpt35' || $DataBase.aiModel === 'gpt4' || $DataBase.subModel === 'gpt4' || $DataBase.subModel === 'gpt35'}
|
{#if $DataBase.aiModel === 'gpt35' || $DataBase.aiModel === 'gpt4' || $DataBase.subModel === 'gpt4' || $DataBase.subModel === 'gpt35'}
|
||||||
<span class="text-neutral-200">OpenAI {language.apiKey} <Help key="oaiapikey"/></span>
|
<span class="text-neutral-200">OpenAI {language.apiKey} <Help key="oaiapikey"/></span>
|
||||||
<input class="text-neutral-200 mb-4 p-2 bg-transparent input-text focus:bg-selected text-sm" placeholder="sk-XXXXXXXXXXXXXXXXXXXX" bind:value={$DataBase.openAIKey}>
|
<input class="text-neutral-200 mb-4 p-2 bg-transparent input-text focus:bg-selected text-sm" placeholder="sk-XXXXXXXXXXXXXXXXXXXX" bind:value={$DataBase.openAIKey}>
|
||||||
@@ -363,6 +369,11 @@
|
|||||||
<span>{language.fullscreen}</span>
|
<span>{language.fullscreen}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center mt-2">
|
||||||
|
<Check bind:check={$DataBase.showMemoryLimit}/>
|
||||||
|
<span>{language.showMemoryLimit}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center mt-2">
|
<div class="flex items-center mt-2">
|
||||||
<Check check={$DataBase.customBackground !== ''} onChange={async (check) => {
|
<Check check={$DataBase.customBackground !== ''} onChange={async (check) => {
|
||||||
if(check){
|
if(check){
|
||||||
@@ -392,6 +403,11 @@
|
|||||||
<span>{language.SwipeRegenerate}</span>
|
<span>{language.SwipeRegenerate}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center mt-2">
|
||||||
|
<Check bind:check={$DataBase.roundIcons}/>
|
||||||
|
<span>{language.roundIcons}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center mt-2">
|
<div class="flex items-center mt-2">
|
||||||
<Check bind:check={$DataBase.instantRemove}/>
|
<Check bind:check={$DataBase.instantRemove}/>
|
||||||
<span>{language.instantRemove}</span>
|
<span>{language.instantRemove}</span>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { DataBase } from "src/ts/database";
|
||||||
|
|
||||||
export let src:string|Promise<string>;
|
export let src:string|Promise<string>;
|
||||||
export let size = "22";
|
export let size = "22";
|
||||||
</script>
|
</script>
|
||||||
@@ -11,6 +13,7 @@
|
|||||||
style:width={size + "px"}
|
style:width={size + "px"}
|
||||||
style:height={size + "px"}
|
style:height={size + "px"}
|
||||||
style:minWidth={size + "px"}
|
style:minWidth={size + "px"}
|
||||||
|
class:rounded-md={!$DataBase.roundIcons} class:rounded-full={$DataBase.roundIcons}
|
||||||
/>
|
/>
|
||||||
{:then img}
|
{:then img}
|
||||||
<img
|
<img
|
||||||
@@ -19,6 +22,7 @@
|
|||||||
style:width={size + "px"}
|
style:width={size + "px"}
|
||||||
style:height={size + "px"}
|
style:height={size + "px"}
|
||||||
style:minWidth={size + "px"}
|
style:minWidth={size + "px"}
|
||||||
|
class:rounded-md={!$DataBase.roundIcons} class:rounded-full={$DataBase.roundIcons}
|
||||||
alt="avatar"
|
alt="avatar"
|
||||||
/>
|
/>
|
||||||
{/await}
|
{/await}
|
||||||
@@ -28,6 +32,7 @@
|
|||||||
style:width={size + "px"}
|
style:width={size + "px"}
|
||||||
style:height={size + "px"}
|
style:height={size + "px"}
|
||||||
style:minWidth={size + "px"}
|
style:minWidth={size + "px"}
|
||||||
|
class:rounded-md={!$DataBase.roundIcons} class:rounded-full={$DataBase.roundIcons}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -108,3 +108,7 @@ html, body{
|
|||||||
outline: 0;
|
outline: 0;
|
||||||
border-bottom: 1px solid #6272a4;
|
border-bottom: 1px solid #6272a4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bgc{
|
||||||
|
border-top: 1px solid rgba(98, 114, 164, 0.3);
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import { cloneDeep } from 'lodash';
|
|||||||
|
|
||||||
export const DataBase = writable({} as any as Database)
|
export const DataBase = writable({} as any as Database)
|
||||||
export const loadedStore = writable(false)
|
export const loadedStore = writable(false)
|
||||||
export let appVer = '0.9.6'
|
export let appVer = '1.10.0'
|
||||||
|
|
||||||
|
|
||||||
export function setDatabase(data:Database){
|
export function setDatabase(data:Database){
|
||||||
@@ -80,6 +80,9 @@ export function setDatabase(data:Database){
|
|||||||
if(checkNullish(data.language)){
|
if(checkNullish(data.language)){
|
||||||
data.language = 'en'
|
data.language = 'en'
|
||||||
}
|
}
|
||||||
|
if(checkNullish(data.swipe)){
|
||||||
|
data.swipe = true
|
||||||
|
}
|
||||||
if(checkNullish(data.translator)){
|
if(checkNullish(data.translator)){
|
||||||
data.translator = ''
|
data.translator = ''
|
||||||
}
|
}
|
||||||
@@ -187,6 +190,9 @@ export function setDatabase(data:Database){
|
|||||||
if(checkNullish(data.supaMemoryPrompt)){
|
if(checkNullish(data.supaMemoryPrompt)){
|
||||||
data.supaMemoryPrompt = ''
|
data.supaMemoryPrompt = ''
|
||||||
}
|
}
|
||||||
|
if(checkNullish(data.showMemoryLimit)){
|
||||||
|
data.showMemoryLimit = false
|
||||||
|
}
|
||||||
if(checkNullish(data.sdConfig)){
|
if(checkNullish(data.sdConfig)){
|
||||||
data.sdConfig = {
|
data.sdConfig = {
|
||||||
width:512,
|
width:512,
|
||||||
@@ -399,6 +405,10 @@ export interface Database{
|
|||||||
showUnrecommended:boolean
|
showUnrecommended:boolean
|
||||||
elevenLabKey:string
|
elevenLabKey:string
|
||||||
useExperimental:boolean
|
useExperimental:boolean
|
||||||
|
showMemoryLimit:boolean
|
||||||
|
roundIcons:boolean
|
||||||
|
useStreaming:boolean
|
||||||
|
palmAPI:string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -422,6 +432,7 @@ export interface Chat{
|
|||||||
localLore: loreBook[]
|
localLore: loreBook[]
|
||||||
sdData?:string
|
sdData?:string
|
||||||
supaMemoryData?:string
|
supaMemoryData?:string
|
||||||
|
lastMemory?:string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Message{
|
export interface Message{
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
|||||||
chats = sp.chats
|
chats = sp.chats
|
||||||
currentTokens = sp.currentTokens
|
currentTokens = sp.currentTokens
|
||||||
currentChat.supaMemoryData = sp.memory ?? currentChat.supaMemoryData
|
currentChat.supaMemoryData = sp.memory ?? currentChat.supaMemoryData
|
||||||
|
currentChat.lastMemory = sp.lastId ?? currentChat.lastMemory
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
while(currentTokens > maxContextTokens){
|
while(currentTokens > maxContextTokens){
|
||||||
@@ -250,6 +251,8 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
|||||||
currentTokens -= (await tokenize(chats[0].content) + 1)
|
currentTokens -= (await tokenize(chats[0].content) + 1)
|
||||||
chats.splice(0, 1)
|
chats.splice(0, 1)
|
||||||
}
|
}
|
||||||
|
currentChat.lastMemory = chats[0].memo
|
||||||
|
console.log(currentChat.lastMemory)
|
||||||
}
|
}
|
||||||
let bias:{[key:number]:number} = {}
|
let bias:{[key:number]:number} = {}
|
||||||
|
|
||||||
@@ -334,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')
|
||||||
@@ -426,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: {
|
||||||
@@ -233,6 +252,78 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case 'palm2':{
|
||||||
|
const body = {
|
||||||
|
"prompt": {
|
||||||
|
"text": stringlizeChat(formated, currentChar?.name ?? '')
|
||||||
|
},
|
||||||
|
"safetySettings":[
|
||||||
|
{
|
||||||
|
"category": "HARM_CATEGORY_UNSPECIFIED",
|
||||||
|
"threshold": "BLOCK_NONE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"category": "HARM_CATEGORY_DEROGATORY",
|
||||||
|
"threshold": "BLOCK_NONE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"category": "HARM_CATEGORY_TOXICITY",
|
||||||
|
"threshold": "BLOCK_NONE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"category": "HARM_CATEGORY_VIOLENCE",
|
||||||
|
"threshold": "BLOCK_NONE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"category": "HARM_CATEGORY_SEXUAL",
|
||||||
|
"threshold": "BLOCK_NONE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"category": "HARM_CATEGORY_MEDICAL",
|
||||||
|
"threshold": "BLOCK_NONE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"category": "HARM_CATEGORY_DANGEROUS",
|
||||||
|
"threshold": "BLOCK_NONE"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"temperature": arg.temperature,
|
||||||
|
"maxOutputTokens": arg.maxTokens,
|
||||||
|
"candidate_count": 1
|
||||||
|
}
|
||||||
|
const res = await globalFetch(`https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=${db.palmAPI}`, {
|
||||||
|
body: body,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if(res.ok){
|
||||||
|
if(res.data.candidates){
|
||||||
|
let output:string = res.data.candidates[0].output
|
||||||
|
const ind = output.search(/(system note)|(user)|(assistant):/gi)
|
||||||
|
if(ind >= 0){
|
||||||
|
output = output.substring(0, ind)
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: 'success',
|
||||||
|
result: output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return {
|
||||||
|
type: 'fail',
|
||||||
|
result: `${JSON.stringify(res.data)}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return {
|
||||||
|
type: 'fail',
|
||||||
|
result: `${JSON.stringify(res.data)}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
default:{
|
default:{
|
||||||
return {
|
return {
|
||||||
type: 'fail',
|
type: 'fail',
|
||||||
|
|||||||
@@ -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{
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import { tokenize } from "../tokenizer";
|
|||||||
import { findCharacterbyId } from "../util";
|
import { findCharacterbyId } from "../util";
|
||||||
import { requestChatData } from "./request";
|
import { requestChatData } from "./request";
|
||||||
|
|
||||||
export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxContextTokens:number,room:Chat,char:character|groupChat): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?:string; memory?:string}>{
|
export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxContextTokens:number,room:Chat,char:character|groupChat): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?:string; memory?:string;lastId?:string}>{
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
|
console.log("Memory: " + currentTokens)
|
||||||
|
|
||||||
if(currentTokens > maxContextTokens){
|
if(currentTokens > maxContextTokens){
|
||||||
let coIndex = -1
|
let coIndex = -1
|
||||||
for(let i=0;i<chats.length;i++){
|
for(let i=0;i<chats.length;i++){
|
||||||
@@ -29,26 +31,28 @@ export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxCont
|
|||||||
const id = splited.splice(0,1)[0]
|
const id = splited.splice(0,1)[0]
|
||||||
const data = splited.join('\n')
|
const data = splited.join('\n')
|
||||||
|
|
||||||
for(let i=0;i<chats.length;i++){
|
let i =0;
|
||||||
|
while(true){
|
||||||
|
if(chats.length === 0){
|
||||||
|
return {
|
||||||
|
currentTokens: currentTokens,
|
||||||
|
chats: chats,
|
||||||
|
error: "SupaMemory: chat ID not found"
|
||||||
|
}
|
||||||
|
}
|
||||||
if(chats[0].memo === id){
|
if(chats[0].memo === id){
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
currentTokens -= (await tokenize(chats[0].content) + 1)
|
currentTokens -= (await tokenize(chats[0].content) + 1)
|
||||||
chats.splice(0, 1)
|
chats.splice(0, 1)
|
||||||
}
|
i += 1
|
||||||
|
|
||||||
if(chats.length === 0){
|
|
||||||
return {
|
|
||||||
currentTokens: currentTokens,
|
|
||||||
chats: chats,
|
|
||||||
error: "SupaMemory: chat ID not found"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
supaMemory = data
|
supaMemory = data
|
||||||
currentTokens += await tokenize(supaMemory) + 1
|
currentTokens += await tokenize(supaMemory) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(currentTokens < maxContextTokens){
|
if(currentTokens < maxContextTokens){
|
||||||
chats.unshift({
|
chats.unshift({
|
||||||
role: "system",
|
role: "system",
|
||||||
@@ -134,7 +138,6 @@ export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxCont
|
|||||||
const tokenz = await tokenize(result + '\n\n') + 5
|
const tokenz = await tokenize(result + '\n\n') + 5
|
||||||
currentTokens += tokenz
|
currentTokens += tokenz
|
||||||
supaMemory += result + '\n\n'
|
supaMemory += result + '\n\n'
|
||||||
console.log(tokenz)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chats.unshift({
|
chats.unshift({
|
||||||
@@ -144,7 +147,8 @@ export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxCont
|
|||||||
return {
|
return {
|
||||||
currentTokens: currentTokens,
|
currentTokens: currentTokens,
|
||||||
chats: chats,
|
chats: chats,
|
||||||
memory: lastId + '\n' + supaMemory
|
memory: lastId + '\n' + supaMemory,
|
||||||
|
lastId: lastId
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ export function messageForm(arg:Message[], loadPages:number){
|
|||||||
role: m.role,
|
role: m.role,
|
||||||
data: reformatContent(m.data),
|
data: reformatContent(m.data),
|
||||||
index: i,
|
index: i,
|
||||||
saying: m.saying
|
saying: m.saying,
|
||||||
|
chatId: m.chatId ?? 'none'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return a.slice(0, loadPages)
|
return a.slice(0, loadPages)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":"0.9.6"}
|
{"version":"1.10.0"}
|
||||||
Reference in New Issue
Block a user