[feat] metrica plugin
This commit is contained in:
@@ -99,6 +99,7 @@ export const languageEnglish = {
|
||||
romanizer: "Romanizer is a plugin that converts non-roman characters to roman characters to reduce tokens when using non-roman characters while requesting data. this can result diffrent output from the original model. it is not recommended to use this plugin when using roman characters on chat.",
|
||||
oaiRandomUser: "If enabled, random uuid would be put on user parameter on request, and would be changed on refresh. this can be used to prevent AI from identifying user.",
|
||||
inlayImages: "If enabled, images could be inlayed to the chat and AIs can see it if they support it.",
|
||||
metrica: 'Metric Systemizer is a plugin that converts metrics to imperial units when request, and vice versa on output to show user metric system while using imperial for performace. it is not recommended to use this plugin when using imperial units on chat.',
|
||||
},
|
||||
setup: {
|
||||
chooseProvider: "Choose AI Provider",
|
||||
|
||||
@@ -30,6 +30,12 @@
|
||||
<div class="flex items-center mt-2">
|
||||
<Check bind:check={$DataBase.officialplugins.romanizer} name={language.able}/>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<span class="font-bold flex-grow">Metric Systemizer <Help key="metrica" /> <span class="text-green-500 italic">(Official Plugin)</span></span>
|
||||
</div>
|
||||
<div class="flex items-center mt-2">
|
||||
<Check bind:check={$DataBase.officialplugins.metrica} name={language.able}/>
|
||||
</div>
|
||||
{#each $DataBase.plugins as plugin, i}
|
||||
<div class="border-borderc mt-2 mb-2 w-full border-solid border-b-1 seperator"></div>
|
||||
<div class="flex">
|
||||
|
||||
68
src/ts/plugins/metrica.ts
Normal file
68
src/ts/plugins/metrica.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
const convertion:[string,string,number][] = [
|
||||
['kg', 'lbs', 2.20462],
|
||||
['m', 'ft', 3.28084],
|
||||
['cm', 'in', 0.393701],
|
||||
['mm', 'in', 0.0393701],
|
||||
['km', 'mi', 0.621371],
|
||||
['killogram', 'pound', 2.20462],
|
||||
['meter', 'foot', 3.28084],
|
||||
['centimeter', 'inch', 0.393701],
|
||||
['millimeter', 'inch', 0.0393701],
|
||||
['kilometer', 'mile', 0.621371],
|
||||
]
|
||||
|
||||
export function metricaPlugin(data:string, toSystem:'metrics'|'imperial'){
|
||||
const c = convertion.sort((a,b) => b[0].length - a[0].length);
|
||||
|
||||
for(let i=0;i<data.length;i++){
|
||||
function extractNumber(data:string, i:number){
|
||||
let number = '';
|
||||
while(i > 0){
|
||||
i--;
|
||||
if(data[i] === ' ' || data[i] === '\n' || data[i] === '\t' || data[i] === ','){
|
||||
continue
|
||||
}
|
||||
if(data[i] === '.'){
|
||||
number = '.' + number;
|
||||
continue;
|
||||
}
|
||||
if(isNaN(Number(data[i]))){
|
||||
break;
|
||||
}
|
||||
number = data[i] + number;
|
||||
}
|
||||
i++
|
||||
while(data[i] === ' ' || data[i] === '\n' || data[i] === '\t' || data[i] === ','){
|
||||
i++;
|
||||
}
|
||||
return {
|
||||
number: number === '' ? 0 : Number(number),
|
||||
index: i
|
||||
};
|
||||
}
|
||||
|
||||
let sub = ''
|
||||
let sublen = 0;
|
||||
for(let j=0;j<c.length;j++){
|
||||
const [from, to, ratio] = (toSystem === 'imperial') ? c[j] : [c[j][1], c[j][0], 1/c[j][2]];
|
||||
if(sublen !== from.length){
|
||||
sub = data.substring(i,i+from.length)
|
||||
sublen = from.length;
|
||||
}
|
||||
if(sub === from){
|
||||
const n = extractNumber(data, i);
|
||||
if(n .number !== 0){
|
||||
const num = (n.number * ratio)
|
||||
const rto = (num >= 1) ? num.toFixed(0) : num.toFixed(1);
|
||||
const newData = data.substring(0, n.index) + rto + ' ' + to + data.substring(i+from.length);
|
||||
const offset = newData.length - data.length;
|
||||
i += offset;
|
||||
data = newData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return data
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { selectSingleFile } from "../util";
|
||||
import { risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
||||
import { autoMarkPlugin } from "../plugins/automark";
|
||||
import { runCharacterJS } from "../plugins/embedscript";
|
||||
import { metricaPlugin } from "../plugins/metrica";
|
||||
|
||||
const dreg = /{{data}}/g
|
||||
const randomness = /\|\|\|/g
|
||||
@@ -62,6 +63,12 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
||||
if(db.officialplugins.automark && mode === 'editdisplay'){
|
||||
data = autoMarkPlugin(data)
|
||||
}
|
||||
if(db.officialplugins.metrica && mode === 'editdisplay'){
|
||||
data = metricaPlugin(data, 'metrics')
|
||||
}
|
||||
if(db.officialplugins.metrica && (mode === 'editinput' || mode === 'editoutput')){
|
||||
data = metricaPlugin(data, 'imperial')
|
||||
}
|
||||
data = await runCharacterJS({
|
||||
code: char.virtualscript ?? null,
|
||||
mode,
|
||||
|
||||
@@ -363,6 +363,7 @@ export interface Database{
|
||||
officialplugins: {
|
||||
automark?: boolean
|
||||
romanizer?: boolean
|
||||
metrica?: boolean
|
||||
}
|
||||
currentPluginProvider: string
|
||||
zoomsize:number
|
||||
|
||||
Reference in New Issue
Block a user