Skip to content

Commit b8da2e9

Browse files
Reformatting, improve docstring and fixing type hints for python < 3.12
1 parent 619626d commit b8da2e9

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

src/agentlab/analyze/inspect_results.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ def summarize(sub_df):
276276
if "stats.cum_cost" in sub_df:
277277
record["cum_cost"] = sub_df["stats.cum_cost"].sum(skipna=True).round(4)
278278
if "stats.cum_effective_cost" in sub_df:
279-
record["cum_effective_cost"] = sub_df["stats.cum_effective_cost"].sum(skipna=True).round(4)
279+
record["cum_effective_cost"] = (
280+
sub_df["stats.cum_effective_cost"].sum(skipna=True).round(4)
281+
)
280282
record.pop("cum_cost", None)
281283

282284
return pd.Series(record)

src/agentlab/llm/response_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"""
2727

2828

29-
type ContentItem = Dict[str, Any]
30-
type Message = Dict[str, Union[str, List[ContentItem]]]
29+
ContentItem = Dict[str, Any]
30+
Message = Dict[str, Union[str, List[ContentItem]]]
3131

3232

3333
@dataclass

src/agentlab/llm/tracking.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def __call__(self, *args, **kwargs):
173173
def fetch_pricing_information_from_provider(self) -> Optional[dict]:
174174
"""
175175
Fetch the pricing information dictionary for the given provider.
176-
Returns a dict mapping model names to pricing info, or None if not found.
176+
177+
Returns:
178+
Optional[dict]: A dict mapping model names to pricing info, or None if not found.
177179
"""
178180
pricing_fn_map = {
179181
"openai": get_pricing_openai,
@@ -248,11 +250,19 @@ def get_effective_cost(self, response):
248250
)
249251
return 0.0
250252

251-
def get_effective_cost_from_antrophic_api(self, response):
252-
"""Get the effective cost from the Anthropic API response.
253-
## Anthropic usage 'input_tokens' are new input tokens (tokens that are not cached).
254-
## Anthorphic has different pricing for cache write and cache read tokens.
255-
## See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#tracking-cache-performance
253+
def get_effective_cost_from_antrophic_api(self, response) -> float:
254+
"""
255+
Get the effective cost from the Anthropic API response.
256+
257+
Anthropic usage 'input_tokens' are new input tokens (tokens that are not cached).
258+
Anthropic has different pricing for cache write and cache read tokens.
259+
See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#tracking-cache-performance
260+
261+
Args:
262+
response: The response object from the Anthropic API.
263+
264+
Returns:
265+
float: The effective cost calculated from the response.
256266
"""
257267
usage = getattr(response, "usage", {})
258268
new_input_tokens = getattr(usage, "input_tokens", 0) # new input tokens
@@ -272,13 +282,21 @@ def get_effective_cost_from_antrophic_api(self, response):
272282
)
273283
return effective_cost
274284

275-
def get_effective_cost_from_openai_api(self, response):
276-
"""Get the effective cost from the OpenAI API response.
277-
## OpenAI usage 'prompt_tokens' are the total input tokens (cache read tokens + new input tokens).
278-
## See https://openai.com/index/api-prompt-caching/
279-
## OpenAI has only one price for cache tokens i.e. cache read price. (Generally 50% cheaper)
280-
## OpenAI had no extra charge for cache write tokens.
281-
## See Pricing Here: https://platform.openai.com/docs/pricing
285+
def get_effective_cost_from_openai_api(self, response) -> float:
286+
"""
287+
Get the effective cost from the OpenAI API response.
288+
289+
OpenAI usage 'prompt_tokens' are the total input tokens (cache read tokens + new input tokens).
290+
See https://openai.com/index/api-prompt-caching/
291+
OpenAI has only one price for cache tokens, i.e., cache read price (generally 50% cheaper).
292+
OpenAI has no extra charge for cache write tokens.
293+
See Pricing Here: https://platform.openai.com/docs/pricing
294+
295+
Args:
296+
response: The response object from the OpenAI API.
297+
298+
Returns:
299+
float: The effective cost calculated from the response.
282300
"""
283301
usage = getattr(response, "usage", {})
284302
prompt_token_details = getattr(response, "prompt_tokens_details", {})

0 commit comments

Comments
 (0)