mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
Litellm dev 12 23 2024 p1 (#7383)
* feat(guardrails_endpoint.py): new `/guardrails/list` endpoint Allow users to view what the available guardrails are * docs: document new `/guardrails/list` endpoint * docs(enterprise.md): update docs * fix(openai/transcription/handler.py): support cost tracking on vtt + srt formats * fix(openai/transcriptions/handler.py): default to 'verbose_json' response format if 'text' or 'json' response_format received. ensures 'duration' param is received for all audio transcription requests * fix: fix linting errors * fix: remove unused import
This commit is contained in:
parent
564ecc728d
commit
db59e08958
11 changed files with 169 additions and 51 deletions
50
litellm/proxy/guardrails/guardrail_endpoints.py
Normal file
50
litellm/proxy/guardrails/guardrail_endpoints.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
CRUD ENDPOINTS FOR GUARDRAILS
|
||||
"""
|
||||
|
||||
from typing import Dict, List, Optional, cast
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from litellm.proxy._types import CommonProxyErrors
|
||||
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||
|
||||
#### GUARDRAILS ENDPOINTS ####
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def _get_guardrail_names_from_config(guardrails_config: List[Dict]) -> List[str]:
|
||||
return [guardrail["guardrail_name"] for guardrail in guardrails_config]
|
||||
|
||||
|
||||
@router.get(
|
||||
"/guardrails/list",
|
||||
tags=["Guardrails"],
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
)
|
||||
async def list_guardrails():
|
||||
"""
|
||||
List the guardrails that are available on the proxy server
|
||||
"""
|
||||
from litellm.proxy.proxy_server import premium_user, proxy_config
|
||||
|
||||
if not premium_user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail={
|
||||
"error": CommonProxyErrors.not_premium_user.value,
|
||||
},
|
||||
)
|
||||
|
||||
config = proxy_config.config
|
||||
|
||||
_guardrails_config = cast(Optional[list[dict]], config.get("guardrails"))
|
||||
|
||||
if _guardrails_config is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail={"error": "No guardrails found in config"},
|
||||
)
|
||||
|
||||
return _get_guardrail_names_from_config(config["guardrails"])
|
Loading…
Add table
Add a link
Reference in a new issue