crewplus 0.2.29__py3-none-any.whl → 0.2.30__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of crewplus might be problematic. Click here for more details.

@@ -76,21 +76,23 @@ class ModelLoadBalancer:
76
76
  self.logger.error(f"Failed to load model configuration: {e}", exc_info=True)
77
77
  raise RuntimeError(f"Failed to load model configuration: {e}")
78
78
 
79
- def get_model(self, provider: str = None, model_type: str = None, deployment_name: str = None, with_metadata: bool = False):
79
+ def get_model(self, provider: str = None, model_type: str = None, deployment_name: str = None, with_metadata: bool = False, selection_strategy: str = 'random'):
80
80
  """
81
81
  Get a model instance.
82
82
 
83
83
  Can fetch a model in two ways:
84
84
  1. By its specific `deployment_name`.
85
- 2. By `provider` and `model_type`, which will select a model using round-robin.
85
+ 2. By `provider` and `model_type`, which will select a model using a specified strategy.
86
86
 
87
87
  Args:
88
88
  provider: The model provider (e.g., 'azure-openai', 'google-genai').
89
89
  model_type: The type of model (e.g., 'inference', 'embedding', 'embedding-large').
90
90
  deployment_name: The unique name for the model deployment.
91
+ with_metadata: If True, returns a tuple of (model, deployment_name).
92
+ selection_strategy: The selection strategy ('random', 'round_robin', or 'least_used'). Defaults to 'random'.
91
93
 
92
94
  Returns:
93
- An instantiated language model object.
95
+ An instantiated language model object, or a tuple if with_metadata is True.
94
96
 
95
97
  Raises:
96
98
  RuntimeError: If the model configuration has not been loaded.
@@ -118,7 +120,16 @@ class ModelLoadBalancer:
118
120
  self.logger.error(f"No models found for provider '{provider}' and type '{model_type}'")
119
121
  raise ValueError(f"No models found for provider '{provider}' and type '{model_type}'")
120
122
 
121
- selected_model_config = self._round_robin_selection(candidates)
123
+ if selection_strategy == 'random':
124
+ selected_model_config = self._random_selection(candidates)
125
+ elif selection_strategy == 'round_robin':
126
+ selected_model_config = self._round_robin_selection(candidates)
127
+ elif selection_strategy == 'least_used':
128
+ selected_model_config = self._least_used_selection(candidates)
129
+ else:
130
+ self.logger.warning(f"Unsupported selection strategy: '{selection_strategy}'. Defaulting to 'random'.")
131
+ selected_model_config = self._random_selection(candidates)
132
+
122
133
  model_id = selected_model_config['id']
123
134
  model = self.models[model_id]
124
135
  if with_metadata:
@@ -186,6 +197,12 @@ class ModelLoadBalancer:
186
197
  self.usage_counter = defaultdict(int)
187
198
  self.current_indices = {}
188
199
 
200
+ def _random_selection(self, candidates: list) -> Dict:
201
+ """Selects a model randomly from a list of candidates."""
202
+ model = random.choice(candidates)
203
+ self.usage_counter[model['id']] += 1
204
+ return model
205
+
189
206
  def _round_robin_selection(self, candidates: list) -> Dict:
190
207
  if id(candidates) not in self.current_indices:
191
208
  self.current_indices[id(candidates)] = 0
@@ -197,8 +214,8 @@ class ModelLoadBalancer:
197
214
  return model
198
215
 
199
216
  def _least_used_selection(self, candidates: list) -> Dict:
200
- min_usage = min(self.usage_counter[m['model_id']] for m in candidates)
201
- least_used = [m for m in candidates if self.usage_counter[m['model_id']] == min_usage]
217
+ min_usage = min(self.usage_counter[m['id']] for m in candidates)
218
+ least_used = [m for m in candidates if self.usage_counter[m['id']] == min_usage]
202
219
  model = random.choice(least_used)
203
220
  self.usage_counter[model['id']] += 1
204
221
  return model
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crewplus
3
- Version: 0.2.29
3
+ Version: 0.2.30
4
4
  Summary: Base services for CrewPlus AI applications
5
5
  Author-Email: Tim Liu <tim@opsmateai.com>
6
6
  License: MIT
@@ -1,13 +1,13 @@
1
- crewplus-0.2.29.dist-info/METADATA,sha256=Gjp8NS1iow7bCkTVYioXaFmWPr6RKFBqiCrMEzTdVJg,5327
2
- crewplus-0.2.29.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- crewplus-0.2.29.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- crewplus-0.2.29.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
1
+ crewplus-0.2.30.dist-info/METADATA,sha256=1Mhnmb9kTEFG0dyGfMTiGaBrNpJxx36lPGg8GmhsmQc,5327
2
+ crewplus-0.2.30.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ crewplus-0.2.30.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ crewplus-0.2.30.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
5
5
  crewplus/__init__.py,sha256=m46HkZL1Y4toD619NL47Sn2Qe084WFFSFD7e6VoYKZc,284
6
6
  crewplus/services/__init__.py,sha256=zUM4ZwUfGMBDx-j7Wehf_KC5yYXPTK8BK_oeO5veIXQ,398
7
7
  crewplus/services/azure_chat_model.py,sha256=WMSf4BDO8UcP7ZASNGRJxdTEnuWBmCRSY_4yx_VMbok,5499
8
8
  crewplus/services/gemini_chat_model.py,sha256=oVLL07VEjwrHOeP56YSPLnldbfjvTVRrsTI6xcPNt1E,35224
9
9
  crewplus/services/init_services.py,sha256=EBpDkIwzuujmdlqjyWvdLQCfhQmfS_OKFz-9Ji8nmAU,1628
10
- crewplus/services/model_load_balancer.py,sha256=meJlmyJoKPXA6AlIYiVJETd8bS6zeaDevMuVLs6LFhk,9715
10
+ crewplus/services/model_load_balancer.py,sha256=2LOiPUslRKreBZTndKOx6WH8VtJT8mep37GsDINQTJs,10780
11
11
  crewplus/services/tracing_manager.py,sha256=aCU9N4Jvh8pDD3h8kWX4O-Ax8xwdLHnQ4wJ3sf-vLwA,6289
12
12
  crewplus/utils/__init__.py,sha256=2Gk1n5srFJQnFfBuYTxktdtKOVZyNrFcNaZKhXk35Pw,142
13
13
  crewplus/utils/schema_action.py,sha256=GDaBoVFQD1rXqrLVSMTfXYW1xcUu7eDcHsn57XBSnIg,422
@@ -20,4 +20,4 @@ docs/GeminiChatModel.md,sha256=zZYyl6RmjZTUsKxxMiC9O4yV70MC4TD-IGUmWhIDBKA,8677
20
20
  docs/ModelLoadBalancer.md,sha256=aGHES1dcXPz4c7Y8kB5-vsCNJjriH2SWmjBkSGoYKiI,4398
21
21
  docs/VDBService.md,sha256=Dw286Rrf_fsi13jyD3Bo4Sy7nZ_G7tYm7d8MZ2j9hxk,9375
22
22
  docs/index.md,sha256=3tlc15uR8lzFNM5WjdoZLw0Y9o1P1gwgbEnOdIBspqc,1643
23
- crewplus-0.2.29.dist-info/RECORD,,
23
+ crewplus-0.2.30.dist-info/RECORD,,