Model\TiktokenTokenizer.cs (66)
1025private static readonly (string Prefix, ModelEncoding Encoding)[] _modelPrefixToEncoding =
1028( "o1-", ModelEncoding.O200kBase ), // e.g. o1-mini
1029( "gpt-4o-", ModelEncoding.O200kBase), // e.g., gpt-4o-2024-05-13
1030( "gpt-4-", ModelEncoding.Cl100kBase), // e.g., gpt-4-0314, etc., plus gpt-4-32k
1031( "gpt-3.5-", ModelEncoding.Cl100kBase), // e.g, gpt-3.5-turbo-0301, -0401, etc.
1032( "gpt-35-", ModelEncoding.Cl100kBase ) // Azure deployment name
1035private static readonly Dictionary<string, ModelEncoding> _modelToEncoding =
1036new Dictionary<string, ModelEncoding>(StringComparer.OrdinalIgnoreCase)
1039{ "gpt-4o", ModelEncoding.O200kBase },
1040{ "o1", ModelEncoding.O200kBase },
1041{ "gpt-4", ModelEncoding.Cl100kBase },
1042{ "gpt-3.5-turbo", ModelEncoding.Cl100kBase },
1043{ "gpt-3.5-turbo-16k", ModelEncoding.Cl100kBase },
1044{ "gpt-35", ModelEncoding.Cl100kBase }, // Azure deployment name
1045{ "gpt-35-turbo", ModelEncoding.Cl100kBase }, // Azure deployment name
1046{ "gpt-35-turbo-16k", ModelEncoding.Cl100kBase }, // Azure deployment name
1049{ "text-davinci-003", ModelEncoding.P50kBase },
1050{ "text-davinci-002", ModelEncoding.P50kBase },
1051{ "text-davinci-001", ModelEncoding.R50kBase },
1052{ "text-curie-001", ModelEncoding.R50kBase },
1053{ "text-babbage-001", ModelEncoding.R50kBase },
1054{ "text-ada-001", ModelEncoding.R50kBase },
1055{ "davinci", ModelEncoding.R50kBase },
1056{ "curie", ModelEncoding.R50kBase },
1057{ "babbage", ModelEncoding.R50kBase },
1058{ "ada", ModelEncoding.R50kBase },
1061{ "code-davinci-002", ModelEncoding.P50kBase },
1062{ "code-davinci-001", ModelEncoding.P50kBase },
1063{ "code-cushman-002", ModelEncoding.P50kBase },
1064{ "code-cushman-001", ModelEncoding.P50kBase },
1065{ "davinci-codex", ModelEncoding.P50kBase },
1066{ "cushman-codex", ModelEncoding.P50kBase },
1069{ "text-davinci-edit-001", ModelEncoding.P50kEdit },
1070{ "code-davinci-edit-001", ModelEncoding.P50kEdit },
1074{ "text-embedding-ada-002", ModelEncoding.Cl100kBase },
1075{ "text-embedding-3-small", ModelEncoding.Cl100kBase },
1076{ "text-embedding-3-large", ModelEncoding.Cl100kBase },
1079{ "text-similarity-davinci-001", ModelEncoding.R50kBase },
1080{ "text-similarity-curie-001", ModelEncoding.R50kBase },
1081{ "text-similarity-babbage-001", ModelEncoding.R50kBase },
1082{ "text-similarity-ada-001", ModelEncoding.R50kBase },
1083{ "text-search-davinci-doc-001", ModelEncoding.R50kBase },
1084{ "text-search-curie-doc-001", ModelEncoding.R50kBase },
1085{ "text-search-babbage-doc-001", ModelEncoding.R50kBase },
1086{ "text-search-ada-doc-001", ModelEncoding.R50kBase },
1087{ "code-search-babbage-code-001", ModelEncoding.R50kBase },
1088{ "code-search-ada-code-001", ModelEncoding.R50kBase },
1091{ "gpt2", ModelEncoding.GPT2 }
1094private static ModelEncoding GetModelEncoding(string modelName)
1096if (!_modelToEncoding.TryGetValue(modelName, out ModelEncoding encoder))
1098foreach ((string Prefix, ModelEncoding Encoding) in _modelPrefixToEncoding)
1108if (encoder == ModelEncoding.None)
1118private static (Dictionary<string, int> SpecialTokens, Regex Regex, string VocabFile, Type? DataType, string PackageName) GetTiktokenConfigurations(ModelEncoding modelEncoding, string? modelName = null)
1122case ModelEncoding.Cl100kBase:
1126case ModelEncoding.GPT2:
1129case ModelEncoding.O200kBase:
1132case ModelEncoding.P50kBase:
1135case ModelEncoding.P50kEdit:
1139case ModelEncoding.R50kBase:
1204ModelEncoding modelEncoding,
1450ModelEncoding modelEncoding;
1453modelEncoding = ModelEncoding.Cl100kBase;
1457modelEncoding = ModelEncoding.O200kBase;
1461modelEncoding = ModelEncoding.P50kBase;
1465modelEncoding = ModelEncoding.P50kEdit;
1469modelEncoding = ModelEncoding.R50kBase;