Skip to content

Commit

Permalink
update tiktoken for gpt-4o
Browse files Browse the repository at this point in the history
  • Loading branch information
bearice committed May 15, 2024
1 parent fb1d837 commit 7fbd177
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion utils/server/tiktoken.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import cl100k from 'tiktoken/encoders/cl100k_base.json';
import p50k from 'tiktoken/encoders/p50k_base.json';
import { Tiktoken } from 'tiktoken/lite';
const { encoding_for_model } = require('tiktoken');
import { encoding_for_model } from 'tiktoken';

export const getTiktokenEncoding = async (model: string): Promise<Tiktoken> => {
// Azure fix
const modelId = model.replace('gpt-35', 'gpt-3.5')
if (modelId.indexOf('text-davinci-') !== -1) {
return new Tiktoken(p50k.bpe_ranks, p50k.special_tokens, p50k.pat_str);
}
if (modelId.indexOf('gpt-4o') !== -1) {
return encoding_for_model('gpt-4o');
}
if (modelId.indexOf('gpt-3.5') !== -1) {
return encoding_for_model('gpt-3.5-turbo', {
'<|im_start|>': 100264,
Expand Down

0 comments on commit 7fbd177

Please sign in to comment.