Merge branch 'main' of https://github.com/kwaroran/RisuAI into gpt-sovits-tts
This commit is contained in:
@@ -230,8 +230,8 @@ export function updateTextTheme(){
|
||||
root.style.setProperty('--FontColorItalic', db.customTextTheme.FontColorItalic);
|
||||
root.style.setProperty('--FontColorBold', db.customTextTheme.FontColorBold);
|
||||
root.style.setProperty('--FontColorItalicBold', db.customTextTheme.FontColorItalicBold);
|
||||
root.style.setProperty('--FontColorQuote1', db.customTextTheme.FontColorQuote1);
|
||||
root.style.setProperty('--FontColorQuote2', db.customTextTheme.FontColorQuote2);
|
||||
root.style.setProperty('--FontColorQuote1', db.customTextTheme.FontColorQuote1 ?? '#8BE9FD');
|
||||
root.style.setProperty('--FontColorQuote2', db.customTextTheme.FontColorQuote2 ?? '#FFB86C');
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { get } from "svelte/store"
|
||||
import { alertToast, doingAlert } from "./alert"
|
||||
import { DataBase, changeToPreset as changeToPreset2 } from "./storage/database"
|
||||
import { selectedCharID, settingsOpen } from "./stores"
|
||||
import { openPersonaList, openPresetList, selectedCharID, settingsOpen } from "./stores"
|
||||
|
||||
export function initHotkey(){
|
||||
document.addEventListener('keydown', (ev) => {
|
||||
@@ -73,6 +73,18 @@ export function initHotkey(){
|
||||
ev.stopPropagation()
|
||||
break
|
||||
}
|
||||
case 'p':{
|
||||
openPresetList.set(!get(openPresetList))
|
||||
ev.preventDefault()
|
||||
ev.stopPropagation()
|
||||
break
|
||||
}
|
||||
case 'e':{
|
||||
openPersonaList.set(!get(openPersonaList))
|
||||
ev.preventDefault()
|
||||
ev.stopPropagation()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ev.key === 'Escape'){
|
||||
|
||||
@@ -109,6 +109,8 @@ export function getModelName(name:string){
|
||||
return 'GPT-4o Mini (2024-07-18)'
|
||||
case 'gemini-1.5-pro-latest':
|
||||
return 'Gemini 1.5 Pro'
|
||||
case 'gemini-1.5-pro-exp-0801':
|
||||
return 'Gemini 1.5 Pro Exp (0801)'
|
||||
case 'gemini-1.5-flash':
|
||||
return 'Gemini 1.5 Flash'
|
||||
case 'ollama-hosted':
|
||||
|
||||
@@ -79,11 +79,19 @@ DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
||||
|
||||
|
||||
function renderMarkdown(md:markdownit, data:string){
|
||||
return md.render(data.replace(/“|”/g, '"').replace(/‘|’/g, "'"))
|
||||
.replace(/\uE9b0/gu, '<mark risu-mark="quote2">“')
|
||||
.replace(/\uE9b1/gu, '”</mark>')
|
||||
.replace(/\uE9b2/gu, '<mark risu-mark="quote1">‘')
|
||||
.replace(/\uE9b3/gu, '’</mark>')
|
||||
const db = get(DataBase)
|
||||
let text = md.render(data.replace(/“|”/g, '"').replace(/‘|’/g, "'"))
|
||||
|
||||
if(db?.unformatQuotes){
|
||||
text = text.replace(/\uE9b0/gu, '“').replace(/\uE9b1/gu, '”')
|
||||
text = text.replace(/\uE9b2/gu, '‘').replace(/\uE9b3/gu, '’')
|
||||
}
|
||||
else{
|
||||
text = text.replace(/\uE9b0/gu, '<mark risu-mark="quote2">“').replace(/\uE9b1/gu, '”</mark>')
|
||||
text = text.replace(/\uE9b2/gu, '<mark risu-mark="quote1">‘').replace(/\uE9b3/gu, '’</mark>')
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
async function renderHighlightableMarkdown(data:string) {
|
||||
|
||||
@@ -1153,6 +1153,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
case 'gemini-pro':
|
||||
case 'gemini-pro-vision':
|
||||
case 'gemini-1.5-pro-latest':
|
||||
case 'gemini-1.5-pro-exp-0801':
|
||||
case 'gemini-1.5-flash':
|
||||
case 'gemini-ultra':
|
||||
case 'gemini-ultra-vision':{
|
||||
@@ -1997,6 +1998,10 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
headers['anthropic-beta'] = 'prompt-caching-2024-07-31'
|
||||
}
|
||||
|
||||
if(db.usePlainFetch){
|
||||
headers['anthropic-dangerous-direct-browser-access'] = 'true'
|
||||
}
|
||||
|
||||
if(useStreaming){
|
||||
|
||||
const res = await fetchNative(replacerURL, {
|
||||
|
||||
@@ -20,9 +20,9 @@ export async function processScript(char:character|groupChat, data:string, mode:
|
||||
return (await processScriptFull(char, data, mode)).data
|
||||
}
|
||||
|
||||
export function exportRegex(){
|
||||
export function exportRegex(s?:customscript[]){
|
||||
let db = get(DataBase)
|
||||
const script = db.globalscript
|
||||
const script = s ?? db.globalscript
|
||||
const data = Buffer.from(JSON.stringify({
|
||||
type: 'regex',
|
||||
data: script
|
||||
@@ -31,22 +31,22 @@ export function exportRegex(){
|
||||
alertNormal(language.successExport)
|
||||
}
|
||||
|
||||
export async function importRegex(){
|
||||
export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
||||
o = o ?? []
|
||||
const filedata = (await selectSingleFile(['json'])).data
|
||||
if(!filedata){
|
||||
return
|
||||
return o
|
||||
}
|
||||
let db = get(DataBase)
|
||||
try {
|
||||
const imported= JSON.parse(Buffer.from(filedata).toString('utf-8'))
|
||||
if(imported.type === 'regex' && imported.data){
|
||||
const datas:customscript[] = imported.data
|
||||
const script = db.globalscript
|
||||
const script = o
|
||||
for(const data of datas){
|
||||
script.push(data)
|
||||
}
|
||||
db.globalscript = script
|
||||
setDatabase(db)
|
||||
return o
|
||||
}
|
||||
else{
|
||||
alertError("File invaid or corrupted")
|
||||
@@ -55,6 +55,7 @@ export async function importRegex(){
|
||||
} catch (error) {
|
||||
alertError(`${error}`)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
let bestMatchCache = new Map<string, string>()
|
||||
|
||||
@@ -11,7 +11,7 @@ export const chatTemplates = {
|
||||
'chatml': `{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}`,
|
||||
'gpt2': `{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}`,
|
||||
'gemma': "{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '<start_of_turn>' + role + '\n' + message['content'] | trim + '<end_of_turn>\n' }}{% endfor %}{% if add_generation_prompt %}{{'<start_of_turn>model\n'}}{% endif %}",
|
||||
'mistral': "{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ ' [INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' ' + message['content'] + ' ' + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}",
|
||||
'mistral': "{% for message in messages %}{% if message['role'] == 'user' %}{{ ' [INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' ' + message['content'] + ' ' + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}",
|
||||
'vicuna': "{%- set ns = namespace(found=false) -%}\n{%- for message in messages -%}\n {%- if message['role'] == 'system' -%}\n {%- set ns.found = true -%}\n {%- endif -%}\n{%- endfor -%}\n{%- if not ns.found -%}\n {{- '' + 'A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user\\'s questions.' + '\\n\\n' -}}\n{%- endif %}\n{%- for message in messages %}\n {%- if message['role'] == 'system' -%}\n {{- '' + message['content'] + '\\n\\n' -}}\n {%- else -%}\n {%- if message['role'] == 'user' -%}\n {{-'USER: ' + message['content'] + '\\n'-}}\n {%- else -%}\n {{-'ASSISTANT: ' + message['content'] + '</s>\\n' -}}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {{-'ASSISTANT:'-}}\n{%- endif -%}",
|
||||
"alpaca": "{%- set ns = namespace(found=false) -%}\n{%- for message in messages -%}\n {%- if message['role'] == 'system' -%}\n {%- set ns.found = true -%}\n {%- endif -%}\n{%- endfor -%}\n{%- if not ns.found -%}\n {{- '' + 'Below is an instruction that describes a task. Write a response that appropriately completes the request.' + '\\n\\n' -}}\n{%- endif %}\n{%- for message in messages %}\n {%- if message['role'] == 'system' -%}\n {{- '' + message['content'] + '\\n\\n' -}}\n {%- else -%}\n {%- if message['role'] == 'user' -%}\n {{-'### Instruction:\\n' + message['content'] + '\\n\\n'-}}\n {%- else -%}\n {{-'### Response:\\n' + message['content'] + '\\n\\n' -}}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {{-'### Response:\\n'-}}\n{%- endif -%}"
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export const templateEffect = {
|
||||
],
|
||||
'mistral': [
|
||||
'no_system_messages',
|
||||
'alter_user_assistant_roles'
|
||||
'alter_user_assistant_roles',
|
||||
],
|
||||
} as {[key:string]:TemplateEffect[]}
|
||||
|
||||
@@ -94,6 +94,8 @@ export const applyChatTemplate = (messages:OpenAIChat[]) => {
|
||||
"messages": formatedMessages,
|
||||
"add_generation_prompt": true,
|
||||
"risu_char": currentChar.name,
|
||||
"risu_user": getUserName()
|
||||
"risu_user": getUserName(),
|
||||
"eos_token": "",
|
||||
"bos_token": "",
|
||||
})
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import localforage from "localforage"
|
||||
import { isNodeServer, replaceDbResources } from "./globalApi"
|
||||
import { NodeStorage } from "./nodeStorage"
|
||||
import { OpfsStorage } from "./opfsStorage"
|
||||
import { alertSelect, alertStore } from "../alert"
|
||||
import { alertInput, alertSelect, alertStore } from "../alert"
|
||||
import { get } from "svelte/store"
|
||||
import { DataBase, type Database } from "./database"
|
||||
import { AccountStorage } from "./accountStorage"
|
||||
@@ -67,6 +67,13 @@ export class AutoStorage{
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
const confirm = await alertInput(`to overwrite your data, type "RISUAI"`)
|
||||
if(confirm !== "RISUAI"){
|
||||
localStorage.setItem('dosync', 'avoid')
|
||||
return false
|
||||
}
|
||||
|
||||
let replaced:{[key:string]:string} = {}
|
||||
|
||||
for(const key of keys){
|
||||
|
||||
@@ -428,6 +428,8 @@ export function setDatabase(data:Database){
|
||||
negInputName: 'text',
|
||||
timeout: 30
|
||||
}
|
||||
data.hideApiKey ??= true
|
||||
data.unformatQuotes ??= false
|
||||
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
@@ -710,6 +712,8 @@ export interface Database{
|
||||
comfyUiUrl: string
|
||||
useLegacyGUI: boolean
|
||||
claudeCachingExperimental: boolean
|
||||
hideApiKey: boolean
|
||||
unformatQuotes: boolean
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
|
||||
@@ -26,7 +26,8 @@ export const ViewBoxsize = writable({ width: 12 * 16, height: 12 * 16 }); // Def
|
||||
export const settingsOpen = writable(false)
|
||||
export const botMakerMode = writable(false)
|
||||
export const moduleBackgroundEmbedding = writable('')
|
||||
|
||||
export const openPresetList = writable(false)
|
||||
export const openPersonaList = writable(false)
|
||||
//optimization
|
||||
|
||||
export const CurrentCharacter = writable(null) as Writable<character | groupChat>
|
||||
|
||||
Reference in New Issue
Block a user