[fix] stringlize ain and revert cha
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
import { selectedCharID } from "../../ts/stores";
|
||||
import { translate } from "../../ts/translator/translator";
|
||||
import { replacePlaceholders } from "../../ts/util";
|
||||
|
||||
export let message = ''
|
||||
export let name = ''
|
||||
export let isLastMemory:boolean
|
||||
@@ -18,7 +17,6 @@
|
||||
export let onReroll = () => {}
|
||||
export let unReroll = () => {}
|
||||
export let character:character|groupChat|null = null
|
||||
let md:string
|
||||
let translating = false
|
||||
let editMode = false
|
||||
let statusMessage:string = ''
|
||||
@@ -26,8 +24,7 @@
|
||||
|
||||
let msgDisplay = ''
|
||||
let msgTranslated = ''
|
||||
let translated = false
|
||||
|
||||
let translated = false;
|
||||
async function rm(){
|
||||
const rm = $DataBase.askRemoval ? await alertConfirm(language.removeChat) : true
|
||||
if(rm){
|
||||
@@ -56,7 +53,7 @@
|
||||
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = msg
|
||||
}
|
||||
|
||||
async function displaya(message:string, isStreaming:boolean = false){
|
||||
async function displaya(message:string){
|
||||
if($DataBase.autoTranslate && $DataBase.translator !== ''){
|
||||
if(msgTranslated==='')
|
||||
msgDisplay = replacePlaceholders(message, name)
|
||||
@@ -67,12 +64,6 @@
|
||||
else{
|
||||
msgDisplay = replacePlaceholders(message, name)
|
||||
}
|
||||
|
||||
if(!md || !isStreaming || isStreaming && idx === $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message.length - 1) {
|
||||
ParseMarkdown(msgDisplay, character, 'normal').then(mdNew=>{
|
||||
md = mdNew
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const setStatusMessage = (message:string, timeout:number = 0)=>{
|
||||
@@ -83,7 +74,7 @@
|
||||
}, timeout)
|
||||
}
|
||||
|
||||
$: displaya(message, $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].isStreaming)
|
||||
$: displaya(message)
|
||||
</script>
|
||||
<div class="flex max-w-full justify-center" class:bgc={isLastMemory}>
|
||||
<div class="text-neutral-200 mt-1 ml-4 mr-4 mb-1 p-2 bg-transparent flex-grow border-t-gray-900 border-opacity-30 border-transparent flexium items-start max-w-full" >
|
||||
@@ -170,17 +161,19 @@
|
||||
</div>
|
||||
{#if editMode}
|
||||
<AutoresizeArea bind:value={message} />
|
||||
{:else if md}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<span class="text chat chattext prose prose-invert minw-0" on:click={() => {
|
||||
if($DataBase.clickToEdit && idx > -1){
|
||||
editMode = true
|
||||
msgTranslated = ""
|
||||
}
|
||||
}}
|
||||
style:font-size="{0.875 * ($DataBase.zoomsize / 100)}rem"
|
||||
style:line-height="{1.25 * ($DataBase.zoomsize / 100)}rem"
|
||||
>{@html md}</span>
|
||||
{:else}
|
||||
{#await ParseMarkdown(msgDisplay, character) then md}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<span class="text chat chattext prose prose-invert minw-0" on:click={() => {
|
||||
if($DataBase.clickToEdit && idx > -1){
|
||||
editMode = true
|
||||
msgTranslated = ""
|
||||
}
|
||||
}}
|
||||
style:font-size="{0.875 * ($DataBase.zoomsize / 100)}rem"
|
||||
style:line-height="{1.25 * ($DataBase.zoomsize / 100)}rem"
|
||||
>{@html md}</span>
|
||||
{/await}
|
||||
{/if}
|
||||
</span>
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
<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 === 'novellist' || $DataBase.subModel === 'novellist'}
|
||||
{#if $DataBase.aiModel.startsWith('novellist') || $DataBase.subModel.startsWith('novellist')}
|
||||
<span class="text-neutral-200">NovelList {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.novellistAPI}>
|
||||
{/if}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { OpenAIChat, OpenAIChatFull } from ".";
|
||||
import { DataBase, setDatabase, type character } from "../storage/database";
|
||||
import { pluginProcess } from "../plugins/plugins";
|
||||
import { language } from "../../lang";
|
||||
import { stringlizeChat, unstringlizeChat } from "./stringlize";
|
||||
import { stringlizeAINChat, stringlizeChat, unstringlizeChat } from "./stringlize";
|
||||
import { globalFetch, isNodeServer, isTauri } from "../storage/globalApi";
|
||||
import { sleep } from "../util";
|
||||
import { createDeep } from "./deepai";
|
||||
@@ -565,12 +565,12 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
};
|
||||
|
||||
const send_body = {
|
||||
text: stringlizeChat(formated, currentChar?.name ?? ''),
|
||||
text: stringlizeAINChat(formated, currentChar?.name ?? ''),
|
||||
length: maxTokens,
|
||||
temperature: temperature,
|
||||
top_p: 0.7,
|
||||
tailfree: 1.0,
|
||||
rep_pen: arg.frequencyPenalty ?? (db.frequencyPenalty / 100),
|
||||
rep_pen: arg.frequencyPenalty ?? (db.frequencyPenalty / 100) + 1,
|
||||
};
|
||||
|
||||
const response = await globalFetch(api_server_url + '/api', {
|
||||
|
||||
@@ -24,17 +24,16 @@ export function stringlizeChat(formated:OpenAIChat[], char:string = ''){
|
||||
export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string = ''){
|
||||
console.log(text)
|
||||
let minIndex = -1
|
||||
let chunks:string[] = ["system note:", "system:"]
|
||||
let chunks:string[] = ["system note:", "system:","system note:", "system:"]
|
||||
if(char){
|
||||
chunks.push(`${char}:`)
|
||||
}
|
||||
|
||||
for(const form of formated){
|
||||
if(form.name){
|
||||
const chunk = `${form.name}:`
|
||||
if(!chunks.includes(chunk)){
|
||||
chunks.push(chunk)
|
||||
}
|
||||
chunks.push(`${form.name}:`)
|
||||
chunks.push(`${form.name}:`)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +52,20 @@ export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
export function stringlizeAINChat(formated:OpenAIChat[], char:string = ''){
|
||||
let resultString:string[] = []
|
||||
for(const form of formated){
|
||||
if(form.role === 'system'){
|
||||
resultString.push(form.content)
|
||||
}
|
||||
else if(form.name){
|
||||
resultString.push(form.name + ": " + form.content)
|
||||
}
|
||||
else{
|
||||
resultString.push(form.content)
|
||||
}
|
||||
}
|
||||
return resultString.join('\n\n') + `\n\n${char}:`
|
||||
}
|
||||
@@ -7,9 +7,8 @@ import type { OpenAIChat } from "./process";
|
||||
|
||||
async function encode(data:string):Promise<(number[]|Uint32Array|Int32Array)>{
|
||||
let db = get(DataBase)
|
||||
if(db.aiModel === 'novellist'){
|
||||
if(db.aiModel.startsWith('novellist')){
|
||||
const nv= await tokenizeWebTokenizers(data, 'novellist')
|
||||
console.log(nv)
|
||||
return nv
|
||||
}
|
||||
if(db.aiModel.startsWith('claude')){
|
||||
|
||||
Reference in New Issue
Block a user