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