crewplus 0.2.4__py3-none-any.whl → 0.2.6__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.

@@ -3,11 +3,15 @@ from crewplus.services.model_load_balancer import ModelLoadBalancer
3
3
 
4
4
  model_balancer = None
5
5
 
6
- def init_load_balancer():
6
+ def init_load_balancer(config_path: str = None):
7
7
  global model_balancer
8
8
  if model_balancer is None:
9
- config_path = os.getenv("MODEL_CONFIG_PATH", "config/models_config.json")
10
- model_balancer = ModelLoadBalancer(config_path)
9
+ # Use parameter if provided, otherwise check env var, then default
10
+ final_config_path = config_path or os.getenv(
11
+ "MODEL_CONFIG_PATH",
12
+ "config/models_config.json" # Fixed default path
13
+ )
14
+ model_balancer = ModelLoadBalancer(final_config_path)
11
15
  model_balancer.load_config() # Load initial configuration synchronously
12
16
 
13
17
  def get_model_balancer() -> ModelLoadBalancer:
@@ -197,7 +197,7 @@ class VDBService(object):
197
197
  """
198
198
  return self._client
199
199
 
200
- def get_embeddings(self, from_model_balancer: bool = False, model_type: Optional[str] = "embedding-large") -> Embeddings:
200
+ def get_embeddings(self, from_model_balancer: bool = False, provider: Optional[str] = "azure-openai", model_type: Optional[str] = "embedding-large") -> Embeddings:
201
201
  """
202
202
  Gets an embedding function, either from the model balancer or directly from settings.
203
203
 
@@ -211,7 +211,7 @@ class VDBService(object):
211
211
  """
212
212
  if from_model_balancer:
213
213
  model_balancer = get_model_balancer()
214
- return model_balancer.get_model(model_type=model_type)
214
+ return model_balancer.get_model(provider=provider, model_type=model_type)
215
215
 
216
216
  embedder_config = self.settings.get("embedder")
217
217
  if not embedder_config:
@@ -248,8 +248,8 @@ class VDBService(object):
248
248
  def get_vector_store(self, collection_name: str, embeddings: Embeddings = None, metric_type: str = "L2") -> Zilliz:
249
249
  """
250
250
  Gets a vector store instance, creating it if it doesn't exist for the collection.
251
-
252
- This method caches instances by collection name to avoid re-instantiation.
251
+ This method validates both the embedding function and the vector store connection
252
+ before caching the instance to prevent faulty instances from being reused.
253
253
 
254
254
  Args:
255
255
  collection_name (str): The name of the collection in the vector database.
@@ -272,6 +272,19 @@ class VDBService(object):
272
272
  if embeddings is None:
273
273
  embeddings = self.get_embeddings()
274
274
 
