Skip to content
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

Fixed 4o models getting counted as GPT-4 models #68

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
3 changes: 3 additions & 0 deletions tests/test_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
("gpt-4-32k-0314", 15),
("gpt-4-1106-preview", 15),
("gpt-4-vision-preview", 15),
("gpt-4o", 15),
],
)
def test_count_message_tokens(model, expected_output):
Expand All @@ -69,6 +70,7 @@ def test_count_message_tokens(model, expected_output):
("gpt-4-32k-0314", 17),
("gpt-4-1106-preview", 17),
("gpt-4-vision-preview", 17),
("gpt-4o", 17),
],
)
def test_count_message_tokens_with_name(model, expected_output):
Expand Down Expand Up @@ -108,6 +110,7 @@ def test_count_message_tokens_invalid_model():
("gpt-4-1106-preview", 4),
("gpt-4-vision-preview", 4),
("text-embedding-ada-002", 4),
("gpt-4o", 4)
],
)
def test_count_string_tokens(model, expected_output):
Expand Down
8 changes: 8 additions & 0 deletions tokencost/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def count_message_tokens(messages: List[Dict[str, str]], model: str) -> int:
"gpt-4-32k-0314",
"gpt-4-0613",
"gpt-4-32k-0613",
"gpt-4-turbo",
"gpt-4-turbo-2024-04-09",
"gpt-4o",
"gpt-4o-2024-05-13",
}:
tokens_per_message = 3
tokens_per_name = 1
Expand All @@ -63,6 +67,10 @@ def count_message_tokens(messages: List[Dict[str, str]], model: str) -> int:
"gpt-3.5-turbo may update over time. Returning num tokens assuming gpt-3.5-turbo-0613."
)
return count_message_tokens(messages, model="gpt-3.5-turbo-0613")
elif "gpt-4o" in model:
print(
"Warning: gpt-4o may update over time. Returning num tokens assuming gpt-4o-2024-05-13.")
return count_message_tokens(messages, model="gpt-4o-2024-05-13")
elif "gpt-4" in model:
logger.warning(
"gpt-4 may update over time. Returning num tokens assuming gpt-4-0613."
Expand Down
Loading