[feat] added template setting
This commit is contained in:
@@ -179,12 +179,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
|
||||
let promptTemplate = cloneDeep(db.promptTemplate)
|
||||
const usingPromptTemplate = !!promptTemplate
|
||||
if(promptTemplate){
|
||||
promptTemplate.push({
|
||||
type: 'postEverything'
|
||||
})
|
||||
}
|
||||
if(currentChar.utilityBot){
|
||||
if(currentChar.utilityBot && (!(usingPromptTemplate && db.proomptSettings.utilOverride))){
|
||||
promptTemplate = [
|
||||
{
|
||||
"type": "plain",
|
||||
@@ -392,6 +393,12 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
case 'postEverything':{
|
||||
await tokenizeChatArray(unformated.postEverything)
|
||||
if(usingPromptTemplate && db.proomptSettings.postEndInnerFormat){
|
||||
await tokenizeChatArray([{
|
||||
role: 'system',
|
||||
content: db.proomptSettings.postEndInnerFormat
|
||||
}])
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'plain':
|
||||
@@ -445,7 +452,11 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
if(start >= end){
|
||||
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)
|
||||
break
|
||||
}
|
||||
@@ -729,6 +740,12 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
case 'postEverything':{
|
||||
pushPrompts(unformated.postEverything)
|
||||
if(usingPromptTemplate && db.proomptSettings.postEndInnerFormat){
|
||||
pushPrompts([{
|
||||
role: 'system',
|
||||
content: db.proomptSettings.postEndInnerFormat
|
||||
}])
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'plain':
|
||||
@@ -783,7 +800,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
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)
|
||||
break
|
||||
}
|
||||
@@ -1244,4 +1264,14 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
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 {
|
||||
type: 'plain'|'jailbreak';
|
||||
|
||||
@@ -10,7 +10,7 @@ import { alertNormal, alertSelect } from '../alert';
|
||||
import type { NAISettings } from '../process/models/nai';
|
||||
import { prebuiltNAIpresets, prebuiltPresets } from '../process/templates/templates';
|
||||
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';
|
||||
|
||||
export const DataBase = writable({} as any as Database)
|
||||
@@ -361,6 +361,14 @@ export function setDatabase(data:Database){
|
||||
data.google.accessToken ??= ''
|
||||
data.google.projectId ??= ''
|
||||
data.genTime ??= 1
|
||||
data.proomptSettings ??= {
|
||||
assistantPrefill: '',
|
||||
postEndInnerFormat: '',
|
||||
sendChatAsSystem: false,
|
||||
sendName: false,
|
||||
utilOverride: false
|
||||
}
|
||||
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
}
|
||||
@@ -563,6 +571,7 @@ export interface Database{
|
||||
mistralKey?:string
|
||||
chainOfThought?:boolean
|
||||
genTime:number
|
||||
proomptSettings: ProomptSettings
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
@@ -759,6 +768,7 @@ export interface botPreset{
|
||||
customProxyRequestModel?: string
|
||||
reverseProxyOobaArgs?: OobaChatCompletionRequestParams
|
||||
top_p?: number
|
||||
proomptSettings?: ProomptSettings
|
||||
|
||||
}
|
||||
|
||||
@@ -1010,7 +1020,8 @@ export function saveCurrentPreset(){
|
||||
autoSuggestPrompt: db.autoSuggestPrompt,
|
||||
customProxyRequestModel: db.customProxyRequestModel,
|
||||
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
|
||||
setDatabase(db)
|
||||
@@ -1080,6 +1091,13 @@ export function setPreset(db:Database, newPres: botPreset){
|
||||
mode: 'instruct'
|
||||
}
|
||||
db.top_p = newPres.top_p ?? 1
|
||||
db.proomptSettings = cloneDeep(newPres.proomptSettings) ?? {
|
||||
assistantPrefill: '',
|
||||
postEndInnerFormat: '',
|
||||
sendChatAsSystem: false,
|
||||
sendName: false,
|
||||
utilOverride: false
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user