[fix] oobabooga prompts
This commit is contained in:
@@ -285,11 +285,11 @@
|
|||||||
{#if $DataBase.ooba.formating.custom}
|
{#if $DataBase.ooba.formating.custom}
|
||||||
<div class="flex flex-col p-3 bg-darkbg mt-4">
|
<div class="flex flex-col p-3 bg-darkbg mt-4">
|
||||||
<span class="text-neutral-200">User Prefix</span>
|
<span class="text-neutral-200">User Prefix</span>
|
||||||
<TextInput marginBottom bind:value={$DataBase.ooba.formating.userPrefix} />
|
<TextAreaInput fullwidth autocomplete="off" height={"24"} bind bind:value={$DataBase.ooba.formating.userPrefix} />
|
||||||
<span class="text-neutral-200">Assistant Prefix</span>
|
<span class="text-neutral-200">Assistant Prefix</span>
|
||||||
<TextInput marginBottom bind:value={$DataBase.ooba.formating.assistantPrefix} />
|
<TextAreaInput fullwidth autocomplete="off" height={"24"} bind bind:value={$DataBase.ooba.formating.assistantPrefix} />
|
||||||
<span class="text-neutral-200">Seperator</span>
|
<span class="text-neutral-200">Seperator</span>
|
||||||
<TextInput marginBottom bind:value={$DataBase.ooba.formating.seperator} />
|
<TextAreaInput fullwidth autocomplete="off" height={"24"} bind bind:value={$DataBase.ooba.formating.seperator} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if $DataBase.aiModel.startsWith('novelai')}
|
{:else if $DataBase.aiModel.startsWith('novelai')}
|
||||||
|
|||||||
@@ -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 { stringlizeAINChat, stringlizeChat, stringlizeChatOba, unstringlizeAIN, unstringlizeChat } from "./stringlize";
|
import { stringlizeAINChat, stringlizeChat, stringlizeChatOba, getStopStrings, unstringlizeAIN, 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";
|
||||||
@@ -375,11 +375,12 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
let DURL = db.textgenWebUIURL
|
let DURL = db.textgenWebUIURL
|
||||||
let bodyTemplate:any
|
let bodyTemplate:any
|
||||||
const proompt = stringlizeChatOba(formated, currentChar?.name ?? '')
|
const proompt = stringlizeChatOba(formated, currentChar?.name ?? '')
|
||||||
|
const stopStrings = getStopStrings()
|
||||||
if(!DURL.endsWith('generate')){
|
if(!DURL.endsWith('generate')){
|
||||||
DURL = DURL + "/v1/generate"
|
DURL = DURL + "/v1/generate"
|
||||||
}
|
}
|
||||||
const stopStrings = [`\nUser:`,`\nuser:`,`\n${db.username}:`]
|
|
||||||
console.log(proompt)
|
console.log(proompt)
|
||||||
|
console.log(stopStrings)
|
||||||
bodyTemplate = {
|
bodyTemplate = {
|
||||||
'max_new_tokens': db.maxResponse,
|
'max_new_tokens': db.maxResponse,
|
||||||
'do_sample': true,
|
'do_sample': true,
|
||||||
|
|||||||
@@ -23,43 +23,69 @@ export function stringlizeChat(formated:OpenAIChat[], char:string = ''){
|
|||||||
return resultString.join('\n\n') + `\n\n${char}:`
|
return resultString.join('\n\n') + `\n\n${char}:`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function appendWhitespace(prefix:string, seperator:string=" ") {
|
||||||
|
if(!"> \n".includes(prefix[prefix.length-1])){
|
||||||
|
prefix += seperator.includes("\n\n") ? "\n" : " "
|
||||||
|
}
|
||||||
|
return prefix
|
||||||
|
}
|
||||||
export function stringlizeChatOba(formated:OpenAIChat[], char:string = ''){
|
export function stringlizeChatOba(formated:OpenAIChat[], char:string = ''){
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
let resultString:string[] = []
|
let resultString:string[] = []
|
||||||
if(db.ooba.formating.custom){
|
let { custom, userPrefix, assistantPrefix, seperator } = db.ooba.formating;
|
||||||
for(const form of formated){
|
if(!custom || !seperator){
|
||||||
if(form.role === 'system'){
|
seperator = "\n\n"
|
||||||
resultString.push(form.content)
|
|
||||||
}
|
}
|
||||||
else if(form.name){
|
|
||||||
resultString.push(db.ooba.formating.userPrefix + form.content + db.ooba.formating.seperator)
|
for(const form of formated){
|
||||||
|
if(form.content === "[Start a new chat]"){
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
let prefix = ""
|
||||||
|
if(form.role !== 'system' && form.name){
|
||||||
|
prefix = custom ? appendWhitespace(userPrefix, seperator) : form.name + ": "
|
||||||
}
|
}
|
||||||
else if(form.role === 'assistant' && char){
|
else if(form.role === 'assistant' && char){
|
||||||
resultString.push(db.ooba.formating.assistantPrefix + form.content + db.ooba.formating.seperator)
|
prefix = custom ? appendWhitespace(assistantPrefix, seperator) : char + ": "
|
||||||
|
}
|
||||||
|
resultString.push(prefix + form.content)
|
||||||
|
}
|
||||||
|
const name = custom ? assistantPrefix : char + ":"
|
||||||
|
resultString.push(name)
|
||||||
|
return resultString.join(seperator)
|
||||||
|
}
|
||||||
|
|
||||||
|
const userStrings = ["user", "human", "input", "inst", "instruction"]
|
||||||
|
function toTitleCase(s:string){
|
||||||
|
return s[0].toUpperCase() + s.slice(1).toLowerCase()
|
||||||
|
}
|
||||||
|
export function getStopStrings(){
|
||||||
|
const db = get(DataBase)
|
||||||
|
let { custom, userPrefix, seperator } = db.ooba.formating;
|
||||||
|
if(!custom || !seperator){
|
||||||
|
seperator = "\n"
|
||||||
}
|
}
|
||||||
else{
|
const { username } = db
|
||||||
resultString.push(form.content)
|
const stopStrings = [
|
||||||
|
"GPT4 User",
|
||||||
|
userPrefix,
|
||||||
|
`${username}:`,
|
||||||
|
]
|
||||||
|
if(seperator !== " "){
|
||||||
|
stopStrings.push(seperator + username)
|
||||||
|
}
|
||||||
|
for (const user of userStrings){
|
||||||
|
for (const u of [
|
||||||
|
user.toLowerCase(),
|
||||||
|
user.toUpperCase(),
|
||||||
|
user.replace(/\w\S*/g, toTitleCase),
|
||||||
|
]){
|
||||||
|
stopStrings.push(`${u}:`)
|
||||||
|
stopStrings.push(`<<${u}>>`)
|
||||||
|
stopStrings.push(`### ${u}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resultString.join('\n\n') + `\n\n${db.ooba.formating.assistantPrefix}:`
|
return [...new Set(stopStrings)]
|
||||||
}
|
|
||||||
for(const form of formated){
|
|
||||||
if(form.role === 'system'){
|
|
||||||
resultString.push(form.content)
|
|
||||||
}
|
|
||||||
else if(form.name){
|
|
||||||
resultString.push(form.name + ": " + form.content)
|
|
||||||
}
|
|
||||||
else if(form.role === 'assistant' && char){
|
|
||||||
resultString.push(char + ": " + form.content)
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
resultString.push(form.content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resultString.join('\n\n') + `\n\n${char}:`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string = ''){
|
export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string = ''){
|
||||||
|
|||||||
Reference in New Issue
Block a user