Add tokenizer playground

This commit is contained in:
kwaroran
2024-04-24 22:06:02 +09:00
parent 90574bcdc3
commit 58513ed54a
2 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
<script lang="ts">
import { encode } from "src/ts/tokenizer";
import TextAreaInput from "../UI/GUI/TextAreaInput.svelte";
import { language } from 'src/lang';
let input = "";
let output = "";
let outputLength = 0;
const onInput = async () => {
try {
const tokenized = await encode(input);
const tokenizedNumArray = Array.from(tokenized)
outputLength = tokenizedNumArray.length;
output = JSON.stringify(tokenizedNumArray);
} catch (e) {
output = `Error: ${e}`
}
}
</script>
<h2 class="text-4xl text-textcolor my-6 font-black relative">{language.tokenizer}</h2>
<span class="text-textcolor text-lg">Input</span>
<TextAreaInput onInput={onInput} bind:value={input} height="32" />
<span class="text-textcolor text-lg">Result</span>
<TextAreaInput value={output} height="32" />
<span class="text-textcolor2 text-lg">{outputLength} {language.tokens}</span>

View File

@@ -18,7 +18,7 @@ export const tokenizerList = [
['novellist', 'Novellist'],
] as const
async function encode(data:string):Promise<(number[]|Uint32Array|Int32Array)>{
export async function encode(data:string):Promise<(number[]|Uint32Array|Int32Array)>{
let db = get(DataBase)
if(db.aiModel === 'openrouter' || db.aiModel === 'reverse_proxy'){
switch(db.customTokenizer){