275
+ # 1. Validate the embedding function before proceeding.
276
+ try:
277
+ self.logger.debug(f"Testing embedding function for collection '{collection_name}'...")
278
+ embeddings.embed_query("validation_test_string")
279
+ self.logger.debug("Embedding function is valid.")
280
+ except Exception as e:
281
+ self.logger.error(
282
+ f"The provided embedding function is invalid and failed with error: {e}. "
283
+ f"Cannot create a vector store for collection '{collection_name}'."
284
+ )
285
+ raise RuntimeError(f"Invalid embedding function provided.") from e
286
+
287
+ # If embeddings are valid, proceed to create the Zilliz instance.
275
288
  index_params = self.index_params or {
276
289
  "metric_type": metric_type,
277
290
  "index_type": "AUTOINDEX",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crewplus
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Base services for CrewPlus AI applications
5
5
  Author-Email: Tim Liu <tim@opsmateai.com>
6
6
  License: MIT
@@ -1,20 +1,20 @@
1
- crewplus-0.2.4.dist-info/METADATA,sha256=GanuWO7TBC2DPca7TZwW3WtVg7rZXpBQ1hWhM22G_-8,4909
2
- crewplus-0.2.4.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- crewplus-0.2.4.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- crewplus-0.2.4.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
1
+ crewplus-0.2.6.dist-info/METADATA,sha256=EWHY3KjrDXJjYeO-WqNITUVJ_3gzhjMwE6f6trstGD0,4909
2
+ crewplus-0.2.6.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ crewplus-0.2.6.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ crewplus-0.2.6.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
5
5
  crewplus/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  crewplus/services/__init__.py,sha256=MmH2v3N0ZMsuqFNAupkXENjUqvgf5ehQ99H6EzPqLZU,48
7
7
  crewplus/services/gemini_chat_model.py,sha256=i9p5KvSJYaHSUBLPKM_bpyGVLWCDQoNeah_WjQVJRXs,26227
8
- crewplus/services/init_services.py,sha256=5MlvZbyGPNgVA_2bPuxhhbw9TgD5rrvC0e_62YJh340,589
8
+ crewplus/services/init_services.py,sha256=yD6gMbXnHfABa3yBxEYihiq2Kv5zxhBcyK4eNCTAETs,775
9
9
  crewplus/services/model_load_balancer.py,sha256=a2BfcWV-OEItVf7_tTBYY0HiXxFzA5Uk7d-6AG-jLNU,8692
10
10
  crewplus/utils/schema_action.py,sha256=GDaBoVFQD1rXqrLVSMTfXYW1xcUu7eDcHsn57XBSnIg,422
11
11
  crewplus/utils/schema_document_updater.py,sha256=frvffxn2vbi71fHFPoGb9hq7gH2azmmdq17p-Fumnvg,7322
12
12
  crewplus/vectorstores/milvus/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  crewplus/vectorstores/milvus/milvus_schema_manager.py,sha256=qHMVIM0NS3rLfACb8d3-tQS9hJo6_7_YP8AxVx4t1Cc,9019
14
14
  crewplus/vectorstores/milvus/schema_milvus.py,sha256=GhHTtCH5HsIJc3RHa25RXl3aZdkS3Rba5KeuUk_Hi0k,11425
15
- crewplus/vectorstores/milvus/vdb_service.py,sha256=J7B6TOZmJl9_K2euJFKJFvSYqvruKbXuYkFiugWnXXs,16657
15
+ crewplus/vectorstores/milvus/vdb_service.py,sha256=iCiSXcmtpD9tW1WYyJ1P0SRJEFEsUoH3lY65mnwf6R8,17524
16
16
  docs/GeminiChatModel.md,sha256=_IQyup3ofAa2HxfSurO1GYUEezTHYYt5Q1khYNVThGM,8040
17
- docs/ModelLoadBalancer.md,sha256=mgwDtiKBlAJMBhXck97SPahCt395QJzHyrKmxmkfRtw,3082
18
- docs/VDBService.md,sha256=YwYpyYsZ-YkLD8WQjFYAHmEkPmVheTKUEJn0mVqrirA,8945
17
+ docs/ModelLoadBalancer.md,sha256=aGHES1dcXPz4c7Y8kB5-vsCNJjriH2SWmjBkSGoYKiI,4398
18
+ docs/VDBService.md,sha256=Dw286Rrf_fsi13jyD3Bo4Sy7nZ_G7tYm7d8MZ2j9hxk,9375
19
19
  docs/index.md,sha256=3tlc15uR8lzFNM5WjdoZLw0Y9o1P1gwgbEnOdIBspqc,1643
20
- crewplus-0.2.4.dist-info/RECORD,,
20
+ crewplus-0.2.6.dist-info/RECORD,,
docs/ModelLoadBalancer.md CHANGED
@@ -88,3 +88,47 @@ The model `o3mini` is identified by the deployment name `gpt-o3mini-eastus2-RPM2
88
88
  ```python
89
89
  o3mini_model = balancer.get_model(deployment_name="gpt-o3mini-eastus2-RPM25")
90
90
  ```
91
+
92
+ ## 5. Global Access with `init_load_balancer`
93
+
94
+ The `init_load_balancer` function provides a convenient singleton pattern for accessing the `ModelLoadBalancer` throughout your application without passing the instance around.
95
+
96
+ First, you initialize the balancer once at the start of your application.
97
+
98
+ ### Initialization
99
+
100
+ You can initialize it in several ways:
101
+
102
+ **1. Default Initialization**
103
+
104
+ This will look for the `MODEL_CONFIG_PATH` environment variable, or use the default path `_config/models_config.json`.
105
+
106
+ ```python
107
+ from crewplus.services.init_services import init_load_balancer
108
+
109
+ init_load_balancer()
110
+ ```
111
+
112
+ **2. Initialization with a Custom Path**
113
+
114
+ You can also provide a direct path to your configuration file.
115
+
116
+ ```python
117
+ from crewplus.services.init_services import init_load_balancer
118
+
119
+ init_load_balancer(config_path="path/to/your/models_config.json")
120
+ ```
121
+
122
+ ### Getting the Balancer and Models
123
+
124
+ Once initialized, you can retrieve the `ModelLoadBalancer` instance from anywhere in your code using `get_model_balancer`.
125
+
126
+ ```python
127
+ from crewplus.services.init_services import get_model_balancer
128
+
129
+ # Get the balancer instance
130
+ balancer = get_model_balancer()
131
+
132
+ # Get a model by deployment name
133
+ gemini_flash_model = balancer.get_model(deployment_name="gemini-2.5-flash")
134
+ ```
docs/VDBService.md CHANGED
@@ -60,6 +60,20 @@ vdb_service = VDBService(settings=settings)
60
60
  print("VDBService initialized successfully!")
61
61
  ```
62
62
 
63
+ **Alternative Initialization for Zilliz**
64
+
65
+ For a simpler Zilliz Cloud connection, you can initialize the service directly with your endpoint and token.
66
+
67
+ ```python
68
+ # Initialize directly with Zilliz credentials
69
+ vdb_service_zilliz = VDBService(
70
+ endpoint="YOUR_ZILLIZ_ENDPOINT",
71
+ token="YOUR_ZILLIZ_TOKEN"
72
+ )
73
+
74
+ print("VDBService for Zilliz initialized successfully!")
75
+ ```
76
+
63
77
  ## 3. Usage Examples
64
78
 
65
79
  ### Basic Usage: Get Vector Store with Default Embeddings
@@ -86,7 +100,8 @@ This requires the `ModelLoadBalancer` to have been initialized, as shown in the
86
100
  # 1. Get a specific embedding model from the ModelLoadBalancer
87
101
  # The service will call get_model_balancer() internally to get the initialized instance.
88
102
  embedding_model = vdb_service.get_embeddings(
89
- from_model_balancer=True,
103
+ from_model_balancer=True,
104
+ provider="azure-openai-embeddings",
90
105
  model_type="embedding-large" # Specify the model type configured in the balancer
91
106
  )
92
107