mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 12:07:34 +00:00
add safety/list_shields to query available shields
This commit is contained in:
parent
44fe099866
commit
b8914bb56f
3 changed files with 52 additions and 3 deletions
|
@ -13,11 +13,10 @@ import fire
|
|||
import httpx
|
||||
|
||||
from llama_models.llama3.api.datatypes import * # noqa: F403
|
||||
from llama_stack.distribution.datatypes import RemoteProviderConfig
|
||||
from pydantic import BaseModel
|
||||
from termcolor import cprint
|
||||
|
||||
from llama_stack.distribution.datatypes import RemoteProviderConfig
|
||||
|
||||
from llama_stack.apis.safety import * # noqa: F403
|
||||
|
||||
|
||||
|
@ -62,6 +61,24 @@ class SafetyClient(Safety):
|
|||
content = response.json()
|
||||
return RunShieldResponse(**content)
|
||||
|
||||
async def list_shields(self) -> ListShieldsResponse:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(
|
||||
f"{self.base_url}/safety/list_shields",
|
||||
json={},
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=20,
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
content = await response.aread()
|
||||
error = f"Error: HTTP {response.status_code} {content.decode()}"
|
||||
cprint(error, "red")
|
||||
raise Exception(error)
|
||||
|
||||
content = response.json()
|
||||
return ListShieldsResponse(**content)
|
||||
|
||||
|
||||
async def run_main(host: str, port: int):
|
||||
client = SafetyClient(f"http://{host}:{port}")
|
||||
|
@ -83,6 +100,9 @@ async def run_main(host: str, port: int):
|
|||
)
|
||||
print(response)
|
||||
|
||||
response = await client.list_shields()
|
||||
print(response)
|
||||
|
||||
|
||||
def main(host: str, port: int):
|
||||
asyncio.run(run_main(host, port))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue