Skip to content

Commit

Permalink
Merge pull request #601 from roboflow/usage-collector-fallback-api-ke…
Browse files Browse the repository at this point in the history
…y-extraction

Fallback API key extraction for UsageCollector
  • Loading branch information
grzegorz-roboflow committed Aug 22, 2024
2 parents d3be171 + bcf8bc3 commit bbf64e1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion inference/usage_tracking/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
List,
Optional,
ParamSpec,
Tuple,
TypeVar,
)

Expand Down Expand Up @@ -593,6 +592,23 @@ def _extract_usage_params_from_func_kwargs(
source = image.get("value")
elif hasattr(image, "_image_reference"):
source = image._image_reference

if not usage_api_key:
_self = func_kwargs.get("self")
if "api_key" in func_kwargs and func_kwargs["api_key"]:
usage_api_key = func_kwargs["api_key"]
elif _self and hasattr(_self, "api_key") and _self.api_key:
usage_api_key = _self.api_key
elif (
"kwargs" in func_kwargs
and isinstance(func_kwargs["kwargs"], dict)
and "api_key" in func_kwargs["kwargs"]
and func_kwargs["kwargs"]["api_key"]
):
usage_api_key = func_kwargs["kwargs"]["api_key"]
else:
logger.debug("Could not obtain API key from func kwargs")

return {
"source": source,
"api_key": usage_api_key,
Expand Down

0 comments on commit bbf64e1

Please sign in to comment.