[feat] better nai support

This commit is contained in:
kwaroran
2023-08-28 00:32:57 +09:00
parent 269673c671
commit f1fce49b89
5 changed files with 37 additions and 12 deletions

View File

@@ -430,4 +430,6 @@ export const languageEnglish = {
supporterThanksDesc: "Thank you for your support!", supporterThanksDesc: "Thank you for your support!",
donatorPatreonDesc:"For default, it will not be shown in the list for privacy. if you want to show your nickname, go to RisuAI's patreon page and press the link button.", donatorPatreonDesc:"For default, it will not be shown in the list for privacy. if you want to show your nickname, go to RisuAI's patreon page and press the link button.",
useNamePrefix: "Use Name Prefix", useNamePrefix: "Use Name Prefix",
textAdventureNAI: "Run as Text Adventure",
appendNameNAI: "Append Name on NAI",
} }

View File

@@ -208,11 +208,13 @@
<span class="text-textcolor">NovelAI Bearer Token</span> <span class="text-textcolor">NovelAI Bearer Token</span>
<TextInput marginBottom={true} bind:value={$DataBase.novelai.token}/> <TextInput marginBottom={true} bind:value={$DataBase.novelai.token}/>
<!-- {#if !($DataBase.novelai.token)} <div class="flex items-center mt-2 mb-4">
<div class="mb-2"> <Check bind:check={$DataBase.NAIadventure} name={language.textAdventureNAI}/>
<Button on:click={novelLogin} size="sm">Login to NovelAI</Button> </div>
<div class="flex items-center mt-2 mb-4">
<Check bind:check={$DataBase.NAIappendName} name={language.appendNameNAI}/>
</div> </div>
{/if} -->
{/if} {/if}
{#if $DataBase.aiModel === "kobold" || $DataBase.subModel === "kobold"} {#if $DataBase.aiModel === "kobold" || $DataBase.subModel === "kobold"}

View File

@@ -13,8 +13,6 @@ export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued:
let starter = db.NAIsettings.starter.replaceAll("\\n","\n") || '***\n[conversation: start]' let starter = db.NAIsettings.starter.replaceAll("\\n","\n") || '***\n[conversation: start]'
let resultString:string[] = [] let resultString:string[] = []
console.log(formated)
for(const form of formated){ for(const form of formated){
if(form.role === 'system'){ if(form.role === 'system'){
if(form.memo === 'NewChatExample' || form.memo === 'NewChat' || form.content === "[Start a new chat]"){ if(form.memo === 'NewChatExample' || form.memo === 'NewChat' || form.content === "[Start a new chat]"){
@@ -25,10 +23,23 @@ export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued:
} }
} }
else if(form.name || form.role === 'assistant'){ else if(form.name || form.role === 'assistant'){
if(db.NAIappendName){
resultString.push(form.content)
}
else{
resultString.push((form.name ?? char) + ": " + form.content) resultString.push((form.name ?? char) + ": " + form.content)
} }
}
else if(form.role === 'user'){ else if(form.role === 'user'){
resultString.push(db.username + ": " + form.content) let res = ''
if(db.NAIadventure){
res += '> '
}
if(db.NAIappendName){
res += db.username + ": "
}
res += form.content
resultString.push(res)
} }
else{ else{
resultString.push(form.content) resultString.push(form.content)
@@ -38,7 +49,7 @@ export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued:
let res = resultString.join(seperator) let res = resultString.join(seperator)
if(!continued){ if(!continued){
res += `\n\n${char}:` res += `${seperator}${char}:`
} }
return res return res
} }

View File

@@ -381,6 +381,12 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
}) })
} }
let prefix = 'vanilla'
if(db.NAIadventure){
prefix = 'theme_textadventure'
}
const gen = db.NAIsettings const gen = db.NAIsettings
const payload = { const payload = {
temperature:temperature, temperature:temperature,
@@ -399,17 +405,19 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
use_cache: false, use_cache: false,
use_string: true, use_string: true,
return_full_text: false, return_full_text: false,
prefix: 'vanilla', prefix: prefix,
order: [2, 3, 0, 4, 1], order: [2, 3, 0, 4, 1],
typical_p: gen.typicalp, typical_p: gen.typicalp,
repetition_penalty_whitelist:[49256,49264,49231,49230,49287,85,49255,49399,49262,336,333,432,363,468,492,745,401,426,623,794,1096,2919,2072,7379,1259,2110,620,526,487,16562,603,805,761,2681,942,8917,653,3513,506,5301,562,5010,614,10942,539,2976,462,5189,567,2032,123,124,125,126,127,128,129,130,131,132,588,803,1040,49209,4,5,6,7,8,9,10,11,12], repetition_penalty_whitelist:[49256,49264,49231,49230,49287,85,49255,49399,49262,336,333,432,363,468,492,745,401,426,623,794,1096,2919,2072,7379,1259,2110,620,526,487,16562,603,805,761,2681,942,8917,653,3513,506,5301,562,5010,614,10942,539,2976,462,5189,567,2032,123,124,125,126,127,128,129,130,131,132,588,803,1040,49209,4,5,6,7,8,9,10,11,12],
stop_sequences: [[49287]], stop_sequences: [[49287], [49405]],
bad_words_ids: NovelAIBadWordIds, bad_words_ids: NovelAIBadWordIds,
logit_bias_exp: logit_bias_exp logit_bias_exp: logit_bias_exp
} }
const body = { const body = {
"input": proompt, "input": proompt,
"model": aiModel === 'novelai_kayra' ? 'kayra-v1' : 'clio-v1', "model": aiModel === 'novelai_kayra' ? 'kayra-v1' : 'clio-v1',

View File

@@ -472,6 +472,8 @@ export interface Database{
emotionProcesser:'submodel'|'embedding', emotionProcesser:'submodel'|'embedding',
showMenuChatList?:boolean, showMenuChatList?:boolean,
translatorType:'google'|'deepl'|'none', translatorType:'google'|'deepl'|'none',
NAIadventure?:boolean,
NAIappendName?:boolean,
deeplOptions:{ deeplOptions:{
key:string, key:string,
freeApi:boolean freeApi:boolean