[feat] trin & claude tokenizer + novellist support
This commit is contained in:
7
public/token/claude/LICENSE
Normal file
7
public/token/claude/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Copyright 2022 Anthropic, PBC.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
1
public/token/claude/claude.json
Normal file
1
public/token/claude/claude.json
Normal file
File diff suppressed because one or more lines are too long
20
public/token/trin/LICENSE
Normal file
20
public/token/trin/LICENSE
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
Copyright (c) Sta, AI Novelist Dev (https://ai-novel.com/) @ Bit192, Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use,
|
||||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
BIN
public/token/trin/spiece.model
Normal file
BIN
public/token/trin/spiece.model
Normal file
Binary file not shown.
@@ -79,6 +79,8 @@
|
|||||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('textgen_webui')}}>Oobabooga WebUI</button>
|
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('textgen_webui')}}>Oobabooga WebUI</button>
|
||||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('palm2')}}>Google PaLM2</button>
|
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('palm2')}}>Google PaLM2</button>
|
||||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('kobold')}}>Kobold</button>
|
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('kobold')}}>Kobold</button>
|
||||||
|
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('novellist')}}>Novellist</button>
|
||||||
|
|
||||||
{#if isTauri ||isNodeServer}
|
{#if isTauri ||isNodeServer}
|
||||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('novelai')}}>NovelAI Clio</button>
|
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('novelai')}}>NovelAI Clio</button>
|
||||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('deepai')}}>DeepAI</button>
|
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('deepai')}}>DeepAI</button>
|
||||||
|
|||||||
@@ -586,6 +586,13 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(response.data.error){
|
||||||
|
return {
|
||||||
|
'type': 'fail',
|
||||||
|
'result': `${response.data.error.replace("token", "api key")}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const result = response.data.data[0];
|
const result = response.data.data[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
import type { Tiktoken } from "@dqbd/tiktoken";
|
import type { Tiktoken } from "@dqbd/tiktoken";
|
||||||
|
import type { Tokenizer } from "@mlc-ai/web-tokenizers";
|
||||||
|
|
||||||
import { DataBase, type character } from "./storage/database";
|
import { DataBase, type character } from "./storage/database";
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
import { tokenizeTransformers } from "./transformers/transformer";
|
|
||||||
import type { OpenAIChat } from "./process";
|
import type { OpenAIChat } from "./process";
|
||||||
|
|
||||||
async function encode(data:string):Promise<(number[]|Uint32Array)>{
|
async function encode(data:string):Promise<(number[]|Uint32Array|Int32Array)>{
|
||||||
let db = get(DataBase)
|
let db = get(DataBase)
|
||||||
if(db.aiModel === 'novellist'){
|
if(db.aiModel === 'novellist'){
|
||||||
return await tokenizeTransformers('naclbit/trin_tokenizer_v3',data)
|
return await tokenizeWebTokenizers(data, 'novellist')
|
||||||
|
}
|
||||||
|
if(db.aiModel.startsWith('claude')){
|
||||||
|
return await tokenizeWebTokenizers(data, 'claude')
|
||||||
}
|
}
|
||||||
return await tikJS(data)
|
return await tikJS(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tokenizerType = 'novellist'|'claude'
|
||||||
|
|
||||||
let tikParser:Tiktoken = null
|
let tikParser:Tiktoken = null
|
||||||
|
let tokenizersTokenizer:Tokenizer = null
|
||||||
|
let tokenizersType:tokenizerType = null
|
||||||
|
|
||||||
async function tikJS(text:string) {
|
async function tikJS(text:string) {
|
||||||
if(!tikParser){
|
if(!tikParser){
|
||||||
@@ -28,6 +36,24 @@ async function tikJS(text:string) {
|
|||||||
return tikParser.encode(text)
|
return tikParser.encode(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function tokenizeWebTokenizers(text:string, type:tokenizerType) {
|
||||||
|
if(type !== tokenizersType || !tokenizersTokenizer){
|
||||||
|
const webTokenizer = await import('@mlc-ai/web-tokenizers')
|
||||||
|
switch(type){
|
||||||
|
case "novellist":
|
||||||
|
tokenizersTokenizer = await webTokenizer.Tokenizer.fromSentencePiece(
|
||||||
|
await (await fetch("/token/trin/spiece.model")
|
||||||
|
).arrayBuffer())
|
||||||
|
case "claude":
|
||||||
|
tokenizersTokenizer = await webTokenizer.Tokenizer.fromJSON(
|
||||||
|
await (await fetch("/token/claude/claude.json")
|
||||||
|
).arrayBuffer())
|
||||||
|
}
|
||||||
|
tokenizersType = type
|
||||||
|
}
|
||||||
|
return (tokenizersTokenizer.encode(text))
|
||||||
|
}
|
||||||
|
|
||||||
export async function tokenizerChar(char:character) {
|
export async function tokenizerChar(char:character) {
|
||||||
const encoded = await encode(char.name + '\n' + char.firstMessage + '\n' + char.desc)
|
const encoded = await encode(char.name + '\n' + char.firstMessage + '\n' + char.desc)
|
||||||
return encoded.length
|
return encoded.length
|
||||||
|
|||||||
Reference in New Issue
Block a user