mirror of
https://github.com/invariantlabs-ai/invariant-gateway.git
synced 2026-08-23 17:12:29 +02:00
Use pyproject.toml instead of requirements.txt and fix some broken tests.
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
FROM python:3.10
|
||||
|
||||
COPY ./requirements.txt /srv/gateway/requirements.txt
|
||||
WORKDIR /srv/gateway
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY . /srv/gateway
|
||||
|
||||
# Ensure run.sh is executable
|
||||
RUN chmod +x /srv/gateway/run.sh
|
||||
WORKDIR /srv/gateway
|
||||
|
||||
# Run the application
|
||||
CMD ["./run.sh"]
|
||||
@@ -8,8 +8,7 @@ from typing import Optional
|
||||
import fastapi
|
||||
from httpx import HTTPStatusError
|
||||
|
||||
from common.guardrails import Guardrail, GuardrailAction, GuardrailRuleSet
|
||||
from common.authorization import extract_authorization_from_headers
|
||||
from gateway.common.guardrails import Guardrail, GuardrailAction, GuardrailRuleSet
|
||||
|
||||
|
||||
def extract_policy_from_headers(request: Optional[fastapi.Request]) -> Optional[str]:
|
||||
@@ -40,7 +39,7 @@ class GatewayConfig:
|
||||
Loads the guardrails from the file specified in GUARDRAILS_FILE_PATH.
|
||||
Returns the guardrails file content as a string.
|
||||
"""
|
||||
from integrations.guardrails import _preload
|
||||
from gateway.integrations.guardrails import _preload
|
||||
|
||||
guardrails_file = os.getenv("GUARDRAILS_FILE_PATH", "")
|
||||
if not guardrails_file:
|
||||
|
||||
@@ -5,9 +5,9 @@ from typing import Any, Dict, Optional
|
||||
|
||||
import fastapi
|
||||
|
||||
from common.config_manager import GatewayConfig
|
||||
from common.guardrails import GuardrailRuleSet, Guardrail, GuardrailAction
|
||||
from common.authorization import (
|
||||
from gateway.common.config_manager import GatewayConfig
|
||||
from gateway.common.guardrails import GuardrailRuleSet, Guardrail, GuardrailAction
|
||||
from gateway.common.authorization import (
|
||||
extract_guardrail_service_authorization_from_headers,
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Any, Dict, List
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from common.guardrails import GuardrailRuleSet, Guardrail, GuardrailAction
|
||||
from gateway.common.guardrails import GuardrailRuleSet, Guardrail, GuardrailAction
|
||||
from invariant_sdk.async_client import AsyncClient
|
||||
from invariant_sdk.types.push_traces import PushTracesRequest, PushTracesResponse
|
||||
from invariant_sdk.types.annotations import AnnotationCreate
|
||||
|
||||
@@ -8,9 +8,10 @@ from functools import wraps
|
||||
|
||||
from fastapi import HTTPException
|
||||
import httpx
|
||||
from common.guardrails import Guardrail
|
||||
from common.request_context import RequestContext
|
||||
from common.authorization import (
|
||||
|
||||
from gateway.common.guardrails import Guardrail
|
||||
from gateway.common.request_context import RequestContext
|
||||
from gateway.common.authorization import (
|
||||
INVARIANT_GUARDRAIL_SERVICE_AUTHORIZATION_HEADER,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
fastapi==0.115.7
|
||||
httpx==0.28.1
|
||||
invariant-ai>=0.2.1
|
||||
invariant-sdk>=0.0.10
|
||||
starlette-compress==1.4.0
|
||||
uvicorn==0.34.0
|
||||
@@ -8,27 +8,27 @@ import httpx
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Request, Response
|
||||
from starlette.responses import StreamingResponse
|
||||
|
||||
from common.authorization import extract_authorization_from_headers
|
||||
from common.config_manager import (
|
||||
from gateway.common.authorization import extract_authorization_from_headers
|
||||
from gateway.common.config_manager import (
|
||||
GatewayConfig,
|
||||
GatewayConfigManager,
|
||||
GuardrailsInHeader,
|
||||
)
|
||||
from common.constants import (
|
||||
from gateway.common.constants import (
|
||||
CLIENT_TIMEOUT,
|
||||
IGNORED_HEADERS,
|
||||
)
|
||||
from common.guardrails import GuardrailAction, GuardrailRuleSet
|
||||
from common.request_context import RequestContext
|
||||
from converters.anthropic_to_invariant import (
|
||||
from gateway.common.guardrails import GuardrailAction, GuardrailRuleSet
|
||||
from gateway.common.request_context import RequestContext
|
||||
from gateway.converters.anthropic_to_invariant import (
|
||||
convert_anthropic_to_invariant_message_format,
|
||||
)
|
||||
from integrations.explorer import (
|
||||
from gateway.integrations.explorer import (
|
||||
create_annotations_from_guardrails_errors,
|
||||
fetch_guardrails_from_explorer,
|
||||
push_trace,
|
||||
)
|
||||
from integrations.guardrails import (
|
||||
from gateway.integrations.guardrails import (
|
||||
ExtraItem,
|
||||
InstrumentedResponse,
|
||||
InstrumentedStreamingResponse,
|
||||
|
||||
@@ -8,25 +8,25 @@ import httpx
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from common.authorization import extract_authorization_from_headers
|
||||
from common.config_manager import (
|
||||
from gateway.common.authorization import extract_authorization_from_headers
|
||||
from gateway.common.config_manager import (
|
||||
GatewayConfig,
|
||||
GatewayConfigManager,
|
||||
GuardrailsInHeader,
|
||||
)
|
||||
from common.constants import (
|
||||
from gateway.common.constants import (
|
||||
CLIENT_TIMEOUT,
|
||||
IGNORED_HEADERS,
|
||||
)
|
||||
from common.guardrails import GuardrailAction, GuardrailRuleSet
|
||||
from common.request_context import RequestContext
|
||||
from converters.gemini_to_invariant import convert_request, convert_response
|
||||
from integrations.explorer import (
|
||||
from gateway.common.guardrails import GuardrailAction, GuardrailRuleSet
|
||||
from gateway.common.request_context import RequestContext
|
||||
from gateway.converters.gemini_to_invariant import convert_request, convert_response
|
||||
from gateway.integrations.explorer import (
|
||||
create_annotations_from_guardrails_errors,
|
||||
fetch_guardrails_from_explorer,
|
||||
push_trace,
|
||||
)
|
||||
from integrations.guardrails import (
|
||||
from gateway.integrations.guardrails import (
|
||||
ExtraItem,
|
||||
InstrumentedResponse,
|
||||
InstrumentedStreamingResponse,
|
||||
|
||||
@@ -8,24 +8,24 @@ import httpx
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Request, Response
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from common.authorization import extract_authorization_from_headers
|
||||
from common.config_manager import (
|
||||
from gateway.common.authorization import extract_authorization_from_headers
|
||||
from gateway.common.config_manager import (
|
||||
GatewayConfig,
|
||||
GatewayConfigManager,
|
||||
GuardrailsInHeader,
|
||||
)
|
||||
from common.constants import (
|
||||
from gateway.common.constants import (
|
||||
CLIENT_TIMEOUT,
|
||||
IGNORED_HEADERS,
|
||||
)
|
||||
from common.guardrails import GuardrailAction, GuardrailRuleSet
|
||||
from common.request_context import RequestContext
|
||||
from integrations.explorer import (
|
||||
from gateway.common.guardrails import GuardrailAction, GuardrailRuleSet
|
||||
from gateway.common.request_context import RequestContext
|
||||
from gateway.integrations.explorer import (
|
||||
create_annotations_from_guardrails_errors,
|
||||
fetch_guardrails_from_explorer,
|
||||
push_trace,
|
||||
)
|
||||
from integrations.guardrails import (
|
||||
from gateway.integrations.guardrails import (
|
||||
ExtraItem,
|
||||
InstrumentedResponse,
|
||||
InstrumentedStreamingResponse,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
export PYTHONPATH=/srv
|
||||
|
||||
# Validate configuration
|
||||
python validate_config.py
|
||||
|
||||
|
||||
+4
-3
@@ -2,11 +2,12 @@
|
||||
|
||||
import fastapi
|
||||
import uvicorn
|
||||
from routes.anthropic import gateway as anthropic_gateway
|
||||
from routes.gemini import gateway as gemini_gateway
|
||||
from routes.open_ai import gateway as open_ai_gateway
|
||||
from starlette_compress import CompressMiddleware
|
||||
|
||||
from gateway.routes.anthropic import gateway as anthropic_gateway
|
||||
from gateway.routes.gemini import gateway as gemini_gateway
|
||||
from gateway.routes.open_ai import gateway as open_ai_gateway
|
||||
|
||||
app = fastapi.app = fastapi.FastAPI(
|
||||
docs_url="/api/v1/gateway/docs",
|
||||
redoc_url="/api/v1/gateway/redoc",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
from common.config_manager import GatewayConfigManager
|
||||
from gateway.common.config_manager import GatewayConfigManager
|
||||
|
||||
try:
|
||||
_ = GatewayConfigManager.get_config()
|
||||
|
||||
Reference in New Issue
Block a user