[feat] added template setting
This commit is contained in:
@@ -465,5 +465,12 @@ export const languageEnglish = {
|
|||||||
newOAIHandle: "New OpenAI Handling",
|
newOAIHandle: "New OpenAI Handling",
|
||||||
oaiRandomUser: "Put OAI Random User",
|
oaiRandomUser: "Put OAI Random User",
|
||||||
inlayImage: "Inlay Image Feature",
|
inlayImage: "Inlay Image Feature",
|
||||||
nativeAutomark: "Experimental Native Automark"
|
nativeAutomark: "Experimental Native Automark",
|
||||||
|
assistantPrefill: "Assistant Prefill",
|
||||||
|
postEndInnerFormat: "Post End",
|
||||||
|
sendChatAsSystem: "Send Chat as System",
|
||||||
|
sendName: "Send Name",
|
||||||
|
utilOverride: "Utility Override",
|
||||||
|
template: "Template",
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -417,4 +417,5 @@ export const languageKorean = {
|
|||||||
nativeAutomark: "실험적 네이티브 오토마크 사용",
|
nativeAutomark: "실험적 네이티브 오토마크 사용",
|
||||||
additionalAssets:"추가 에셋",
|
additionalAssets:"추가 에셋",
|
||||||
genTimes: "생성 횟수",
|
genTimes: "생성 횟수",
|
||||||
|
template: "템플릿",
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
import { tokenizePreset, type Proompt } from "src/ts/process/proompt";
|
import { tokenizePreset, type Proompt } from "src/ts/process/proompt";
|
||||||
import { templateCheck } from "src/ts/process/templates/templateCheck";
|
import { templateCheck } from "src/ts/process/templates/templateCheck";
|
||||||
import { DataBase } from "src/ts/storage/database";
|
import { DataBase } from "src/ts/storage/database";
|
||||||
|
import Check from "src/lib/UI/GUI/CheckInput.svelte";
|
||||||
|
import TextInput from "src/lib/UI/GUI/TextInput.svelte";
|
||||||
|
|
||||||
let sorted = 0
|
let sorted = 0
|
||||||
let opened = 0
|
let opened = 0
|
||||||
@@ -13,6 +15,7 @@
|
|||||||
let tokens = 0
|
let tokens = 0
|
||||||
let extokens = 0
|
let extokens = 0
|
||||||
executeTokenize($DataBase.promptTemplate)
|
executeTokenize($DataBase.promptTemplate)
|
||||||
|
let subMenu = 0
|
||||||
|
|
||||||
async function executeTokenize(prest: Proompt[]){
|
async function executeTokenize(prest: Proompt[]){
|
||||||
tokens = await tokenizePreset(prest, true)
|
tokens = await tokenizePreset(prest, true)
|
||||||
@@ -29,6 +32,18 @@
|
|||||||
</button>
|
</button>
|
||||||
{language.promptTemplate}
|
{language.promptTemplate}
|
||||||
</h2>
|
</h2>
|
||||||
|
<div class="flex w-full rounded-md border border-selected">
|
||||||
|
<button on:click={() => {
|
||||||
|
subMenu = 0
|
||||||
|
}} class="p-2 flex-1" class:bg-selected={subMenu === 0}>
|
||||||
|
<span>{language.template}</span>
|
||||||
|
</button>
|
||||||
|
<button on:click={() => {
|
||||||
|
subMenu = 1
|
||||||
|
}} class="p-2 flex-1" class:bg-selected={subMenu === 1}>
|
||||||
|
<span>{language.settings}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{#if warns.length > 0}
|
{#if warns.length > 0}
|
||||||
<div class="text-red-500 flex flex-col items-start p-2 rounded-md border-red-500 border">
|
<div class="text-red-500 flex flex-col items-start p-2 rounded-md border-red-500 border">
|
||||||
<h2 class="text-xl font-bold">Warning</h2>
|
<h2 class="text-xl font-bold">Warning</h2>
|
||||||
@@ -38,6 +53,8 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if subMenu === 0}
|
||||||
<div class="contain w-full max-w-full mt-4 flex flex-col p-3 rounded-md">
|
<div class="contain w-full max-w-full mt-4 flex flex-col p-3 rounded-md">
|
||||||
{#if $DataBase.promptTemplate.length === 0}
|
{#if $DataBase.promptTemplate.length === 0}
|
||||||
<div class="text-textcolor2">No Format</div>
|
<div class="text-textcolor2">No Format</div>
|
||||||
@@ -76,7 +93,7 @@
|
|||||||
value.push({
|
value.push({
|
||||||
type: "plain",
|
type: "plain",
|
||||||
text: "",
|
text: "",
|
||||||
role: "bot",
|
role: "system",
|
||||||
type2: 'normal'
|
type2: 'normal'
|
||||||
})
|
})
|
||||||
$DataBase.promptTemplate = value
|
$DataBase.promptTemplate = value
|
||||||
@@ -84,3 +101,14 @@
|
|||||||
|
|
||||||
<span class="text-textcolor2 text-sm mt-2">{tokens} {language.fixedTokens}</span>
|
<span class="text-textcolor2 text-sm mt-2">{tokens} {language.fixedTokens}</span>
|
||||||
<span class="text-textcolor2 mb-6 text-sm mt-2">{extokens} {language.exactTokens}</span>
|
<span class="text-textcolor2 mb-6 text-sm mt-2">{extokens} {language.exactTokens}</span>
|
||||||
|
{:else}
|
||||||
|
|
||||||
|
<!-- <span class="text-textcolor mt-4">{language.assistantPrefill}</span>
|
||||||
|
<TextInput bind:value={$DataBase.proomptSettings.assistantPrefill}/> -->
|
||||||
|
<span class="text-textcolor mt-4">{language.postEndInnerFormat}</span>
|
||||||
|
<TextInput bind:value={$DataBase.proomptSettings.postEndInnerFormat}/>
|
||||||
|
|
||||||
|
<Check bind:check={$DataBase.proomptSettings.sendChatAsSystem} name={language.sendChatAsSystem} className="mt-4"/>
|
||||||
|
<!-- <Check bind:check={$DataBase.proomptSettings.sendName} name={language.sendName} className="mt-4"/> -->
|
||||||
|
<Check bind:check={$DataBase.proomptSettings.utilOverride} name={language.utilOverride} className="mt-4"/>
|
||||||
|
{/if}
|
||||||
@@ -179,12 +179,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
}
|
}
|
||||||
|
|
||||||
let promptTemplate = cloneDeep(db.promptTemplate)
|
let promptTemplate = cloneDeep(db.promptTemplate)
|
||||||
|
const usingPromptTemplate = !!promptTemplate
|
||||||
if(promptTemplate){
|
if(promptTemplate){
|
||||||
promptTemplate.push({
|
promptTemplate.push({
|
||||||
type: 'postEverything'
|
type: 'postEverything'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if(currentChar.utilityBot){
|
if(currentChar.utilityBot && (!(usingPromptTemplate && db.proomptSettings.utilOverride))){
|
||||||
promptTemplate = [
|
promptTemplate = [
|
||||||
{
|
{
|
||||||
"type": "plain",
|
"type": "plain",
|
||||||
@@ -392,6 +393,12 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
}
|
}
|
||||||
case 'postEverything':{
|
case 'postEverything':{
|
||||||
await tokenizeChatArray(unformated.postEverything)
|
await tokenizeChatArray(unformated.postEverything)
|
||||||
|
if(usingPromptTemplate && db.proomptSettings.postEndInnerFormat){
|
||||||
|
await tokenizeChatArray([{
|
||||||
|
role: 'system',
|
||||||
|
content: db.proomptSettings.postEndInnerFormat
|
||||||
|
}])
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'plain':
|
case 'plain':
|
||||||
@@ -445,7 +452,11 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
if(start >= end){
|
if(start >= end){
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
const chats = unformated.chats.slice(start, end)
|
let chats = unformated.chats.slice(start, end)
|
||||||
|
|
||||||
|
if(usingPromptTemplate && db.proomptSettings.sendChatAsSystem){
|
||||||
|
chats = systemizeChat(chats)
|
||||||
|
}
|
||||||
await tokenizeChatArray(chats)
|
await tokenizeChatArray(chats)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -729,6 +740,12 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
}
|
}
|
||||||
case 'postEverything':{
|
case 'postEverything':{
|
||||||
pushPrompts(unformated.postEverything)
|
pushPrompts(unformated.postEverything)
|
||||||
|
if(usingPromptTemplate && db.proomptSettings.postEndInnerFormat){
|
||||||
|
pushPrompts([{
|
||||||
|
role: 'system',
|
||||||
|
content: db.proomptSettings.postEndInnerFormat
|
||||||
|
}])
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'plain':
|
case 'plain':
|
||||||
@@ -783,7 +800,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const chats = unformated.chats.slice(start, end)
|
let chats = unformated.chats.slice(start, end)
|
||||||
|
if(usingPromptTemplate && db.proomptSettings.sendChatAsSystem){
|
||||||
|
chats = systemizeChat(chats)
|
||||||
|
}
|
||||||
pushPrompts(chats)
|
pushPrompts(chats)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -1245,3 +1265,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function systemizeChat(chat:OpenAIChat[]){
|
||||||
|
for(let i=0;i<chat.length;i++){
|
||||||
|
if(chat[i].role === 'user' || chat[i].role === 'assistant'){
|
||||||
|
chat[i].content = chat[i].role + ': ' + chat[i].content
|
||||||
|
chat[i].role = 'system'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return chat
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
import { tokenizeAccurate } from "../tokenizer";
|
import { tokenizeAccurate } from "../tokenizer";
|
||||||
|
|
||||||
export type Proompt = ProomptPlain|ProomptTyped|ProomptChat|ProomptAuthorNote;
|
export type Proompt = ProomptPlain|ProomptTyped|ProomptChat|ProomptAuthorNote;
|
||||||
|
export type ProomptType = Proompt['type'];
|
||||||
|
export type ProomptSettings = {
|
||||||
|
assistantPrefill: string
|
||||||
|
postEndInnerFormat: string
|
||||||
|
sendChatAsSystem: boolean
|
||||||
|
sendName: boolean
|
||||||
|
utilOverride: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export interface ProomptPlain {
|
export interface ProomptPlain {
|
||||||
type: 'plain'|'jailbreak';
|
type: 'plain'|'jailbreak';
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { alertNormal, alertSelect } from '../alert';
|
|||||||
import type { NAISettings } from '../process/models/nai';
|
import type { NAISettings } from '../process/models/nai';
|
||||||
import { prebuiltNAIpresets, prebuiltPresets } from '../process/templates/templates';
|
import { prebuiltNAIpresets, prebuiltPresets } from '../process/templates/templates';
|
||||||
import { defaultColorScheme, type ColorScheme } from '../gui/colorscheme';
|
import { defaultColorScheme, type ColorScheme } from '../gui/colorscheme';
|
||||||
import type { Proompt } from '../process/proompt';
|
import type { Proompt, ProomptSettings } from '../process/proompt';
|
||||||
import type { OobaChatCompletionRequestParams } from '../model/ooba';
|
import type { OobaChatCompletionRequestParams } from '../model/ooba';
|
||||||
|
|
||||||
export const DataBase = writable({} as any as Database)
|
export const DataBase = writable({} as any as Database)
|
||||||
@@ -361,6 +361,14 @@ export function setDatabase(data:Database){
|
|||||||
data.google.accessToken ??= ''
|
data.google.accessToken ??= ''
|
||||||
data.google.projectId ??= ''
|
data.google.projectId ??= ''
|
||||||
data.genTime ??= 1
|
data.genTime ??= 1
|
||||||
|
data.proomptSettings ??= {
|
||||||
|
assistantPrefill: '',
|
||||||
|
postEndInnerFormat: '',
|
||||||
|
sendChatAsSystem: false,
|
||||||
|
sendName: false,
|
||||||
|
utilOverride: false
|
||||||
|
}
|
||||||
|
|
||||||
changeLanguage(data.language)
|
changeLanguage(data.language)
|
||||||
DataBase.set(data)
|
DataBase.set(data)
|
||||||
}
|
}
|
||||||
@@ -563,6 +571,7 @@ export interface Database{
|
|||||||
mistralKey?:string
|
mistralKey?:string
|
||||||
chainOfThought?:boolean
|
chainOfThought?:boolean
|
||||||
genTime:number
|
genTime:number
|
||||||
|
proomptSettings: ProomptSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface customscript{
|
export interface customscript{
|
||||||
@@ -759,6 +768,7 @@ export interface botPreset{
|
|||||||
customProxyRequestModel?: string
|
customProxyRequestModel?: string
|
||||||
reverseProxyOobaArgs?: OobaChatCompletionRequestParams
|
reverseProxyOobaArgs?: OobaChatCompletionRequestParams
|
||||||
top_p?: number
|
top_p?: number
|
||||||
|
proomptSettings?: ProomptSettings
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1010,7 +1020,8 @@ export function saveCurrentPreset(){
|
|||||||
autoSuggestPrompt: db.autoSuggestPrompt,
|
autoSuggestPrompt: db.autoSuggestPrompt,
|
||||||
customProxyRequestModel: db.customProxyRequestModel,
|
customProxyRequestModel: db.customProxyRequestModel,
|
||||||
reverseProxyOobaArgs: cloneDeep(db.reverseProxyOobaArgs) ?? null,
|
reverseProxyOobaArgs: cloneDeep(db.reverseProxyOobaArgs) ?? null,
|
||||||
top_p: db.top_p ?? 1
|
top_p: db.top_p ?? 1,
|
||||||
|
proomptSettings: cloneDeep(db.proomptSettings) ?? null
|
||||||
}
|
}
|
||||||
db.botPresets = pres
|
db.botPresets = pres
|
||||||
setDatabase(db)
|
setDatabase(db)
|
||||||
@@ -1080,6 +1091,13 @@ export function setPreset(db:Database, newPres: botPreset){
|
|||||||
mode: 'instruct'
|
mode: 'instruct'
|
||||||
}
|
}
|
||||||
db.top_p = newPres.top_p ?? 1
|
db.top_p = newPres.top_p ?? 1
|
||||||
|
db.proomptSettings = cloneDeep(newPres.proomptSettings) ?? {
|
||||||
|
assistantPrefill: '',
|
||||||
|
postEndInnerFormat: '',
|
||||||
|
sendChatAsSystem: false,
|
||||||
|
sendName: false,
|
||||||
|
utilOverride: false
|
||||||
|
}
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user