mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-02 10:21:52 +00:00
Merge pull request #21422 from BerriAI/fix/lakera-keyerror-missing-api-key
fix(lakera-guardrail): avoid KeyError on missing LAKERA_API_KEY during initialization
This commit is contained in:
@@ -59,7 +59,7 @@ class lakeraAI_Moderation(CustomGuardrail):
|
||||
self.async_handler = get_async_httpx_client(
|
||||
llm_provider=httpxSpecialProvider.GuardrailCallback
|
||||
)
|
||||
self.lakera_api_key = api_key or os.environ["LAKERA_API_KEY"]
|
||||
self.lakera_api_key = api_key or os.environ.get("LAKERA_API_KEY") or ""
|
||||
self.moderation_check = moderation_check
|
||||
self.category_thresholds = category_thresholds
|
||||
self.api_base = (
|
||||
|
||||
@@ -54,7 +54,7 @@ class LakeraAIGuardrail(CustomGuardrail):
|
||||
self.async_handler = get_async_httpx_client(
|
||||
llm_provider=httpxSpecialProvider.GuardrailCallback
|
||||
)
|
||||
self.lakera_api_key = api_key or os.environ["LAKERA_API_KEY"]
|
||||
self.lakera_api_key = api_key or os.environ.get("LAKERA_API_KEY") or ""
|
||||
self.project_id = project_id
|
||||
self.api_base = (
|
||||
api_base or get_secret_str("LAKERA_API_BASE") or "https://api.lakera.ai"
|
||||
|
||||
@@ -30,7 +30,8 @@ from litellm.proxy.proxy_server import ( # Replace with the actual module where
|
||||
def client():
|
||||
filepath = os.path.dirname(os.path.abspath(__file__))
|
||||
config_fp = f"{filepath}/test_configs/test_guardrails_config.yaml"
|
||||
asyncio.run(initialize(config=config_fp))
|
||||
with mock.patch("litellm.proxy.proxy_server.premium_user", True):
|
||||
asyncio.run(initialize(config=config_fp))
|
||||
from litellm.proxy.proxy_server import app
|
||||
|
||||
return TestClient(app)
|
||||
|
||||
Reference in New Issue
Block a user