Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
-
from pydantic import BaseModel,
|
| 3 |
from typing import Dict, Any, List, Literal
|
| 4 |
from datetime import datetime
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# Optional tracing:
|
| 8 |
TRACING = False
|
| 9 |
try:
|
| 10 |
if os.getenv("TRACELOOP_API_KEY"):
|
|
@@ -15,7 +15,8 @@ try:
|
|
| 15 |
except Exception:
|
| 16 |
TRACING = False
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
app = FastAPI()
|
| 21 |
|
|
@@ -30,7 +31,8 @@ class Metrics(BaseModel):
|
|
| 30 |
class AuditResult(BaseModel):
|
| 31 |
metrics: Metrics
|
| 32 |
decision: Literal['APPROVE','REWORK']
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
AUDIT_SCHEMA = {
|
| 36 |
"type": "object",
|
|
@@ -42,6 +44,7 @@ AUDIT_SCHEMA = {
|
|
| 42 |
"required": ["decision","metrics","deltas"]
|
| 43 |
}
|
| 44 |
guard = Guard().configure(output_schema=AUDIT_SCHEMA)
|
|
|
|
| 45 |
|
| 46 |
@app.get("/health")
|
| 47 |
def health():
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel, Field, confloat
|
| 3 |
from typing import Dict, Any, List, Literal
|
| 4 |
from datetime import datetime
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# Optional tracing: initialize ONLY if key exists (won't crash if missing)
|
| 8 |
TRACING = False
|
| 9 |
try:
|
| 10 |
if os.getenv("TRACELOOP_API_KEY"):
|
|
|
|
| 15 |
except Exception:
|
| 16 |
TRACING = False
|
| 17 |
|
| 18 |
+
# Guardrails: schema guard only (semantic validators optional)
|
| 19 |
+
from guardrails import Guard
|
| 20 |
|
| 21 |
app = FastAPI()
|
| 22 |
|
|
|
|
| 31 |
class AuditResult(BaseModel):
|
| 32 |
metrics: Metrics
|
| 33 |
decision: Literal['APPROVE','REWORK']
|
| 34 |
+
# Pydantic v2 uses min_length/max_length instead of v1's conlist(min_items)
|
| 35 |
+
deltas: List[str] = Field(default_factory=list, min_length=0)
|
| 36 |
|
| 37 |
AUDIT_SCHEMA = {
|
| 38 |
"type": "object",
|
|
|
|
| 44 |
"required": ["decision","metrics","deltas"]
|
| 45 |
}
|
| 46 |
guard = Guard().configure(output_schema=AUDIT_SCHEMA)
|
| 47 |
+
# Pydantic v2 migration: min_items → min_length etc. :contentReference[oaicite:1]{index=1}
|
| 48 |
|
| 49 |
@app.get("/health")
|
| 50 |
def health():
|