mirror of
https://github.com/invariantlabs-ai/invariant-gateway.git
synced 2026-07-08 11:57:52 +02:00
add session id
This commit is contained in:
@@ -17,12 +17,21 @@ from gateway.common.authorization import (
|
||||
)
|
||||
from gateway.common.guardrails import Guardrail
|
||||
|
||||
import uuid
|
||||
|
||||
# Timestamps of last API calls per guardrails string
|
||||
_guardrails_cache = {}
|
||||
# Locks per guardrails string
|
||||
_guardrails_locks = {}
|
||||
|
||||
|
||||
# Temporary session ID generation
|
||||
def generate_session_id():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
session_id = generate_session_id()
|
||||
|
||||
|
||||
def rate_limit(expiration_time: int = 3600):
|
||||
"""
|
||||
Decorator to limit API calls to once per expiration_time seconds
|
||||
@@ -153,6 +162,7 @@ async def check_guardrails(
|
||||
headers={
|
||||
"Authorization": context.get_guardrailing_authorization(),
|
||||
"Accept": CONTENT_TYPE_JSON,
|
||||
"X-Session-Id": session_id,
|
||||
},
|
||||
timeout=5,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user