Download src/lib/utils/getTokenizer.ts from WOosts/chat-ui: direct link, hf CLI and curl.
- Browser
- Download file 753 Bytes
-
https://huggingface.co/spaces/WOosts/chat-ui/resolve/main/src/lib/utils/getTokenizer.ts
- Command line
-
hf download hf://spaces/WOosts/chat-ui/src/lib/utils/getTokenizer.ts
-
curl -L -o getTokenizer.ts https://huggingface.co/spaces/WOosts/chat-ui/resolve/main/src/lib/utils/getTokenizer.ts
753 Bytes
| import type { Model } from "$lib/types/Model"; | |
| import { AutoTokenizer, PreTrainedTokenizer } from "@xenova/transformers"; | |
| export async function getTokenizer(_modelTokenizer: Exclude<Model["tokenizer"], undefined>) { | |
| if (typeof _modelTokenizer === "string") { | |
| // return auto tokenizer | |
| return await AutoTokenizer.from_pretrained(_modelTokenizer); | |
| } else { | |
| // construct & return pretrained tokenizer | |
| const { tokenizerUrl, tokenizerConfigUrl } = _modelTokenizer satisfies { | |
| tokenizerUrl: string; | |
| tokenizerConfigUrl: string; | |
| }; | |
| const tokenizerJSON = await (await fetch(tokenizerUrl)).json(); | |
| const tokenizerConfig = await (await fetch(tokenizerConfigUrl)).json(); | |
| return new PreTrainedTokenizer(tokenizerJSON, tokenizerConfig); | |
| } | |
| } | |