Skip to content

Commit f8af725

Browse files
afourneyqingyun-wu
andauthored
Updated get_max_token_limit with latest models and numbers (microsoft#972)
* Updated with latest models and numbers * Updated as per comments. * Added common Azure deployment names for models. --------- Co-authored-by: Qingyun Wu <[email protected]>
1 parent 50748e4 commit f8af725

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

autogen/token_count_utils.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@
22
import logging
33
import json
44
import tiktoken
5+
import re
56

67

78
logger = logging.getLogger(__name__)
89

910

1011
def get_max_token_limit(model="gpt-3.5-turbo-0613"):
12+
# Handle common azure model names/aliases
13+
model = re.sub(r"^gpt\-?35", "gpt-3.5", model)
14+
model = re.sub(r"^gpt4", "gpt-4", model)
15+
1116
max_token_limit = {
1217
"gpt-3.5-turbo": 4096,
1318
"gpt-3.5-turbo-0301": 4096,
1419
"gpt-3.5-turbo-0613": 4096,
1520
"gpt-3.5-turbo-instruct": 4096,
16-
"gpt-3.5-turbo-16k": 16384,
17-
"gpt-35-turbo": 4096,
18-
"gpt-35-turbo-16k": 16384,
19-
"gpt-35-turbo-instruct": 4096,
21+
"gpt-3.5-turbo-16k": 16385,
22+
"gpt-3.5-turbo-16k-0613": 16385,
23+
"gpt-3.5-turbo-1106": 16385,
2024
"gpt-4": 8192,
2125
"gpt-4-32k": 32768,
2226
"gpt-4-32k-0314": 32768, # deprecate in Sep
2327
"gpt-4-0314": 8192, # deprecate in Sep
2428
"gpt-4-0613": 8192,
2529
"gpt-4-32k-0613": 32768,
30+
"gpt-4-1106-preview": 128000,
31+
"gpt-4-vision-preview": 128000,
2632
}
2733
return max_token_limit[model]
2834

test/test_token_count.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
from autogen.token_count_utils import count_token, num_tokens_from_functions, token_left, percentile_used
1+
from autogen.token_count_utils import (
2+
count_token,
3+
num_tokens_from_functions,
4+
token_left,
5+
percentile_used,
6+
get_max_token_limit,
7+
)
28
import pytest
39

410
func1 = {
@@ -67,6 +73,14 @@ def test_count_token():
6773
assert percentile_used(text) == 10 / 4096
6874

6975

76+
def test_model_aliases():
77+
assert get_max_token_limit("gpt35-turbo") == get_max_token_limit("gpt-3.5-turbo")
78+
assert get_max_token_limit("gpt-35-turbo") == get_max_token_limit("gpt-3.5-turbo")
79+
assert get_max_token_limit("gpt4") == get_max_token_limit("gpt-4")
80+
assert get_max_token_limit("gpt4-32k") == get_max_token_limit("gpt-4-32k")
81+
82+
7083
if __name__ == "__main__":
71-
test_num_tokens_from_functions()
72-
test_count_token()
84+
# test_num_tokens_from_functions()
85+
# test_count_token()
86+
test_model_aliases()

0 commit comments

Comments
 (0)