universal-mcp 0.1.12__py3-none-any.whl → 0.1.13rc2__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.
Files changed (109) hide show
  1. universal_mcp/applications/__init__.py +51 -7
  2. universal_mcp/cli.py +109 -17
  3. universal_mcp/integrations/__init__.py +1 -1
  4. universal_mcp/integrations/integration.py +79 -0
  5. universal_mcp/servers/README.md +79 -0
  6. universal_mcp/servers/server.py +17 -29
  7. universal_mcp/stores/README.md +74 -0
  8. universal_mcp/stores/store.py +0 -2
  9. universal_mcp/templates/README.md.j2 +93 -0
  10. universal_mcp/templates/api_client.py.j2 +27 -0
  11. universal_mcp/tools/README.md +86 -0
  12. universal_mcp/tools/tools.py +1 -1
  13. universal_mcp/utils/agentr.py +90 -0
  14. universal_mcp/utils/api_generator.py +166 -208
  15. universal_mcp/utils/openapi.py +221 -321
  16. universal_mcp/utils/singleton.py +23 -0
  17. {universal_mcp-0.1.12.dist-info → universal_mcp-0.1.13rc2.dist-info}/METADATA +16 -41
  18. universal_mcp-0.1.13rc2.dist-info/RECORD +38 -0
  19. universal_mcp/applications/ahrefs/README.md +0 -76
  20. universal_mcp/applications/ahrefs/__init__.py +0 -0
  21. universal_mcp/applications/ahrefs/app.py +0 -2291
  22. universal_mcp/applications/cal_com_v2/README.md +0 -175
  23. universal_mcp/applications/cal_com_v2/__init__.py +0 -0
  24. universal_mcp/applications/cal_com_v2/app.py +0 -5390
  25. universal_mcp/applications/calendly/README.md +0 -78
  26. universal_mcp/applications/calendly/__init__.py +0 -0
  27. universal_mcp/applications/calendly/app.py +0 -1195
  28. universal_mcp/applications/clickup/README.md +0 -160
  29. universal_mcp/applications/clickup/__init__.py +0 -0
  30. universal_mcp/applications/clickup/app.py +0 -5009
  31. universal_mcp/applications/coda/README.md +0 -133
  32. universal_mcp/applications/coda/__init__.py +0 -0
  33. universal_mcp/applications/coda/app.py +0 -3671
  34. universal_mcp/applications/e2b/README.md +0 -37
  35. universal_mcp/applications/e2b/app.py +0 -65
  36. universal_mcp/applications/elevenlabs/README.md +0 -84
  37. universal_mcp/applications/elevenlabs/__init__.py +0 -0
  38. universal_mcp/applications/elevenlabs/app.py +0 -1402
  39. universal_mcp/applications/falai/README.md +0 -42
  40. universal_mcp/applications/falai/__init__.py +0 -0
  41. universal_mcp/applications/falai/app.py +0 -332
  42. universal_mcp/applications/figma/README.md +0 -74
  43. universal_mcp/applications/figma/__init__.py +0 -0
  44. universal_mcp/applications/figma/app.py +0 -1261
  45. universal_mcp/applications/firecrawl/README.md +0 -45
  46. universal_mcp/applications/firecrawl/app.py +0 -268
  47. universal_mcp/applications/github/README.md +0 -47
  48. universal_mcp/applications/github/app.py +0 -429
  49. universal_mcp/applications/gong/README.md +0 -88
  50. universal_mcp/applications/gong/__init__.py +0 -0
  51. universal_mcp/applications/gong/app.py +0 -2297
  52. universal_mcp/applications/google_calendar/app.py +0 -442
  53. universal_mcp/applications/google_docs/README.md +0 -40
  54. universal_mcp/applications/google_docs/app.py +0 -88
  55. universal_mcp/applications/google_drive/README.md +0 -44
  56. universal_mcp/applications/google_drive/app.py +0 -286
  57. universal_mcp/applications/google_mail/README.md +0 -47
  58. universal_mcp/applications/google_mail/app.py +0 -664
  59. universal_mcp/applications/google_sheet/README.md +0 -42
  60. universal_mcp/applications/google_sheet/app.py +0 -150
  61. universal_mcp/applications/hashnode/app.py +0 -81
  62. universal_mcp/applications/hashnode/prompt.md +0 -23
  63. universal_mcp/applications/heygen/README.md +0 -69
  64. universal_mcp/applications/heygen/__init__.py +0 -0
  65. universal_mcp/applications/heygen/app.py +0 -956
  66. universal_mcp/applications/mailchimp/README.md +0 -306
  67. universal_mcp/applications/mailchimp/__init__.py +0 -0
  68. universal_mcp/applications/mailchimp/app.py +0 -10937
  69. universal_mcp/applications/markitdown/app.py +0 -44
  70. universal_mcp/applications/notion/README.md +0 -55
  71. universal_mcp/applications/notion/__init__.py +0 -0
  72. universal_mcp/applications/notion/app.py +0 -527
  73. universal_mcp/applications/perplexity/README.md +0 -37
  74. universal_mcp/applications/perplexity/app.py +0 -65
  75. universal_mcp/applications/reddit/README.md +0 -45
  76. universal_mcp/applications/reddit/app.py +0 -379
  77. universal_mcp/applications/replicate/README.md +0 -65
  78. universal_mcp/applications/replicate/__init__.py +0 -0
  79. universal_mcp/applications/replicate/app.py +0 -980
  80. universal_mcp/applications/resend/README.md +0 -38
  81. universal_mcp/applications/resend/app.py +0 -37
  82. universal_mcp/applications/retell_ai/README.md +0 -46
  83. universal_mcp/applications/retell_ai/__init__.py +0 -0
  84. universal_mcp/applications/retell_ai/app.py +0 -333
  85. universal_mcp/applications/rocketlane/README.md +0 -42
  86. universal_mcp/applications/rocketlane/__init__.py +0 -0
  87. universal_mcp/applications/rocketlane/app.py +0 -194
  88. universal_mcp/applications/serpapi/README.md +0 -37
  89. universal_mcp/applications/serpapi/app.py +0 -73
  90. universal_mcp/applications/spotify/README.md +0 -116
  91. universal_mcp/applications/spotify/__init__.py +0 -0
  92. universal_mcp/applications/spotify/app.py +0 -2526
  93. universal_mcp/applications/supabase/README.md +0 -112
  94. universal_mcp/applications/supabase/__init__.py +0 -0
  95. universal_mcp/applications/supabase/app.py +0 -2970
  96. universal_mcp/applications/tavily/README.md +0 -38
  97. universal_mcp/applications/tavily/app.py +0 -51
  98. universal_mcp/applications/wrike/README.md +0 -71
  99. universal_mcp/applications/wrike/__init__.py +0 -0
  100. universal_mcp/applications/wrike/app.py +0 -1372
  101. universal_mcp/applications/youtube/README.md +0 -82
  102. universal_mcp/applications/youtube/__init__.py +0 -0
  103. universal_mcp/applications/youtube/app.py +0 -1428
  104. universal_mcp/applications/zenquotes/README.md +0 -37
  105. universal_mcp/applications/zenquotes/app.py +0 -31
  106. universal_mcp/integrations/agentr.py +0 -112
  107. universal_mcp-0.1.12.dist-info/RECORD +0 -119
  108. {universal_mcp-0.1.12.dist-info → universal_mcp-0.1.13rc2.dist-info}/WHEEL +0 -0
  109. {universal_mcp-0.1.12.dist-info → universal_mcp-0.1.13rc2.dist-info}/entry_points.txt +0 -0
