| 9 | } |
| 10 | |
| 11 | export class LlamaAsyncEncoder implements AsyncEncoder { |
| 12 | private workerPool: workerpool.Pool; |
| 13 | |
| 14 | constructor() { |
| 15 | this.workerPool = workerpool.pool( |
| 16 | workerCodeFilePath("llamaTokenizerWorkerPool.mjs"), |
| 17 | ); |
| 18 | } |
| 19 | |
| 20 | async encode(text: string): Promise<number[]> { |
| 21 | return this.workerPool.exec("encode", [text]); |
| 22 | } |
| 23 | |
| 24 | async decode(tokens: number[]): Promise<string> { |
| 25 | return this.workerPool.exec("decode", [tokens]); |
| 26 | } |
| 27 | |
| 28 | // TODO: this should be called somewhere before exit or potentially with a shutdown hook |
| 29 | public async close(): Promise<void> { |
| 30 | await this.workerPool.terminate(); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // this class does not yet do anything asynchronous |
| 35 | export class GPTAsyncEncoder implements AsyncEncoder { |
nothing calls this directly
no outgoing calls
no test coverage detected