Mirrowel commited on
Commit
3962356
·
1 Parent(s): 39e01ca

refactor(core): 🔨 use static class attribute for provider skipping flag

Browse files

Convert `DynamicOpenAICompatibleProvider.skip_cost_calculation` from an instance method to a static class attribute.

This allows the `UsageManager` to check the property directly against the provider class definition via `getattr`, avoiding unnecessary method overhead and potential instantiation checks for a simple flag.

src/rotator_library/providers/__init__.py CHANGED
@@ -16,6 +16,9 @@ class DynamicOpenAICompatibleProvider:
16
  Created at runtime for providers with API_BASE environment variables.
17
  """
18
 
 
 
 
19
  def __init__(self, provider_name: str):
20
  self.provider_name = provider_name
21
  # Get API base URL from environment
@@ -30,10 +33,6 @@ class DynamicOpenAICompatibleProvider:
30
 
31
  self.model_definitions = ModelDefinitions()
32
 
33
- def skip_cost_calculation(self) -> bool:
34
- """Custom providers should skip cost calculation."""
35
- return True
36
-
37
  def get_models(self, api_key: str, client):
38
  """Delegate to OpenAI-compatible provider implementation."""
39
  from .openai_compatible_provider import OpenAICompatibleProvider
 
16
  Created at runtime for providers with API_BASE environment variables.
17
  """
18
 
19
+ # Class attribute - no need to instantiate
20
+ skip_cost_calculation: bool = True
21
+
22
  def __init__(self, provider_name: str):
23
  self.provider_name = provider_name
24
  # Get API base URL from environment
 
33
 
34
  self.model_definitions = ModelDefinitions()
35
 
 
 
 
 
36
  def get_models(self, api_key: str, client):
37
  """Delegate to OpenAI-compatible provider implementation."""
38
  from .openai_compatible_provider import OpenAICompatibleProvider
src/rotator_library/usage_manager.py CHANGED
@@ -344,7 +344,10 @@ class UsageManager:
344
  provider_name = model.split("/")[0]
345
  provider_plugin = PROVIDER_PLUGINS.get(provider_name)
346
 
347
- if provider_plugin and provider_plugin.skip_cost_calculation():
 
 
 
348
  lib_logger.debug(
349
  f"Skipping cost calculation for provider '{provider_name}' (custom provider)."
350
  )
 
344
  provider_name = model.split("/")[0]
345
  provider_plugin = PROVIDER_PLUGINS.get(provider_name)
346
 
347
+ # Check class attribute directly - no need to instantiate
348
+ if provider_plugin and getattr(
349
+ provider_plugin, "skip_cost_calculation", False
350
+ ):
351
  lib_logger.debug(
352
  f"Skipping cost calculation for provider '{provider_name}' (custom provider)."
353
  )