[feat] added features in spec v2
This commit is contained in:
@@ -192,6 +192,7 @@ function convertOldTavernAndJSON(charaData:OldTavernChar, imgp:string|undefined
|
||||
characterVersion: 0,
|
||||
personality: charaData.personality ?? '',
|
||||
scenario:charaData.scenario ?? '',
|
||||
firstMsgIndex: -1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,6 +351,8 @@ async function importSpecv2(card:CharacterCardV2, img?:Uint8Array):Promise<boole
|
||||
characterVersion: data.character_version ?? 0,
|
||||
personality:data.personality ?? '',
|
||||
scenario:data.scenario ?? '',
|
||||
firstMsgIndex: -1,
|
||||
removedQuotes: false
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ export function createNewGroup(){
|
||||
emotionImages: [],
|
||||
customscript: [],
|
||||
chaId: uuidv4(),
|
||||
firstMsgIndex: -1
|
||||
})
|
||||
setDatabase(db)
|
||||
return db.characters.length - 1
|
||||
@@ -269,6 +270,18 @@ export function characterFormatUpdate(index:number|character){
|
||||
if(checkNullish(cha.utilityBot)){
|
||||
cha.utilityBot = false
|
||||
}
|
||||
cha.alternateGreetings = cha.alternateGreetings ?? []
|
||||
cha.exampleMessage = cha.exampleMessage ?? ''
|
||||
cha.creatorNotes = cha.creatorNotes ?? ''
|
||||
cha.systemPrompt = cha.systemPrompt ?? ''
|
||||
cha.postHistoryInstructions = cha.postHistoryInstructions ?? ''
|
||||
cha.tags = cha.tags ?? []
|
||||
cha.creator = cha.creator ?? ''
|
||||
cha.characterVersion = cha.characterVersion ?? 0
|
||||
cha.personality = cha.personality ?? ''
|
||||
cha.scenario = cha.scenario ?? ''
|
||||
cha.firstMsgIndex = cha.firstMsgIndex ?? -1
|
||||
|
||||
}
|
||||
if(checkNullish(cha.customscript)){
|
||||
cha.customscript = []
|
||||
@@ -313,6 +326,7 @@ export function createBlankChar():character{
|
||||
characterVersion: 0,
|
||||
personality:"",
|
||||
scenario:"",
|
||||
firstMsgIndex: -1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +178,9 @@ export function setDatabase(data:Database){
|
||||
if(checkNullish(data.requestproxy)){
|
||||
data.requestproxy = ''
|
||||
}
|
||||
if(checkNullish(data.showUnrecommended)){
|
||||
data.showUnrecommended = false
|
||||
}
|
||||
if(checkNullish(data.sdConfig)){
|
||||
data.sdConfig = {
|
||||
width:512,
|
||||
@@ -238,7 +241,7 @@ export interface character{
|
||||
customscript: customscript[]
|
||||
utilityBot: boolean
|
||||
exampleMessage:string
|
||||
|
||||
removedQuotes?:boolean
|
||||
creatorNotes:string
|
||||
systemPrompt:string
|
||||
postHistoryInstructions:string
|
||||
@@ -248,6 +251,7 @@ export interface character{
|
||||
characterVersion: number
|
||||
personality:string
|
||||
scenario:string
|
||||
firstMsgIndex:number
|
||||
}
|
||||
|
||||
export interface groupChat{
|
||||
@@ -265,6 +269,10 @@ export interface groupChat{
|
||||
emotionImages: [string, string][]
|
||||
customscript: customscript[],
|
||||
chaId: string
|
||||
alternateGreetings?: string[]
|
||||
creatorNotes?:string,
|
||||
removedQuotes?:boolean
|
||||
firstMsgIndex?:number,
|
||||
}
|
||||
|
||||
export interface botPreset{
|
||||
@@ -358,6 +366,7 @@ export interface Database{
|
||||
didFirstSetup: boolean
|
||||
requestmet: string
|
||||
requestproxy: string
|
||||
showUnrecommended:boolean
|
||||
}
|
||||
|
||||
|
||||
|
||||
62
src/ts/process/exampleMessages.ts
Normal file
62
src/ts/process/exampleMessages.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { OpenAIChat } from ".";
|
||||
import type { character } from "../database";
|
||||
import { replacePlaceholders } from "../util";
|
||||
|
||||
export function exampleMessage(char:character):OpenAIChat[]{
|
||||
if(char.exampleMessage === ''){
|
||||
return []
|
||||
}
|
||||
|
||||
const messages = char.exampleMessage.split('\n')
|
||||
let result:OpenAIChat[] = []
|
||||
let currentMessage:OpenAIChat
|
||||
|
||||
function add(){
|
||||
if(currentMessage){
|
||||
result.push(currentMessage)
|
||||
}
|
||||
}
|
||||
|
||||
for(const mes of messages){
|
||||
const trimed = mes.trim()
|
||||
const lowered = trimed.toLocaleLowerCase()
|
||||
|
||||
|
||||
if(lowered === '<start>'){
|
||||
add()
|
||||
result.push({
|
||||
role: "system",
|
||||
content: '[Start a new chat]'
|
||||
})
|
||||
}
|
||||
else if(lowered.startsWith('{{char}}:') || lowered.startsWith('<bot>:') || lowered.startsWith(`${char.name}:`)){
|
||||
add()
|
||||
currentMessage = {
|
||||
role: "assistant",
|
||||
content: trimed.split(':', 2)[1]
|
||||
}
|
||||
}
|
||||
else if(lowered.startsWith('{{user}}:') || lowered.startsWith('<user>:')){
|
||||
add()
|
||||
currentMessage = {
|
||||
role: "user",
|
||||
content: trimed.split(':', 2)[1]
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(currentMessage){
|
||||
currentMessage.content += "\n" + trimed
|
||||
}
|
||||
}
|
||||
}
|
||||
add()
|
||||
|
||||
result = result.map((r) => {
|
||||
return {
|
||||
role: r.role,
|
||||
content: replacePlaceholders(r.content, char.name)
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { findCharacterbyId, replacePlaceholders } from "../util";
|
||||
import { requestChatData } from "./request";
|
||||
import { stableDiff } from "./stableDiff";
|
||||
import { processScript, processScriptFull } from "./scripts";
|
||||
import { exampleMessage } from "./exampleMessages";
|
||||
|
||||
export interface OpenAIChat{
|
||||
role: 'system'|'user'|'assistant'
|
||||
@@ -99,9 +100,11 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
||||
}
|
||||
|
||||
if(!currentChar.utilityBot){
|
||||
const mainp = currentChar.systemPrompt.length > 3 ? currentChar.systemPrompt : db.mainPrompt
|
||||
|
||||
unformated.main.push({
|
||||
role: 'system',
|
||||
content: replacePlaceholders(db.mainPrompt + ((db.additionalPrompt === '' || (!db.promptPreprocess)) ? '' : `\n${db.additionalPrompt}`), currentChar.name)
|
||||
content: replacePlaceholders(mainp + ((db.additionalPrompt === '' || (!db.promptPreprocess)) ? '' : `\n${db.additionalPrompt}`), currentChar.name)
|
||||
})
|
||||
|
||||
if(db.jailbreakToggle){
|
||||
@@ -122,10 +125,30 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
||||
content: replacePlaceholders(currentChat.note, currentChar.name)
|
||||
})
|
||||
|
||||
unformated.description.push({
|
||||
role: 'system',
|
||||
content: replacePlaceholders((db.promptPreprocess ? db.descriptionPrefix: '') + currentChar.desc, currentChar.name)
|
||||
})
|
||||
if(currentChar.postHistoryInstructions !== ''){
|
||||
unformated.authorNote.push({
|
||||
role: 'system',
|
||||
content: replacePlaceholders(currentChar.postHistoryInstructions, currentChar.name)
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
let description = replacePlaceholders((db.promptPreprocess ? db.descriptionPrefix: '') + currentChar.desc, currentChar.name)
|
||||
|
||||
if(currentChar.personality){
|
||||
description += replacePlaceholders("\n\nDescription of {{char}}: " + currentChar.personality,currentChar.name)
|
||||
}
|
||||
|
||||
if(currentChar.scenario){
|
||||
description += replacePlaceholders("\n\nCircumstances and context of the dialogue: " + currentChar.scenario,currentChar.name)
|
||||
}
|
||||
|
||||
unformated.description.push({
|
||||
role: 'system',
|
||||
content: description
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
unformated.lorebook.push({
|
||||
role: 'system',
|
||||
@@ -139,20 +162,12 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
||||
}).join('\n\n')
|
||||
}).join('\n\n')) + db.maxResponse) + 150
|
||||
|
||||
let chats:OpenAIChat[] = []
|
||||
let chats:OpenAIChat[] = exampleMessage(currentChar)
|
||||
|
||||
if(nowChatroom.type === 'group'){
|
||||
chats.push({
|
||||
role: 'system',
|
||||
content: '[Start a new group chat]'
|
||||
})
|
||||
}
|
||||
else{
|
||||
chats.push({
|
||||
role: 'system',
|
||||
content: '[Start a new chat]'
|
||||
})
|
||||
}
|
||||
chats.push({
|
||||
role: 'system',
|
||||
content: '[Start a new chat]'
|
||||
})
|
||||
|
||||
chats.push({
|
||||
role: 'assistant',
|
||||
@@ -349,25 +364,6 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// const promptbody:OpenAIChat[] = [
|
||||
// {
|
||||
|
||||
// role:'system',
|
||||
// content: `assistant is a emotion extractor. user will input a prompt of a character, and assistant must output the emotion of a character.\n\n must chosen from this list: ${shuffleArray(emotionList).join(', ')} \noutput only one word.`
|
||||
// },
|
||||
// {
|
||||
// role: 'user',
|
||||
// content: `"Good morning, Master! Is there anything I can do for you today?"`
|
||||
// },
|
||||
// {
|
||||
// role: 'assistant',
|
||||
// content: 'happy'
|
||||
// },
|
||||
// {
|
||||
// role: 'user',
|
||||
// content: result
|
||||
// },
|
||||
// ]
|
||||
|
||||
const promptbody:OpenAIChat[] = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user