Skip to content

Updated get_max_token_limit with latest models and numbers #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions autogen/token_count_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@
import logging
import json
import tiktoken
import re


logger = logging.getLogger(__name__)


def get_max_token_limit(model="gpt-3.5-turbo-0613"):
# Handle common azure model names/aliases
model = re.sub(r"^gpt\-?35", "gpt-3.5", model)
model = re.sub(r"^gpt4", "gpt-4", model)

max_token_limit = {
"gpt-3.5-turbo": 4096,
"gpt-3.5-turbo-0301": 4096,
"gpt-3.5-turbo-0613": 4096,
"gpt-3.5-turbo-instruct": 4096,
"gpt-3.5-turbo-16k": 16384,
"gpt-35-turbo": 4096,
"gpt-35-turbo-16k": 16384,
"gpt-35-turbo-instruct": 4096,
"gpt-3.5-turbo-16k": 16385,
"gpt-3.5-turbo-16k-0613": 16385,
"gpt-3.5-turbo-1106": 16385,
"gpt-4": 8192,
"gpt-4-32k": 32768,
"gpt-4-32k-0314": 32768, # deprecate in Sep
"gpt-4-0314": 8192, # deprecate in Sep
"gpt-4-0613": 8192,
"gpt-4-32k-0613": 32768,
"gpt-4-1106-preview": 128000,
"gpt-4-vision-preview": 128000,
}
return max_token_limit[model]

Expand Down
20 changes: 17 additions & 3 deletions test/test_token_count.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from autogen.token_count_utils import count_token, num_tokens_from_functions, token_left, percentile_used
from autogen.token_count_utils import (
count_token,
num_tokens_from_functions,
token_left,
percentile_used,
get_max_token_limit,
)
import pytest

func1 = {
Expand Down Expand Up @@ -67,6 +73,14 @@ def test_count_token():
assert percentile_used(text) == 10 / 4096


def test_model_aliases():
assert get_max_token_limit("gpt35-turbo") == get_max_token_limit("gpt-3.5-turbo")
assert get_max_token_limit("gpt-35-turbo") == get_max_token_limit("gpt-3.5-turbo")
assert get_max_token_limit("gpt4") == get_max_token_limit("gpt-4")
assert get_max_token_limit("gpt4-32k") == get_max_token_limit("gpt-4-32k")


if __name__ == "__main__":
test_num_tokens_from_functions()
test_count_token()
# test_num_tokens_from_functions()
# test_count_token()
test_model_aliases()