| 1 | import { GPTAsyncEncoder, LlamaAsyncEncoder } from "./asyncEncoder"; |
| 2 | |
| 3 | describe("llama encoder", () => { |
| 4 | var tokenizer: LlamaAsyncEncoder; |
| 5 | |
| 6 | beforeAll(() => { |
| 7 | tokenizer = new LlamaAsyncEncoder(); |
| 8 | }); |
| 9 | |
| 10 | afterAll(() => { |
| 11 | tokenizer.close().catch((e) => {}); |
| 12 | }); |
| 13 | |
| 14 | test("hello world", async () => { |
| 15 | const input = "the quick brown fox jumped over the lazy dog"; |
| 16 | const output = await tokenizer.encode(input); |
| 17 | expect(output).toEqual([ |
| 18 | 1, 278, 4996, 17354, 1701, 29916, 12500, 287, 975, 278, 17366, 11203, |
| 19 | ]); |
| 20 | const decoded = await tokenizer.decode(output); |
| 21 | expect(decoded).toBe(input); |
| 22 | }); |
| 23 | }); |
| 24 | |
| 25 | describe("tiktoken encoder", () => { |
| 26 | var tokenizer: GPTAsyncEncoder; |
| 27 | |
| 28 | beforeAll(() => { |
| 29 | tokenizer = new GPTAsyncEncoder(); |
| 30 | }); |
| 31 | |
| 32 | afterAll(() => { |
| 33 | tokenizer.close().catch((e) => {}); |
| 34 | }); |
| 35 | |
| 36 | test("hello world", async () => { |
| 37 | const input = "the quick brown fox jumped over the lazy dog"; |
| 38 | const output = await tokenizer.encode(input); |
| 39 | expect(output).toEqual([ |
| 40 | 1820, 4062, 14198, 39935, 27096, 927, 279, 16053, 5679, |
| 41 | ]); |
| 42 | const decoded = await tokenizer.decode(output); |
| 43 | expect(decoded).toBe(input); |
| 44 | }); |
| 45 | }); |