Skip to content

Commit 47916b1

Browse files
authored
Merge pull request #90 from AgentOps-AI/upgrade_pyproject
upgrade version and run black
2 parents abf5e6d + 0bf6df9 commit 47916b1

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tokencost = ["model_prices.json"]
1010

1111
[project]
1212
name = "tokencost"
13-
version = "0.1.16"
13+
version = "0.1.17"
1414
authors = [
1515
{ name = "Trisha Pan", email = "[email protected]" },
1616
{ name = "Alex Reibman", email = "[email protected]" },

tokencost/costs.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,26 @@
1818

1919
def get_anthropic_token_count(messages: List[Dict[str, str]], model: str) -> int:
2020
if not any(
21-
supported_model in model for supported_model in [
22-
"claude-3-5-sonnet", "claude-3-5-haiku", "claude-3-haiku", "claude-3-opus"
21+
supported_model in model
22+
for supported_model in [
23+
"claude-3-5-sonnet",
24+
"claude-3-5-haiku",
25+
"claude-3-haiku",
26+
"claude-3-opus",
2327
]
2428
):
2529
raise ValueError(
2630
f"{model} is not supported in token counting (beta) API. Use the `usage` property in the response for exact counts."
2731
)
2832
try:
29-
return anthropic.Anthropic().beta.messages.count_tokens(
30-
model=model,
31-
messages=messages,
32-
).input_tokens
33+
return (
34+
anthropic.Anthropic()
35+
.beta.messages.count_tokens(
36+
model=model,
37+
messages=messages,
38+
)
39+
.input_tokens
40+
)
3341
except TypeError as e:
3442
raise e
3543
except Exception as e:
@@ -286,9 +294,7 @@ def calculate_all_costs_and_tokens(
286294
)
287295

288296
if "claude-" in model:
289-
logger.warning(
290-
"Warning: Token counting is estimated for "
291-
)
297+
logger.warning("Warning: Token counting is estimated for ")
292298
completion_list = [{"role": "assistant", "content": completion}]
293299
# Anthropic appends some 13 additional tokens to the actual completion tokens
294300
completion_tokens = count_message_tokens(completion_list, model) - 13

0 commit comments

Comments
 (0)