@@ -1,980 +0,0 @@
1
- from typing import Any, Literal
2
-
3
- from loguru import logger
4
-
5
- # Import the base APIApplication class
6
- from universal_mcp.applications.application import APIApplication
7
-
8
- # Import the Integration class
9
- from universal_mcp.integrations import Integration
10
-
11
-
12
- class ReplicateApp(APIApplication):
13
- """
14
- Application for interacting with the Replicate HTTP API.
15
-
16
- Exposes Replicate operations as tools, allowing interaction with models,
17
- predictions, trainings, deployments, etc.
18
- """
19
-
20
- def __init__(self, integration: Integration = None) -> None:
21
- """
22
- Initializes the ReplicateApp.
23
-
24
- Args:
25
- integration: The integration object providing authentication credentials.
26
- Expected to provide a Replicate API token as 'api_key'.
27
- """
28
- # Call the parent constructor with the application name and integration
29
- super().__init__(name="replicate", integration=integration)
30
-
31
- # Set the base URL for the Replicate API (from the OpenAPI schema's servers section)
32
- self.base_url = "https://api.replicate.com/v1"
33
- logger.debug(f"ReplicateApp initialized with base_url: {self.base_url}")
34
-
35
- # --- Account Operations ---
36
-
37
- def account_get(self) -> dict[str, Any]:
38
- """
39
- Gets information about the authenticated account.
40
-
41
- Args:
42
- None: This function takes no parameters.
43
-
44
- Returns:
45
- Dict[str, Any]: A dictionary containing account details including type, username, name, and other account-related information.
46
-
47
- Raises:
48
- HTTPError: When the API request fails or returns a non-200 status code
49
- RequestException: When there are network connectivity issues or other request-related problems
50
-
51
- Tags:
52
- account, get, read, api, authentication, important
53
- """
54
- url = f"{self.base_url}/account"
55
- response = self._get(url)
56
- response.raise_for_status()
57
- return response.json()
58
-
59
- # --- Collection Operations ---
60
-
61
- def collections_list(self) -> dict[str, Any]:
62
- """
63
- Lists collections of models available on Replicate, returning a paginated list of collection objects.
64
-
65
- Args:
66
- None: This function takes no arguments other than self
67
-
68
- Returns:
69
- A dictionary containing a paginated list of collection objects from the Replicate API
70
-
71
- Raises:
72
- HTTPError: When the API request fails or returns a non-200 status code
73
-
74
- Tags:
75
- list, collections, read, api, important, fetch, models
76
- """
77
- url = f"{self.base_url}/collections"
78
- response = self._get(url)
79
- response.raise_for_status()
80
- return response.json()
81
-
82
- def collections_get(self, collection_slug: str) -> dict[str, Any]:
83
- """
84
- Retrieves detailed information about a specific model collection, with automatic truncation of large model lists to manage response size.
85
-
86
- Args:
87
- collection_slug: The unique identifier (slug) for the collection to retrieve (e.g., 'super-resolution')
88
-
89
- Returns:
90
- A dictionary containing collection details and its associated models. If the model list exceeds the truncation threshold (15), returns a modified dictionary with the model list replaced by a summary count and message.
91
-
92
- Raises:
93
- HTTPError: Raised when the API request fails or returns an error status code
94
- RequestException: Raised when there's a network-related error during the API request
95
-
96
- Tags:
97
- get, read, collections, api, data-retrieval, important, truncation
98
- """
99
- url = f"{self.base_url}/collections/{collection_slug}"
100
- response = self._get(url)
101
- response.raise_for_status()
102
- collection_data = response.json()
103
- if "models" in collection_data and isinstance(collection_data["models"], list):
104
- original_model_count = len(collection_data["models"])
105
-
106
- # Define a threshold for truncation.
107
- # This is a heuristic value. You might need to adjust this number
108
- # based on how many model objects typically fit within your LLM's context,
109
- # considering the size of each model object description.
110
- TRUNCATION_THRESHOLD = 10 # Example: Truncate if more than 15 models
111
-
112
- if original_model_count > TRUNCATION_THRESHOLD:
113
- logger.warning(
114
- f"Truncating model list for collection '{collection_slug}'. Found {original_model_count} models, exceeding threshold {TRUNCATION_THRESHOLD}."
115
- )
116
-
117
- # Create a new dictionary with essential collection data
118
- # and replace the 'models' list with a summary.
119
- truncated_data = {
120
- k: v
121
- for k, v in collection_data.items()
122
- if k != "models" # Exclude the full models list
123
- }
124
- # Add information about the models list being truncated
125
- truncated_data["model_count"] = original_model_count
126
- truncated_data["models"] = (
127
- f"List of {original_model_count} models omitted due to size. Use models_get for details on individual models by owner/name."
128
- )
129
- # Optionally, include a small number of models as a preview, but this adds size.
130
- # For maximum reduction, just provide the count and message.
131
- # truncated_data['models_preview'] = collection_data['models'][:5] # Example: include first 5 models
132
-
133
- return truncated_data
134
- else:
135
- # If the list is not too large, return the full data
136
- return collection_data
137
- else:
138
- # If 'models' key is missing or not a list, return the data as is
139
- # (This handles cases where the structure is unexpected, or an error occurred before this point)
140
- return collection_data
141
-
142
- # --- Deployment Operations ---
143
-
144
- def deployments_list(self) -> dict[str, Any]:
145
- """
146
- Lists all deployments associated with the authenticated account.
147
-
148
- Args:
149
- None: This function takes no arguments.
150
-
151
- Returns:
152
- Dict[str, Any]: A dictionary containing a paginated list of deployment objects with deployment details and metadata.
153
-
154
- Raises:
155
- HTTPError: When the API request fails or returns a non-200 status code
156
- RequestException: When there are network connectivity issues or API communication errors
157
-
158
- Tags:
159
- list, read, deployments, api, management, important
160
- """
161
- url = f"{self.base_url}/deployments"
162
- response = self._get(url)
163
- response.raise_for_status()
164
- return response.json()
165
-
166
- def deployments_create(
167
- self,
168
- name: str,
169
- model: str,
170
- version: str,
171
- hardware: str,
172
- min_instances: int,
173
- max_instances: int,
174
- ) -> dict[str, Any]:
175
- """
176
- Creates a new model deployment with specified configuration parameters.
177
-
178
- Args:
179
- name: The name of the deployment
180
- model: The full name of the model (e.g., 'stability-ai/sdxl')
181
- version: The 64-character string ID of the model version
182
- hardware: The SKU for the hardware (e.g., 'gpu-t4')
183
- min_instances: The minimum number of instances, ranging from 0 to 5
184
- max_instances: The maximum number of instances, ranging from 0 to 20
185
-
186
- Returns:
187
- Dictionary containing the details of the newly created deployment
188
-
189
- Raises:
190
- HTTPError: When the API request fails or returns a non-200 status code
191
-
192
- Tags:
193
- create, deployment, configuration, api, infrastructure, scaling, important
194
- """
195
- url = f"{self.base_url}/deployments"
196
- request_body = {
197
- "name": name,
198
- "model": model,
199
- "version": version,
200
- "hardware": hardware,
201
- "min_instances": min_instances,
202
- "max_instances": max_instances,
203
- }
204
- response = self._post(url, data=request_body)
205
- response.raise_for_status()
206
- return response.json()
207
-
208
- def deployments_get(
209
- self, deployment_owner: str, deployment_name: str
210
- ) -> dict[str, Any]:
211
- """
212
- Retrieves detailed information about a specific deployment by its owner and name.
213
-
214
- Args:
215
- deployment_owner: The owner's username or organization name associated with the deployment
216
- deployment_name: The unique name identifier of the deployment
217
-
218
- Returns:
219
- A dictionary containing detailed information about the requested deployment
220
-
221
- Raises:
222
- HTTPError: When the HTTP request fails or returns a non-200 status code
223
-
224
- Tags:
225
- get, read, deployments, api, fetch, important
226
- """
227
- url = f"{self.base_url}/deployments/{deployment_owner}/{deployment_name}"
228
- response = self._get(url)
229
- response.raise_for_status()
230
- return response.json()
231
-
232
- def deployments_update(
233
- self,
234
- deployment_owner: str,
235
- deployment_name: str,
236
- hardware: str = None,
237
- max_instances: int = None,
238
- min_instances: int = None,
239
- version: str = None,
240
- ) -> dict[str, Any]:
241
- """
242
- Updates configurable properties of an existing deployment, such as hardware specifications and instance scaling parameters.
243
-
244
- Args:
245
- deployment_owner: The owner's username or organization name
246
- deployment_name: The name of the deployment to be updated
247
- hardware: Optional. The new SKU for the hardware specification
248
- max_instances: Optional. The new maximum number of instances for scaling
249
- min_instances: Optional. The new minimum number of instances for scaling
250
- version: Optional. The new ID of the model version to deploy
251
-
252
- Returns:
253
- Dictionary containing the updated deployment configuration details or a message if no updates were provided
254
-
255
- Raises:
256
- HTTPError: Raised when the API request fails or returns an error status code
257
-
258
- Tags:
259
- update, deployments, configuration, scaling, management, important
260
- """
261
- url = f"{self.base_url}/deployments/{deployment_owner}/{deployment_name}"
262
- update_data = {
263
- "hardware": hardware,
264
- "max_instances": max_instances,
265
- "min_instances": min_instances,
266
- "version": version,
267
- }
268
- update_data = {k: v for k, v in update_data.items() if v is not None}
269
- if not update_data:
270
- return {"message": "No update parameters provided."}
271
- response = self._patch(url, data=update_data)
272
- response.raise_for_status()
273
- return response.json()
274
-
275
- def deployments_delete(self, deployment_owner: str, deployment_name: str) -> str:
276
- """
277
- Deletes a specified deployment associated with a given owner or organization
278
-
279
- Args:
280
- deployment_owner: The username or organization name that owns the deployment
281
- deployment_name: The unique identifier/name of the deployment to be deleted
282
-
283
- Returns:
284
- A string containing a success message confirming the deployment deletion
285
-
286
- Raises:
287
- HTTPError: If the deletion request fails due to server error, invalid permissions, deployment being in use, or deployment not found
288
-
289
- Tags:
290
- delete, deployments, management, important, infrastructure, resource-management
291
- """
292
- url = f"{self.base_url}/deployments/{deployment_owner}/{deployment_name}"
293
- response = self._delete(url)
294
- response.raise_for_status()
295
- return f"Deployment '{deployment_owner}/{deployment_name}' deleted successfully." # Assuming 204 No Content
296
-
297
- # --- Deployments Predictions Operations ---
298
- # Note: The 'Prefer: wait' header is not directly supported by default _post.
299
- # The response will likely be 201 or 202, requiring polling via predictions_get.
300
-
301
- def deployments_predictions_create(
302
- self,
303
- deployment_owner: str,
304
- deployment_name: str,
305
- input: dict[str, Any],
306
- stream: bool = None, # Deprecated according to schema
307
- webhook: str = None,
308
- webhook_events_filter: list[
309
- Literal["start", "output", "logs", "completed"]
310
- ] = None,
311
- ) -> dict[str, Any]:
312
- """
313
- Creates an asynchronous prediction using a specified deployment, optionally configuring webhook notifications for status updates.
314
-
315
- Args:
316
- deployment_owner: The owner's username or organization name of the deployment
317
- deployment_name: The name of the deployment to use for prediction
318
- input: Dictionary containing the model's input data as a JSON-serializable object
319
- stream: Deprecated parameter for requesting streaming output URL
320
- webhook: HTTPS URL where prediction status updates will be sent
321
- webhook_events_filter: List of specific events to trigger webhook notifications ('start', 'output', 'logs', 'completed')
322
-
323
- Returns:
324
- Dictionary containing the initial prediction state, including a prediction ID for status polling
325
-
326
- Raises:
327
- HTTPError: When the API request fails or returns an error status code
328
- JSONDecodeError: When the API response contains invalid JSON
329
-
330
- Tags:
331
- create, predict, async, deployments, webhook, http-request, important
332
- """
333
- url = f"{self.base_url}/deployments/{deployment_owner}/{deployment_name}/predictions"
334
- request_body = {
335
- "input": input,
336
- "stream": stream, # Included for completeness, though deprecated
337
- "webhook": webhook,
338
- "webhook_events_filter": webhook_events_filter,
339
- }
340
- request_body = {k: v for k, v in request_body.items() if v is not None}
341
- response = self._post(url, data=request_body)
342
- response.raise_for_status()
343
- return response.json()
344
-
345
- # --- Hardware Operations ---
346
-
347
- def hardware_list(self) -> list[dict[str, Any]]:
348
- """
349
- Retrieves a list of available hardware options for running models.
350
-
351
- Returns:
352
- List[Dict[str, Any]]: A list of dictionaries, where each dictionary represents a hardware option containing 'name' and 'sku' keys.
353
-
354
- Raises:
355
- HTTPError: When the API request fails or returns a non-200 status code
356
-
357
- Tags:
358
- list, hardware, read, api, configuration, important
359
- """
360
- url = f"{self.base_url}/hardware"
361
- response = self._get(url)
362
- response.raise_for_status()
363
- return response.json()
364
-
365
- # --- Model Operations ---
366
-
367
- def models_list(self) -> dict[str, Any]:
368
- """
369
- Retrieves a paginated list of publicly available models from the Replicate API.
370
-
371
- Returns:
372
- Dict[str, Any]: A dictionary containing the paginated list of model objects with their metadata and configurations.
373
-
374
- Raises:
375
- HTTPError: When the API request fails or returns a non-200 status code
376
- RequestException: When there are network connectivity issues or other request-related problems
377
-
378
- Tags:
379
- list, models, read, api, fetch, important
380
- """
381
- url = f"{self.base_url}/models"
382
- response = self._get(url)
383
- response.raise_for_status()
384
- return response.json()
385
-
386
- def models_create(
387
- self,
388
- owner: str,
389
- name: str,
390
- visibility: Literal["public", "private"],
391
- hardware: str,
392
- cover_image_url: str = None,
393
- description: str = None,
394
- github_url: str = None,
395
- license_url: str = None,
396
- paper_url: str = None,
397
- ) -> dict[str, Any]:
398
- """
399
- Creates a new model in the system with specified parameters and metadata.
400
-
401
- Args:
402
- owner: The username or organization name that will own the model
403
- name: The name of the model (must be unique for the owner)
404
- visibility: Visibility setting for the model ('public' or 'private')
405
- hardware: The SKU for the hardware requirements
406
- cover_image_url: Optional URL for the model's cover image
407
- description: Optional text description of the model
408
- github_url: Optional URL for the model's source code repository
409
- license_url: Optional URL for the model's license documentation
410
- paper_url: Optional URL for the associated research paper
411
-
412
- Returns:
413
- Dictionary containing the details and metadata of the newly created model
414
-
415
- Raises:
416
- HTTPError: Raised when the API request fails or returns an error status code
417
-
418
- Tags:
419
- create, models, management, api, important
420
- """
421
- url = f"{self.base_url}/models"
422
- request_body = {
423
- "owner": owner,
424
- "name": name,
425
- "visibility": visibility,
426
- "hardware": hardware,
427
- "cover_image_url": cover_image_url,
428
- "description": description,
429
- "github_url": github_url,
430
- "license_url": license_url,
431
- "paper_url": paper_url,
432
- }
433
- request_body = {k: v for k, v in request_body.items() if v is not None}
434
- response = self._post(url, data=request_body)
435
- response.raise_for_status()
436
- return response.json()
437
-
438
- def models_search(self, query: str) -> dict[str, Any]:
439
- """
440
- Searches for public models based on a provided query string
441
-
442
- Args:
443
- query: A string containing the search query to filter models
444
-
445
- Returns:
446
- A dictionary containing paginated search results with matching model objects
447
-
448
- Raises:
449
- Exception: When the HTTP request fails or encounters network/server errors
450
- HTTPStatusError: When the API returns a non-successful status code
451
-
452
- Tags:
453
- search, models, query, read, api, http, important
454
- """
455
- url = f"{self.base_url}/models"
456
- headers = self._get_headers()
457
- headers["Content-Type"] = "text/plain"
458
- try:
459
- # Use httpx directly to send raw text body
460
- response = self.client.post(
461
- url, content=query, headers=headers, timeout=self.client.timeout
462
- )
463
- response.raise_for_status()
464
- return response.json()
465
- except Exception as e:
466
- logger.error(f"Error during models_search: {e}")
467
- raise
468
-
469
- def models_get(self, model_owner: str, model_name: str) -> dict[str, Any]:
470
- """
471
- Retrieves detailed information about a specific AI model by its owner and name
472
-
473
- Args:
474
- model_owner: The owner's username or organization name who owns the model
475
- model_name: The unique name identifier of the model
476
-
477
- Returns:
478
- A dictionary containing detailed model information, including its latest version and usage examples
479
-
480
- Raises:
481
- HTTPError: Raised when the API request fails, such as when the model doesn't exist or there are authentication issues
482
-
483
- Tags:
484
- get, read, models, api, metadata, important
485
- """
486
- url = f"{self.base_url}/models/{model_owner}/{model_name}"
487
- response = self._get(url)
488
- response.raise_for_status()
489
- return response.json()
490
-
491
- def models_delete(self, model_owner: str, model_name: str) -> str:
492
- """
493
- Deletes a private model from the system, provided it has no existing versions.
494
-
495
- Args:
496
- model_owner: The owner's username or organization name of the model
497
- model_name: The name of the model to be deleted
498
-
499
- Returns:
500
- A success message string confirming the model deletion
501
-
502
- Raises:
503
- HTTPError: When deletion fails due to model being public, having existing versions, or other API restrictions
504
-
505
- Tags:
506
- delete, models, management, important, api, cleanup
507
- """
508
- url = f"{self.base_url}/models/{model_owner}/{model_name}"
509
- response = self._delete(url)
510
- response.raise_for_status() # Expecting 204 No Content
511
- return f"Model '{model_owner}/{model_name}' deleted successfully."
512
-
513
- # --- Model Examples Operations ---
514
-
515
- def models_examples_list(self, model_owner: str, model_name: str) -> dict[str, Any]:
516
- """
517
- Retrieves a list of example predictions associated with a specific model.
518
-
519
- Args:
520
- model_owner: The owner's username or organization name of the model
521
- model_name: The name of the model to retrieve examples for
522
-
523
- Returns:
524
- A dictionary containing a paginated list of example prediction objects for the specified model
525
-
526
- Raises:
527
- HTTPError: When the API request fails or returns a non-200 status code
528
- RequestException: When there are network connectivity issues or API communication errors
529
-
530
- Tags:
531
- list, read, models, examples, api, pagination, prediction
532
- """
533
- url = f"{self.base_url}/models/{model_owner}/{model_name}/examples"
534
- response = self._get(url)
535
- response.raise_for_status()
536
- return response.json()
537
-
538
- # --- Model Predictions Operations ---
539
- # Note: The 'Prefer: wait' header is not directly supported by default _post.
540
- # The response will likely be 201 or 202, requiring polling via predictions_get.
541
-
542
- def models_predictions_create(
543
- self,
544
- model_owner: str,
545
- model_name: str,
546
- input: dict[str, Any],
547
- stream: bool = None, # Deprecated according to schema
548
- webhook: str = None,
549
- webhook_events_filter: list[
550
- Literal["start", "output", "logs", "completed"]
551
- ] = None,
552
- ) -> dict[str, Any]:
553
- """
554
- Creates an asynchronous prediction request using a specified machine learning model.
555
-
556
- Args:
557
- model_owner: The owner's username or organization name
558
- model_name: The name of the model to use for prediction
559
- input: Dictionary containing the model's input parameters
560
- stream: DEPRECATED. Boolean flag to request a streaming output URL
561
- webhook: HTTPS URL for receiving prediction status updates and results
562
- webhook_events_filter: List of events to trigger webhook notifications ('start', 'output', 'logs', 'completed')
563
-
564
- Returns:
565
- Dictionary containing the initial prediction state and metadata. Includes prediction ID for status polling.
566
-
567
- Raises:
568
- HTTPError: Raised when the API request fails or returns an error status code
569
-
570
- Tags:
571
- predict, create, async, models, webhook, api, ml, important
572
- """
573
- url = f"{self.base_url}/models/{model_owner}/{model_name}/predictions"
574
- request_body = {
575
- "input": input,
576
- "stream": stream, # Included for completeness, though deprecated
577
- "webhook": webhook,
578
- "webhook_events_filter": webhook_events_filter,
579
- }
580
- request_body = {k: v for k, v in request_body.items() if v is not None}
581
- response = self._post(url, data=request_body)
582
- response.raise_for_status()
583
- return response.json()
584
-
585
- # --- Model Readme Operations ---
586
-
587
- def models_readme_get(self, model_owner: str, model_name: str) -> str:
588
- """
589
- Retrieves the README content for a specified model in Markdown format.
590
-
591
- Args:
592
- model_owner: The owner's username or organization name
593
- model_name: The name of the model
594
-
595
- Returns:
596
- A string containing the README content in Markdown format
597
-
598
- Raises:
599
- HTTPError: When the API request fails or returns a non-200 status code
600
- RequestException: When there are network connectivity issues or other request-related problems
601
-
602
- Tags:
603
- get, read, models, documentation, markdown, api, metadata
604
- """
605
- url = f"{self.base_url}/models/{model_owner}/{model_name}/readme"
606
- response = self._get(url)
607
- response.raise_for_status()
608
- return response.text # README is text/plain
609
-
610
- # --- Model Versions Operations ---
611
-
612
- def models_versions_list(self, model_owner: str, model_name: str) -> dict[str, Any]:
613
- """
614
- Lists all available versions of a specified model.
615
-
616
- Args:
617
- model_owner: The username or organization name that owns the model
618
- model_name: The name of the model whose versions are to be listed
619
-
620
- Returns:
621
- A dictionary containing a paginated list of model version objects with version details
622
-
623
- Raises:
624
- HTTPError: When the API request fails or returns a non-200 status code
625
-
626
- Tags:
627
- list, read, models, versions, api, management, paginated, important
628
- """
629
- url = f"{self.base_url}/models/{model_owner}/{model_name}/versions"
630
- response = self._get(url)
631
- response.raise_for_status()
632
- return response.json()
633
-
634
- def models_versions_get(
635
- self, model_owner: str, model_name: str, version_id: str
636
- ) -> dict[str, Any]:
637
- """
638
- Retrieves detailed information about a specific version of a model by querying the API.
639
-
640
- Args:
641
- model_owner: The owner's username or organization name who owns the model
642
- model_name: The name of the model to query
643
- version_id: The unique identifier of the specific model version
644
-
645
- Returns:
646
- A dictionary containing detailed information about the model version, including its OpenAPI schema and metadata
647
-
648
- Raises:
649
- HTTPError: Raised when the API request fails, such as when the model version doesn't exist or there are authentication issues
650
-
651
- Tags:
652
- get, read, models, versions, api, metadata, important
653
- """
654
- url = f"{self.base_url}/models/{model_owner}/{model_name}/versions/{version_id}"
655
- response = self._get(url)
656
- response.raise_for_status()
657
- return response.json()
658
-
659
- def models_versions_delete(
660
- self, model_owner: str, model_name: str, version_id: str
661
- ) -> str:
662
- """
663
- Deletes a specific version of a model and its associated predictions/output.
664
-
665
- Args:
666
- model_owner: The owner's username or organization name
667
- model_name: The name of the model
668
- version_id: The ID of the version to be deleted
669
-
670
- Returns:
671
- A success message confirming the deletion request was accepted
672
-
673
- Raises:
674
- HTTPError: If the deletion request fails due to API restrictions or permissions
675
-
676
- Tags:
677
- delete, models, versions, management, important
678
- """
679
- url = f"{self.base_url}/models/{model_owner}/{model_name}/versions/{version_id}"
680
- response = self._delete(url)
681
- response.raise_for_status() # Expecting 202 Accepted or 204 No Content
682
- return f"Deletion request for version '{version_id}' of model '{model_owner}/{model_name}' accepted."
683
-
684
- # --- Training Operations (via Model Version) ---
685
-
686
- def trainings_create(
687
- self,
688
- model_owner: str,
689
- model_name: str,
690
- version_id: str,
691
- destination: str,
692
- input: dict[str, Any],
693
- webhook: str = None,
694
- webhook_events_filter: list[
695
- Literal["start", "output", "logs", "completed"]
696
- ] = None,
697
- ) -> dict[str, Any]:
698
- """
699
- Initiates a new asynchronous training job for a specific model version, with optional webhook notifications for progress updates.
700
-
701
- Args:
702
- model_owner: The owner's username or organization name of the base model
703
- model_name: The name of the base model
704
- version_id: The ID of the model version to train from
705
- destination: The target model identifier string in '{new_owner}/{new_name}' format
706
- input: Dictionary containing inputs for the training function
707
- webhook: Optional HTTPS URL for receiving training updates
708
- webhook_events_filter: Optional list of events to trigger webhooks ('start', 'output', 'logs', 'completed')
709
-
710
- Returns:
711
- Dictionary containing the initial state of the training job
712
-
713
- Raises:
714
- HTTPError: Raised when the API request fails or returns an error status code
715
-
716
- Tags:
717
- training, create, async-job, start, model-management, webhook, important
718
- """
719
- url = f"{self.base_url}/models/{model_owner}/{model_name}/versions/{version_id}/trainings"
720
- request_body = {
721
- "destination": destination,
722
- "input": input,
723
- "webhook": webhook,
724
- "webhook_events_filter": webhook_events_filter,
725
- }
726
- request_body = {k: v for k, v in request_body.items() if v is not None}
727
- response = self._post(url, data=request_body)
728
- response.raise_for_status()
729
- return response.json()
730
-
731
- # --- Prediction Operations ---
732
-
733
- def predictions_list(
734
- self,
735
- created_after: str = None, # ISO 8601 date-time
736
- created_before: str = None, # ISO 8601 date-time
737
- ) -> dict[str, Any]:
738
- """
739
- Lists all predictions created by the authenticated account within an optional time range.
740
-
741
- Args:
742
- created_after: ISO 8601 date-time string specifying the lower bound for prediction creation time (inclusive)
743
- created_before: ISO 8601 date-time string specifying the upper bound for prediction creation time (exclusive)
744
-
745
- Returns:
746
- Dictionary containing a paginated list of prediction objects with their associated metadata
747
-
748
- Raises:
749
- HTTPError: When the API request fails or returns a non-200 status code
750
- RequestException: When there are network connectivity issues or invalid request parameters
751
-
752
- Tags:
753
- list, read, predictions, query, filter, pagination, important
754
- """
755
- url = f"{self.base_url}/predictions"
756
- query_params = {
757
- "created_after": created_after,
758
- "created_before": created_before,
759
- }
760
- query_params = {k: v for k, v in query_params.items() if v is not None}
761
- response = self._get(url, params=query_params)
762
- response.raise_for_status()
763
- return response.json()
764
-
765
- # Note: The 'Prefer: wait' header is not directly supported by default _post.
766
- # The response will likely be 201 or 202, requiring polling via predictions_get.
767
-
768
- def predictions_create(
769
- self,
770
- version: str,
771
- input: dict[str, Any],
772
- stream: bool = None, # Deprecated according to schema
773
- webhook: str = None,
774
- webhook_events_filter: list[
775
- Literal["start", "output", "logs", "completed"]
776
- ] = None,
777
- ) -> dict[str, Any]:
778
- """
779
- Creates an asynchronous prediction request using a specified model version.
780
-
781
- Args:
782
- version: The ID of the model version to execute the prediction
783
- input: A dictionary containing the input data for the model prediction
784
- stream: Deprecated parameter - Previously used for requesting streaming output URL
785
- webhook: Optional HTTPS URL to receive prediction status updates and results
786
- webhook_events_filter: Optional list of event types to trigger webhook notifications. Valid events: 'start', 'output', 'logs', 'completed'
787
-
788
- Returns:
789
- A dictionary containing the initial prediction state, including a prediction ID for status tracking
790
-
791
- Raises:
792
- HTTPError: Raised when the API request fails or returns an error status code
793
-
794
- Tags:
795
- predictions, create, async, api, model, important, webhook, ml
796
- """
797
- url = f"{self.base_url}/predictions"
798
- request_body = {
799
- "version": version,
800
- "input": input,
801
- "stream": stream, # Included for completeness, though deprecated
802
- "webhook": webhook,
803
- "webhook_events_filter": webhook_events_filter,
804
- }
805
- request_body = {k: v for k, v in request_body.items() if v is not None}
806
- response = self._post(url, data=request_body)
807
- response.raise_for_status()
808
- return response.json()
809
-
810
- def predictions_get(self, prediction_id: str) -> dict[str, Any]:
811
- """
812
- Retrieves the current state and details of a prediction by its ID.
813
-
814
- Args:
815
- prediction_id: String identifier of the prediction to retrieve
816
-
817
- Returns:
818
- Dictionary containing the prediction's current state and associated details
819
-
820
- Raises:
821
- HTTPError: When the API request fails or returns a non-200 status code
822
- RequestException: When there are network connectivity issues or invalid URL
823
-
824
- Tags:
825
- get, read, status, predictions, retrieve, api, important
826
- """
827
- url = f"{self.base_url}/predictions/{prediction_id}"
828
- response = self._get(url)
829
- response.raise_for_status()
830
- return response.json()
831
-
832
- def predictions_cancel(
833
- self, prediction_id: str
834
- ) -> str: # Schema shows no content for 200 success
835
- """
836
- Cancels a running prediction job identified by its ID.
837
-
838
- Args:
839
- prediction_id: The unique identifier of the prediction job to cancel
840
-
841
- Returns:
842
- A string message confirming successful cancellation of the prediction
843
-
844
- Raises:
845
- HTTPError: When the API request fails or returns an error status code
846
- RequestException: When there are network connectivity issues or other request-related problems
847
-
848
- Tags:
849
- cancel, predictions, management, api, async-job, important
850
- """
851
- url = f"{self.base_url}/predictions/{prediction_id}/cancel"
852
- response = self._post(
853
- url, data={}
854
- ) # POST with empty body for cancel according to typical patterns
855
- response.raise_for_status() # Expecting 200 Success or similar
856
- return f"Prediction '{prediction_id}' cancelled successfully."
857
-
858
- # --- Training Operations ---
859
-
860
- def trainings_list(self) -> dict[str, Any]:
861
- """
862
- Lists all training jobs created by the authenticated account.
863
-
864
- Returns:
865
- Dict[str, Any]: A dictionary containing a paginated list of training objects with their details and metadata.
866
-
867
- Raises:
868
- HTTPError: When the API request fails or returns a non-200 status code
869
- RequestException: When there's a network error or connection issue
870
-
871
- Tags:
872
- list, read, trainings, management, important
873
- """
874
- url = f"{self.base_url}/trainings"
875
- response = self._get(url)
876
- response.raise_for_status()
877
- return response.json()
878
-
879
- def trainings_get(self, training_id: str) -> dict[str, Any]:
880
- """
881
- Retrieves the current state of a training job by its ID.
882
-
883
- Args:
884
- training_id: A string identifier for the training job
885
-
886
- Returns:
887
- A dictionary containing the current state and details of the training job
888
-
889
- Raises:
890
- HTTPError: When the API request fails or returns a non-200 status code
891
-
892
- Tags:
893
- get, read, status, training, api, fetch, monitor, important
894
- """
895
- url = f"{self.base_url}/trainings/{training_id}"
896
- response = self._get(url)
897
- response.raise_for_status()
898
- return response.json()
899
-
900
- def trainings_cancel(self, training_id: str) -> dict[str, Any]:
901
- """
902
- Cancels a specific training job in progress.
903
-
904
- Args:
905
- training_id: String identifier of the training job to be cancelled
906
-
907
- Returns:
908
- Dictionary containing the updated state and details of the cancelled training job
909
-
910
- Raises:
911
- HTTPError: When the cancellation request fails or the server returns an error response
912
- RequestException: When network issues or connection problems occur during the API call
913
-
914
- Tags:
915
- cancel, trainings, management, async-job, important
916
- """
917
- url = f"{self.base_url}/trainings/{training_id}/cancel"
918
- response = self._post(url, data={}) # POST with empty body for cancel
919
- response.raise_for_status()
920
- return response.json()
921
-
922
- # --- Webhooks Operations ---
923
-
924
- def webhooks_default_secret_get(self) -> dict[str, str]:
925
- """
926
- Retrieves the signing secret for the default webhook endpoint.
927
-
928
- Returns:
929
- Dict[str, str]: A dictionary containing the 'key' field with the signing secret value.
930
-
931
- Raises:
932
- HTTPError: If the API request fails or returns a non-200 status code.
933
- RequestException: If there are network connectivity issues or other request-related problems.
934
-
935
- Tags:
936
- get, read, webhooks, security, secret, authentication, api, important
937
- """
938
- url = f"{self.base_url}/webhooks/default/secret"
939
- response = self._get(url)
940
- response.raise_for_status()
941
- return response.json()
942
-
943
- # --- Required list_tools method ---
944
-
945
- def list_tools(self):
946
- """
947
- Returns a list of methods exposed as tools by this application.
948
- """
949
- return [
950
- self.account_get,
951
- self.collections_list,
952
- self.collections_get,
953
- self.deployments_list,
954
- self.deployments_create,
955
- self.deployments_get,
956
- self.deployments_update,
957
- self.deployments_delete,
958
- self.deployments_predictions_create,
959
- self.hardware_list,
960
- self.models_list,
961
- self.models_create,
962
- self.models_search,
963
- self.models_get,
964
- self.models_delete,
965
- self.models_examples_list,
966
- self.models_predictions_create,
967
- self.models_readme_get,
968
- self.models_versions_list,
969
- self.models_versions_get,
970
- self.models_versions_delete,
971
- self.trainings_create, # Training is started via model version path
972
- self.predictions_list,
973
- self.predictions_create,
974
- self.predictions_get,
975
- self.predictions_cancel,
976
- self.trainings_list,
977
- self.trainings_get,
978
- self.trainings_cancel,
979
- self.webhooks_default_secret_get,
980
- ]