Skip to content

Commit

Permalink
1.91.0 (#339)
Browse files Browse the repository at this point in the history
# PR Checklist
- [ ] Did you check if it works normally in all models? *ignore this
when it dosen't uses models*
- [ ] Did you check if it works normally in all of web, local and node
hosted versions? if it dosen't, did you blocked it in those versions?
- [ ] Did you added a type def?

# Description
  • Loading branch information
kwaroran authored Apr 3, 2024
2 parents 11c1b50 + f35e3e6 commit 213ac33
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "RisuAI",
"version": "1.90.1"
"version": "1.91.0"
},
"tauri": {
"allowlist": {
Expand Down
22 changes: 17 additions & 5 deletions src/etc/patchNote.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
export const patchNote = {
version: "1.90",
version: "1.91",
content:
`
# Update 1.90.1
- Added {{spread::A}} and {{trim::B}}
- Fixed undefined variable crashing the app
- Now invaild curly brace syntax will be ignored
# Update 1.91.0
- {{#if A}} now trims the whitespace inside the content
- Old {{time}} and {{date}} is renamed to {{message_time}} and {{message_date}}
- Added {{lastcharmessage}} as allias for {{previous_char_chat}}
- Added {{lastusermessage}} as allias for {{previous_user_chat}}
- Added {{newline}} as allias for {{br}}
- Added {{lastmessage}}, which returns the last message sent in the current chat
- Added {{maxcontext}}, which returns the maximum context length
- Added {{lastmessageid}}, which returns the index of the last message sent in the current chat
- Added {{pow::A::B}}, which returns A raised to the power of B
- Added {{pick::A::B...}} which returns a random element from the list, but is consistent across the same message
- Added {{time}}, which returns the current time in the format HH:MM:SS in your timezone
- Added {{date}}, which returns the current date in the format YYYY-MM-DD in your timezone
- Added {{isotime}}, which returns the current time in the format HH:MM:SS in UTC
- Added {{isodate}}, which returns the current date in the format YYYY-MM-DD in UTC
- Added {{#if-pure A}} which is the same as {{#if A}}, but does not trim the whitespace inside the content
`
}

Expand Down
104 changes: 87 additions & 17 deletions src/ts/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { get } from 'svelte/store';
import css from '@adobe/css-tools'
import { selectedCharID } from './stores';
import { calcString } from './process/infunctions';
import { findCharacterbyId } from './util';
import { findCharacterbyId, sfc32, uuidtoNumber } from './util';
import { getInlayImage } from './process/files/image';
import { autoMarkNew } from './plugins/automark';
import { getModuleLorebooks } from './process/modules';
Expand Down Expand Up @@ -405,7 +405,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
const db = matcherArg.db
const chara = matcherArg.chara
switch(lowerCased){
case 'previous_char_chat':{
case 'previous_char_chat':
case 'lastcharmessage':{
if(chatID !== -1){
const selchar = db.characters[get(selectedCharID)]
const chat = selchar.chats[selchar.chatPage]
Expand All @@ -420,7 +421,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
}
return ''
}
case 'previous_user_chat':{
case 'previous_user_chat':
case 'lastusermessage':{
if(chatID !== -1){
const selchar = db.characters[get(selectedCharID)]
const chat = selchar.chats[selchar.chatPage]
Expand Down Expand Up @@ -537,7 +539,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
case 'none':{
return ''
}
case 'time':{
case 'message_time':{
if(matcherArg.tokenizeAccurate){
return `00:00:00`
}
Expand All @@ -555,7 +557,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
//output time in format like 10:30 AM
return date.toLocaleTimeString()
}
case 'date':{
case 'message_date':{
if(matcherArg.tokenizeAccurate){
return `00:00:00`
}
Expand All @@ -572,6 +574,22 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
//output date in format like Aug 23, 2021
return date.toLocaleDateString()
}
case 'time':{
const now = new Date()
return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
}
case 'date':{
const now = new Date()
return `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`
}
case 'isotime':{
const now = new Date()
return `${now.getUTCHours()}:${now.getUTCMinutes()}:${now.getUTCSeconds()}`
}
case 'isodate':{
const now = new Date()
return `${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}`
}
case 'idle_duration':{
if(matcherArg.tokenizeAccurate){
return `00:00:00`
Expand Down Expand Up @@ -625,7 +643,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
//output, like 1:30:00
return hours.toString() + ':' + minutes.toString().padStart(2,'0') + ':' + seconds.toString().padStart(2,'0')
}
case 'br':{
case 'br':
case 'newline':{
return '\n'
}
case 'model':{
Expand All @@ -643,6 +662,26 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
case 'random':{
return Math.random().toString()
}
case 'maxcontext':{
return db.maxContext.toString()
}
case 'lastmessage':{
const selchar = db.characters[get(selectedCharID)]
if(!selchar){
return ''
}
const chat = selchar.chats[selchar.chatPage]
return chat.message[chat.message.length - 1].data
}
case 'lastmessageid':
case 'lastmessageindex':{
const selchar = db.characters[get(selectedCharID)]
if(!selchar){
return ''
}
const chat = selchar.chats[selchar.chatPage]
return chat.message.length - 1
}
}
const arra = p1.split("::")
if(arra.length > 1){
Expand Down Expand Up @@ -779,6 +818,9 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
return !isNaN(Number(v)) || v === '.'
}).join('')
}
case 'pow':{
return Math.pow(Number(arra[1]), Number(arra[2])).toString()
}
}
}
if(p1.startsWith('random')){
Expand All @@ -798,6 +840,25 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
return arr[randomIndex]
}
}
if(p1.startsWith('pick')){
const selchar = db.characters[get(selectedCharID)]
const rand = sfc32(uuidtoNumber(selchar.chaId), chatID, uuidtoNumber(selchar.chaId), chatID)
if(p1.startsWith('pick::')){
const randomIndex = Math.floor(rand() * (arra.length - 1)) + 1
if(matcherArg.tokenizeAccurate){
return arra[0]
}
return arra[randomIndex]
}
else{
const arr = p1.split(/\:|\,/g)
const randomIndex = Math.floor(rand() * (arr.length - 1)) + 1
if(matcherArg.tokenizeAccurate){
return arra[0]
}
return arr[randomIndex]
}
}
if(p1.startsWith('roll')){
const arr = p1.split(/\:|\ /g)
let ina = arr.at(-1)
Expand Down Expand Up @@ -879,30 +940,39 @@ const legacyBlockMatcher = (p1:string,matcherArg:matcherArg) => {
return null
}

type blockMatch = 'ignore'|'parse'|'nothing'
type blockMatch = 'ignore'|'parse'|'nothing'|'parse-pure'


function blockStartMatcher(p1:string,matcherArg:matcherArg):blockMatch{
if(p1.startsWith('#if')){
const statement = p1.split(" ", 2)
if(p1.startsWith('#if') || p1.startsWith('#if_pure ')){
const statement = p1.substring(p1.indexOf(' ') + 1)
const state = statement[1]
if(state === 'true' || state === '1'){
return 'parse'
return p1.startsWith('#if_pure') ? 'parse-pure' : 'parse'
}
return 'ignore'
}
return 'nothing'
}

function blockEndMatcher(p1:string,type:blockMatch,matcherArg:matcherArg):string{
if(type === 'ignore'){
return ''
}
if(type === 'parse'){
return p1

switch(type){
case 'ignore':{
return ''
}
case 'parse':{
const trimedLines = p1.split('\n').map((v) => {
return v.trim()
}).join('\n').trim()
return trimedLines
}
case 'parse-pure':{
return p1
}
default:{
return ''
}
}
return ''
}

export function risuChatParser(da:string, arg:{
Expand Down
2 changes: 1 addition & 1 deletion src/ts/storage/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { OobaChatCompletionRequestParams } from '../model/ooba';

export const DataBase = writable({} as any as Database)
export const loadedStore = writable(false)
export let appVer = "1.90.1"
export let appVer = "1.91.0"
export let webAppSubVer = ''

export function setDatabase(data:Database){
Expand Down
23 changes: 22 additions & 1 deletion src/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,25 @@ export function blobToUint8Array(data:Blob){
})
}

export const languageCodes = ["af","ak","am","an","ar","as","ay","az","be","bg","bh","bm","bn","br","bs","ca","co","cs","cy","da","de","dv","ee","el","en","eo","es","et","eu","fa","fi","fo","fr","fy","ga","gd","gl","gn","gu","ha","he","hi","hr","ht","hu","hy","ia","id","ig","is","it","iu","ja","jv","ka","kk","km","kn","ko","ku","ky","la","lb","lg","ln","lo","lt","lv","mg","mi","mk","ml","mn","mr","ms","mt","my","nb","ne","nl","nn","no","ny","oc","om","or","pa","pl","ps","pt","qu","rm","ro","ru","rw","sa","sd","si","sk","sl","sm","sn","so","sq","sr","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ug","uk","ur","uz","vi","wa","wo","xh","yi","yo","zh","zu"]
export const languageCodes = ["af","ak","am","an","ar","as","ay","az","be","bg","bh","bm","bn","br","bs","ca","co","cs","cy","da","de","dv","ee","el","en","eo","es","et","eu","fa","fi","fo","fr","fy","ga","gd","gl","gn","gu","ha","he","hi","hr","ht","hu","hy","ia","id","ig","is","it","iu","ja","jv","ka","kk","km","kn","ko","ku","ky","la","lb","lg","ln","lo","lt","lv","mg","mi","mk","ml","mn","mr","ms","mt","my","nb","ne","nl","nn","no","ny","oc","om","or","pa","pl","ps","pt","qu","rm","ro","ru","rw","sa","sd","si","sk","sl","sm","sn","so","sq","sr","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ug","uk","ur","uz","vi","wa","wo","xh","yi","yo","zh","zu"]

export function sfc32(a:number, b:number, c:number, d:number) {
return function() {
a |= 0; b |= 0; c |= 0; d |= 0;
let t = (a + b | 0) + d | 0;
d = d + 1 | 0;
a = b ^ b >>> 9;
b = c + (c << 3) | 0;
c = (c << 21 | c >>> 11);
c = c + t | 0;
return (t >>> 0) / 4294967296;
}
}

export function uuidtoNumber(uuid:string){
let result = 0
for(let i=0;i<uuid.length;i++){
result += uuid.charCodeAt(i)
}
return result
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.90.1"}
{"version":"1.91.0"}

0 comments on commit 213ac33

Please sign in to comment.