|
11 | 11 | import requests |
12 | 12 | from langchain_community.callbacks import bedrock_anthropic_callback, openai_info |
13 | 13 |
|
14 | | - |
15 | 14 | TRACKER = threading.local() |
16 | 15 |
|
17 | 16 | ANTHROPHIC_CACHE_PRICING_FACTOR = { |
@@ -207,9 +206,7 @@ def update_pricing_tracker(self, raw_response) -> None: |
207 | 206 | input_tokens, output_tokens = self.get_tokens_counts_from_response(raw_response) |
208 | 207 | cost = input_tokens * self.input_cost + output_tokens * self.output_cost |
209 | 208 |
|
210 | | - if hasattr(TRACKER, "instance") and isinstance( |
211 | | - TRACKER.instance, LLMTracker |
212 | | - ): |
| 209 | + if hasattr(TRACKER, "instance") and isinstance(TRACKER.instance, LLMTracker): |
213 | 210 | TRACKER.instance(input_tokens, output_tokens, cost) |
214 | 211 |
|
215 | 212 | def get_tokens_counts_from_response(self, response) -> tuple: |
@@ -286,7 +283,9 @@ def get_effective_cost_from_openai_api(self, response): |
286 | 283 | usage = getattr(response, "usage", {}) |
287 | 284 | prompt_token_details = getattr(response, "prompt_tokens_details", {}) |
288 | 285 |
|
289 | | - total_input_tokens = getattr(prompt_token_details, "prompt_tokens", 0) # Cache read tokens + new input tokens |
| 286 | + total_input_tokens = getattr( |
| 287 | + prompt_token_details, "prompt_tokens", 0 |
| 288 | + ) # Cache read tokens + new input tokens |
290 | 289 | output_tokens = getattr(usage, "completion_tokens", 0) |
291 | 290 | cache_read_tokens = getattr(prompt_token_details, "cached_tokens", 0) |
292 | 291 |
|
|
0 commit comments