Skip to content

Commit 3c66d8b

Browse files
removed unused code
1 parent edf953a commit 3c66d8b

File tree

2 files changed

+0
-31
lines changed

2 files changed

+0
-31
lines changed

src/openlayer/lib/integrations/portkey_tracer.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ def extract_usage(obj: Any) -> Dict[str, Optional[int]]:
532532
This function attempts to extract token usage information from various
533533
locations where it might be stored, including:
534534
- Direct `usage` attribute
535-
- `_hidden_params` (for streaming chunks)
536535
- `model_dump()` dictionary (for streaming chunks)
537536
538537
Parameters
@@ -556,27 +555,6 @@ def extract_usage(obj: Any) -> Dict[str, Optional[int]]:
556555
"completion_tokens": getattr(usage, "completion_tokens", None),
557556
}
558557

559-
# Check for usage in _hidden_params (primarily for streaming chunks)
560-
if hasattr(obj, "_hidden_params"):
561-
hidden_params = obj._hidden_params
562-
# Check if usage is a direct attribute
563-
if hasattr(hidden_params, "usage") and hidden_params.usage is not None:
564-
usage = hidden_params.usage
565-
return {
566-
"total_tokens": getattr(usage, "total_tokens", None),
567-
"prompt_tokens": getattr(usage, "prompt_tokens", None),
568-
"completion_tokens": getattr(usage, "completion_tokens", None),
569-
}
570-
# Check if usage is a dictionary key
571-
elif _supports_membership_check(hidden_params) and "usage" in hidden_params:
572-
usage = hidden_params["usage"]
573-
if usage:
574-
return {
575-
"total_tokens": usage.get("total_tokens", None),
576-
"prompt_tokens": usage.get("prompt_tokens", None),
577-
"completion_tokens": usage.get("completion_tokens", None),
578-
}
579-
580558
# Check if object model dump has usage (primarily for streaming chunks)
581559
if hasattr(obj, "model_dump"):
582560
obj_dict = obj.model_dump()

tests/test_portkey_integration.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,6 @@ def test_extract_usage_from_chunk(self) -> None:
230230
"completion_tokens": 80,
231231
}
232232

233-
chunk_hidden = SimpleNamespace(
234-
_hidden_params={"usage": {"total_tokens": 30, "prompt_tokens": 10, "completion_tokens": 20}}
235-
)
236-
assert extract_usage(chunk_hidden) == {
237-
"total_tokens": 30,
238-
"prompt_tokens": 10,
239-
"completion_tokens": 20,
240-
}
241-
242233
class ChunkWithModelDump: # pylint: disable=too-few-public-methods
243234
def model_dump(self) -> Dict[str, Any]:
244235
return {"usage": {"total_tokens": 12, "prompt_tokens": 5, "completion_tokens": 7}}

0 commit comments

Comments
 (0)