mirror of
https://github.com/invariantlabs-ai/invariant-gateway.git
synced 2026-06-11 15:27:46 +02:00
Show logs if the docker container doesn't start on doing up(). Tested when the guardrails file contained unparseable policy.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from config_manager import GatewayConfig
|
||||
from common.config_manager import GatewayConfig
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
||||
@@ -17,18 +17,14 @@ def create_annotations_from_guardrails_errors(
|
||||
annotations = []
|
||||
for error in guardrails_errors:
|
||||
content = error.get("args")[0]
|
||||
address = None
|
||||
for r in error.get("ranges", []):
|
||||
# Choose the longest path as the address
|
||||
if address is None or len(r) > len(address):
|
||||
address = r
|
||||
annotations.append(
|
||||
AnnotationCreate(
|
||||
content=content,
|
||||
address=address,
|
||||
extra_metadata={"source": "guardrails-error"},
|
||||
annotations.append(
|
||||
AnnotationCreate(
|
||||
content=content,
|
||||
address=r,
|
||||
extra_metadata={"source": "guardrails-error"},
|
||||
)
|
||||
)
|
||||
)
|
||||
return annotations
|
||||
|
||||
|
||||
@@ -36,6 +32,7 @@ async def push_trace(
|
||||
messages: List[List[Dict[str, Any]]],
|
||||
dataset_name: str,
|
||||
invariant_authorization: str,
|
||||
annotations: List[List[AnnotationCreate]] = None,
|
||||
) -> PushTracesResponse:
|
||||
"""Pushes traces to the dataset on the Invariant Explorer.
|
||||
|
||||
@@ -55,7 +52,9 @@ async def push_trace(
|
||||
[{k: v for k, v in msg.items() if v is not None} for msg in msg_list]
|
||||
for msg_list in messages
|
||||
]
|
||||
request = PushTracesRequest(messages=update_messages, dataset=dataset_name)
|
||||
request = PushTracesRequest(
|
||||
messages=update_messages, annotations=annotations, dataset=dataset_name
|
||||
)
|
||||
client = AsyncClient(
|
||||
api_url=os.getenv("INVARIANT_API_URL", DEFAULT_API_URL).rstrip("/"),
|
||||
api_key=invariant_authorization.split("Bearer ")[1],
|
||||
|
||||
@@ -332,9 +332,14 @@ async def handle_non_streaming_response(
|
||||
response_code = response.status_code
|
||||
|
||||
if context.config and context.config.guardrails:
|
||||
# Block on the guardrails check
|
||||
messages = list(context.request_json.get("messages", []))
|
||||
messages += [choice["message"] for choice in json_response.get("choices", [])]
|
||||
# TODO: Remove this once the guardrails API is fixed
|
||||
for message in messages:
|
||||
if "tool_calls" in message and message["tool_calls"] is None:
|
||||
message["tool_calls"] = []
|
||||
|
||||
# Block on the guardrails check
|
||||
guardrails_execution_result = await check_guardrails(
|
||||
messages=messages,
|
||||
guardrails=context.config.guardrails,
|
||||
|
||||
@@ -32,9 +32,20 @@ up() {
|
||||
# Start Docker Compose with the correct environment variable
|
||||
GUARDRAILS_FILE_PATH="$GUARDRAILS_FILE_PATH" docker compose -f docker-compose.local.yml up -d
|
||||
|
||||
# Get the status of the container
|
||||
sleep 2
|
||||
|
||||
if [ -z "$(docker ps -qf 'name=invariant-gateway')" ]; then
|
||||
echo "The invariant-gateway container failed to start."
|
||||
docker logs invariant-gateway | tail -20 # Show last 20 lines of logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Gateway started at http://localhost:8005/api/v1/gateway/"
|
||||
echo "See http://localhost:8005/api/v1/gateway/docs for API documentation"
|
||||
echo "Using Guardrails File: ${GUARDRAILS_FILE_PATH:-None}"
|
||||
if [ -n "$GUARDRAILS_FILE_PATH" ]; then
|
||||
echo "Using Guardrails File: $GUARDRAILS_FILE_PATH"
|
||||
fi
|
||||
}
|
||||
|
||||
build() {
|
||||
|
||||
Reference in New Issue
Block a user