-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for gpt-4o * Make case insensitive matching because javascript doesn't support (?i: ...) inline modifier for case insensitivity
- Loading branch information
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import * as assert from "assert"; | ||
import * as fs from "fs"; | ||
import { suite, before } from "mocha"; | ||
import { createByModelName } from "../src/tokenizerBuilder"; | ||
import { TikTokenizer } from "../src/tikTokenizer"; | ||
const ENDOFTEXT: string = "<|endoftext|>"; | ||
const ENDOFPROMPT: string = "<|endofprompt|>"; | ||
const specialTokens: ReadonlyMap<string, number> = new Map([ | ||
[ENDOFTEXT, 199999], | ||
[ENDOFPROMPT, 200018] | ||
]); | ||
|
||
suite("TikTokenizer gpt-4o Test Suite", function() { | ||
let tokenizer_gpt4o: TikTokenizer; | ||
before(async () => { | ||
tokenizer_gpt4o = await createByModelName("gpt-4o", specialTokens); | ||
}); | ||
|
||
test("tokenize source code - gpt-4o", done => { | ||
const source = fs.readFileSync("test/testdata/lib.rs.txt", "utf8"); | ||
const filePath = "test/testdata/tokens_gpt_4o.json"; | ||
|
||
fs.readFile(filePath, "utf8", (err, data) => { | ||
assert.strictEqual(err, null); | ||
const jsonArray = JSON.parse(data) as Array<number>; | ||
let encoded = tokenizer_gpt4o.encode( | ||
source, | ||
Array.from(specialTokens.keys()) | ||
); | ||
assert.deepStrictEqual(encoded.length, 5609); | ||
assert.deepStrictEqual(encoded, jsonArray); | ||
assert.strictEqual(tokenizer_gpt4o.decode(encoded), source); | ||
done(); | ||
}); | ||
}); | ||
}); |