|
8 | 8 |
|
9 | 9 | from pydantic import BaseModel |
10 | 10 |
|
| 11 | +from llama_stack.apis.providers.connection import ProviderConnectionInfo |
11 | 12 | from llama_stack.apis.version import LLAMA_STACK_API_V1 |
12 | 13 | from llama_stack.providers.datatypes import HealthResponse |
13 | 14 | from llama_stack.schema_utils import json_schema_type, webmethod |
@@ -40,6 +41,85 @@ class ListProvidersResponse(BaseModel): |
40 | 41 | data: list[ProviderInfo] |
41 | 42 |
|
42 | 43 |
|
| 44 | +# ===== Dynamic Provider Management API Models ===== |
| 45 | + |
| 46 | + |
| 47 | +@json_schema_type |
| 48 | +class RegisterProviderRequest(BaseModel): |
| 49 | + """Request to register a new dynamic provider. |
| 50 | +
|
| 51 | + :param provider_id: Unique identifier for the provider instance |
| 52 | + :param api: API namespace (e.g., 'inference', 'vector_io', 'safety') |
| 53 | + :param provider_type: Provider type identifier (e.g., 'remote::openai', 'inline::faiss') |
| 54 | + :param config: Provider-specific configuration (API keys, endpoints, etc.) |
| 55 | + :param attributes: Optional key-value attributes for ABAC access control |
| 56 | + """ |
| 57 | + |
| 58 | + provider_id: str |
| 59 | + api: str |
| 60 | + provider_type: str |
| 61 | + config: dict[str, Any] |
| 62 | + attributes: dict[str, list[str]] | None = None |
| 63 | + |
| 64 | + |
| 65 | +@json_schema_type |
| 66 | +class RegisterProviderResponse(BaseModel): |
| 67 | + """Response after registering a provider. |
| 68 | +
|
| 69 | + :param provider: Information about the registered provider |
| 70 | + """ |
| 71 | + |
| 72 | + provider: ProviderConnectionInfo |
| 73 | + |
| 74 | + |
| 75 | +@json_schema_type |
| 76 | +class UpdateProviderRequest(BaseModel): |
| 77 | + """Request to update an existing provider's configuration. |
| 78 | +
|
| 79 | + :param config: New configuration parameters (will be merged with existing) |
| 80 | + :param attributes: Optional updated attributes for access control |
| 81 | + """ |
| 82 | + |
| 83 | + config: dict[str, Any] | None = None |
| 84 | + attributes: dict[str, list[str]] | None = None |
| 85 | + |
| 86 | + |
| 87 | +@json_schema_type |
| 88 | +class UpdateProviderResponse(BaseModel): |
| 89 | + """Response after updating a provider. |
| 90 | +
|
| 91 | + :param provider: Updated provider information |
| 92 | + """ |
| 93 | + |
| 94 | + provider: ProviderConnectionInfo |
| 95 | + |
| 96 | + |
| 97 | +@json_schema_type |
| 98 | +class UnregisterProviderResponse(BaseModel): |
| 99 | + """Response after unregistering a provider. |
| 100 | +
|
| 101 | + :param success: Whether the operation succeeded |
| 102 | + :param message: Optional status message |
| 103 | + """ |
| 104 | + |
| 105 | + success: bool |
| 106 | + message: str | None = None |
| 107 | + |
| 108 | + |
| 109 | +@json_schema_type |
| 110 | +class TestProviderConnectionResponse(BaseModel): |
| 111 | + """Response from testing a provider connection. |
| 112 | +
|
| 113 | + :param success: Whether the connection test succeeded |
| 114 | + :param health: Health status from the provider |
| 115 | + :param error_message: Error message if test failed |
| 116 | + """ |
| 117 | + |
| 118 | + success: bool |
| 119 | + health: HealthResponse | None = None |
| 120 | + error_message: str | None = None |
| 121 | + |
| 122 | + |
43 | 123 | @runtime_checkable |
44 | 124 | class Providers(Protocol): |
45 | 125 | """Providers |
@@ -67,3 +147,71 @@ async def inspect_provider(self, provider_id: str) -> ProviderInfo: |
67 | 147 | :returns: A ProviderInfo object containing the provider's details. |
68 | 148 | """ |
69 | 149 | ... |
| 150 | + |
| 151 | + # ===== Dynamic Provider Management Methods ===== |
| 152 | + |
| 153 | + @webmethod(route="/admin/providers", method="POST", level=LLAMA_STACK_API_V1) |
| 154 | + async def register_provider( |
| 155 | + self, |
| 156 | + provider_id: str, |
| 157 | + api: str, |
| 158 | + provider_type: str, |
| 159 | + config: dict[str, Any], |
| 160 | + attributes: dict[str, list[str]] | None = None, |
| 161 | + ) -> RegisterProviderResponse: |
| 162 | + """Register a new dynamic provider. |
| 163 | +
|
| 164 | + Register a new provider instance at runtime. The provider will be validated, |
| 165 | + instantiated, and persisted to the kvstore. Requires appropriate ABAC permissions. |
| 166 | +
|
| 167 | + :param provider_id: Unique identifier for this provider instance. |
| 168 | + :param api: API namespace this provider implements. |
| 169 | + :param provider_type: Provider type (e.g., 'remote::openai'). |
| 170 | + :param config: Provider configuration (API keys, endpoints, etc.). |
| 171 | + :param attributes: Optional attributes for ABAC access control. |
| 172 | + :returns: RegisterProviderResponse with the registered provider info. |
| 173 | + """ |
| 174 | + ... |
| 175 | + |
| 176 | + @webmethod(route="/admin/providers/{provider_id}", method="PUT", level=LLAMA_STACK_API_V1) |
| 177 | + async def update_provider( |
| 178 | + self, |
| 179 | + provider_id: str, |
| 180 | + config: dict[str, Any] | None = None, |
| 181 | + attributes: dict[str, list[str]] | None = None, |
| 182 | + ) -> UpdateProviderResponse: |
| 183 | + """Update an existing provider's configuration. |
| 184 | +
|
| 185 | + Update the configuration and/or attributes of a dynamic provider. The provider |
| 186 | + will be re-instantiated with the new configuration (hot-reload). Static providers |
| 187 | + from run.yaml cannot be updated. |
| 188 | +
|
| 189 | + :param provider_id: ID of the provider to update |
| 190 | + :param config: New configuration parameters (merged with existing) |
| 191 | + :param attributes: New attributes for access control |
| 192 | + :returns: UpdateProviderResponse with updated provider info |
| 193 | + """ |
| 194 | + ... |
| 195 | + |
| 196 | + @webmethod(route="/admin/providers/{provider_id}", method="DELETE", level=LLAMA_STACK_API_V1) |
| 197 | + async def unregister_provider(self, provider_id: str) -> None: |
| 198 | + """Unregister a dynamic provider. |
| 199 | +
|
| 200 | + Remove a dynamic provider, shutting down its instance and removing it from |
| 201 | + the kvstore. Static providers from run.yaml cannot be unregistered. |
| 202 | +
|
| 203 | + :param provider_id: ID of the provider to unregister. |
| 204 | + """ |
| 205 | + ... |
| 206 | + |
| 207 | + @webmethod(route="/providers/{provider_id}/test", method="POST", level=LLAMA_STACK_API_V1) |
| 208 | + async def test_provider_connection(self, provider_id: str) -> TestProviderConnectionResponse: |
| 209 | + """Test a provider connection. |
| 210 | +
|
| 211 | + Execute a health check on a provider to verify it is reachable and functioning. |
| 212 | + Works for both static and dynamic providers. |
| 213 | +
|
| 214 | + :param provider_id: ID of the provider to test. |
| 215 | + :returns: TestProviderConnectionResponse with health status. |
| 216 | + """ |
| 217 | + ... |
0 commit comments