Spaces:
Paused
Paused
Mirrowel commited on
Commit ·
f00537a
1
Parent(s): ed1b48f
refactor(core): resolve model id early to ensure consistent model usage
Browse filesResolve `Attempted to release credential ...... for model..., but it was not in use.`
Move model ID resolution out of the credential rotation loops so the model is resolved once before any credential operations. This ensures a single canonical model ID is used for acquisition, release, and logging, and eliminates redundant per-iteration resolution.
- Call self._resolve_model_id(...) before the main rotation and retry loops.
- Log when a resolution occurs and update kwargs['model'] so downstream calls use the resolved ID.
- Remove duplicate in-loop resolution and related updates/comments.
This improves consistency and reduces redundant work during rotation.
- src/rotator_library/client.py +21 -14
src/rotator_library/client.py
CHANGED
|
@@ -636,6 +636,15 @@ class RotatingClient:
|
|
| 636 |
kwargs = self._convert_model_params(**kwargs)
|
| 637 |
|
| 638 |
# The main rotation loop. It continues as long as there are untried credentials and the global deadline has not been exceeded.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 639 |
while (
|
| 640 |
len(tried_creds) < len(credentials_for_provider) and time.time() < deadline
|
| 641 |
):
|
|
@@ -689,13 +698,8 @@ class RotatingClient:
|
|
| 689 |
|
| 690 |
provider_plugin = self._get_provider_instance(provider)
|
| 691 |
|
| 692 |
-
#
|
| 693 |
-
|
| 694 |
-
if resolved_model != model:
|
| 695 |
-
lib_logger.info(f"Resolved model '{model}' to '{resolved_model}'")
|
| 696 |
-
litellm_kwargs["model"] = resolved_model
|
| 697 |
-
# Update the model variable for subsequent logging
|
| 698 |
-
model = resolved_model
|
| 699 |
|
| 700 |
# Apply model-specific options for custom providers
|
| 701 |
if provider_plugin and hasattr(provider_plugin, "get_model_options"):
|
|
@@ -996,6 +1000,14 @@ class RotatingClient:
|
|
| 996 |
|
| 997 |
consecutive_quota_failures = 0
|
| 998 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 999 |
try:
|
| 1000 |
while (
|
| 1001 |
len(tried_creds) < len(credentials_for_provider)
|
|
@@ -1071,13 +1083,8 @@ class RotatingClient:
|
|
| 1071 |
|
| 1072 |
provider_plugin = self._get_provider_instance(provider)
|
| 1073 |
|
| 1074 |
-
#
|
| 1075 |
-
|
| 1076 |
-
if resolved_model != model:
|
| 1077 |
-
lib_logger.info(f"Resolved model '{model}' to '{resolved_model}'")
|
| 1078 |
-
litellm_kwargs["model"] = resolved_model
|
| 1079 |
-
# Update the model variable for subsequent logging
|
| 1080 |
-
model = resolved_model
|
| 1081 |
|
| 1082 |
# Apply model-specific options for custom providers
|
| 1083 |
if provider_plugin and hasattr(
|
|
|
|
| 636 |
kwargs = self._convert_model_params(**kwargs)
|
| 637 |
|
| 638 |
# The main rotation loop. It continues as long as there are untried credentials and the global deadline has not been exceeded.
|
| 639 |
+
|
| 640 |
+
# Resolve model ID early, before any credential operations
|
| 641 |
+
# This ensures consistent model ID usage for acquisition, release, and tracking
|
| 642 |
+
resolved_model = self._resolve_model_id(model, provider)
|
| 643 |
+
if resolved_model != model:
|
| 644 |
+
lib_logger.info(f"Resolved model '{model}' to '{resolved_model}'")
|
| 645 |
+
model = resolved_model
|
| 646 |
+
kwargs["model"] = model # Ensure kwargs has the resolved model for litellm
|
| 647 |
+
|
| 648 |
while (
|
| 649 |
len(tried_creds) < len(credentials_for_provider) and time.time() < deadline
|
| 650 |
):
|
|
|
|
| 698 |
|
| 699 |
provider_plugin = self._get_provider_instance(provider)
|
| 700 |
|
| 701 |
+
# Model ID is already resolved before the loop, and kwargs['model'] is updated.
|
| 702 |
+
# No further resolution needed here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
|
| 704 |
# Apply model-specific options for custom providers
|
| 705 |
if provider_plugin and hasattr(provider_plugin, "get_model_options"):
|
|
|
|
| 1000 |
|
| 1001 |
consecutive_quota_failures = 0
|
| 1002 |
|
| 1003 |
+
# Resolve model ID early, before any credential operations
|
| 1004 |
+
# This ensures consistent model ID usage for acquisition, release, and tracking
|
| 1005 |
+
resolved_model = self._resolve_model_id(model, provider)
|
| 1006 |
+
if resolved_model != model:
|
| 1007 |
+
lib_logger.info(f"Resolved model '{model}' to '{resolved_model}'")
|
| 1008 |
+
model = resolved_model
|
| 1009 |
+
kwargs["model"] = model # Ensure kwargs has the resolved model for litellm
|
| 1010 |
+
|
| 1011 |
try:
|
| 1012 |
while (
|
| 1013 |
len(tried_creds) < len(credentials_for_provider)
|
|
|
|
| 1083 |
|
| 1084 |
provider_plugin = self._get_provider_instance(provider)
|
| 1085 |
|
| 1086 |
+
# Model ID is already resolved before the loop, and kwargs['model'] is updated.
|
| 1087 |
+
# No further resolution needed here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1088 |
|
| 1089 |
# Apply model-specific options for custom providers
|
| 1090 |
if provider_plugin and hasattr(
|