mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-16 23:03:49 +00:00
improved registration flow
This commit is contained in:
parent
39f0c5f544
commit
0eaca98229
10 changed files with 95 additions and 26 deletions
|
@ -36,8 +36,3 @@ class Resource(BaseModel):
|
|||
type: ResourceType = Field(
|
||||
description="Type of resource (e.g. 'model', 'shield', 'memory_bank', etc.)"
|
||||
)
|
||||
|
||||
# If the provider_resource_identifier is not set, set it to the identifier
|
||||
def model_post_init(self, __context) -> None:
|
||||
if self.provider_resource_identifier is None:
|
||||
self.provider_resource_identifier = self.identifier
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
# the root directory of this source tree.
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
|
@ -35,12 +34,23 @@ class ShieldsClient(Shields):
|
|||
response.raise_for_status()
|
||||
return [Shield(**x) for x in response.json()]
|
||||
|
||||
async def register_shield(self, shield: Shield) -> None:
|
||||
async def register_shield(
|
||||
self,
|
||||
shield_id: str,
|
||||
shield_type: ShieldType,
|
||||
provider_resource_identifier: Optional[str],
|
||||
provider_id: Optional[str],
|
||||
params: Optional[Dict[str, Any]],
|
||||
) -> None:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(
|
||||
f"{self.base_url}/shields/register",
|
||||
json={
|
||||
"shield": json.loads(shield.json()),
|
||||
"shield_id": shield_id,
|
||||
"shield_type": shield_type,
|
||||
"provider_resource_identifier": provider_resource_identifier,
|
||||
"provider_id": provider_id,
|
||||
"params": params,
|
||||
},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
|
|
@ -38,4 +38,11 @@ class Shields(Protocol):
|
|||
async def get_shield(self, identifier: str) -> Optional[Shield]: ...
|
||||
|
||||
@webmethod(route="/shields/register", method="POST")
|
||||
async def register_shield(self, shield: Shield) -> None: ...
|
||||
async def register_shield(
|
||||
self,
|
||||
shield_id: str,
|
||||
shield_type: ShieldType,
|
||||
provider_resource_identifier: Optional[str] = None,
|
||||
provider_id: Optional[str] = None,
|
||||
params: Optional[Dict[str, Any]] = None,
|
||||
) -> Shield: ...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue