Spaces:
Runtime error
Runtime error
trakshan-mishra commited on
Commit Β·
84d68b4
1
Parent(s): 28aea4f
Fix OpenAPI schema for ChatGPT Actions support
Browse files
diffcontext-service/backend/main.py
CHANGED
|
@@ -51,6 +51,15 @@ class InlineRequest(BaseModel):
|
|
| 51 |
files: Dict[str, str] # filename -> source code
|
| 52 |
symbol: str # which function to analyze
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# ββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 56 |
|
|
@@ -227,7 +236,7 @@ def _list_symbols(repo_path: str) -> List[str]:
|
|
| 227 |
|
| 228 |
# ββ Routes βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 229 |
|
| 230 |
-
@app.get("/")
|
| 231 |
def root():
|
| 232 |
return {
|
| 233 |
"service": "DiffContext API",
|
|
@@ -243,11 +252,12 @@ def root():
|
|
| 243 |
}
|
| 244 |
|
| 245 |
|
| 246 |
-
@app.get("/health")
|
| 247 |
def health():
|
| 248 |
return {"status": "ok"}
|
| 249 |
|
| 250 |
|
|
|
|
| 251 |
@app.post("/upload")
|
| 252 |
async def upload_repo(file: UploadFile = File(...)):
|
| 253 |
"""
|
|
@@ -433,3 +443,37 @@ try:
|
|
| 433 |
except ImportError:
|
| 434 |
pass
|
| 435 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
files: Dict[str, str] # filename -> source code
|
| 52 |
symbol: str # which function to analyze
|
| 53 |
|
| 54 |
+
class HealthResponse(BaseModel):
|
| 55 |
+
status: str
|
| 56 |
+
|
| 57 |
+
class RootResponse(BaseModel):
|
| 58 |
+
service: str
|
| 59 |
+
docs: str
|
| 60 |
+
endpoints: List[str]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
|
| 64 |
# ββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 65 |
|
|
|
|
| 236 |
|
| 237 |
# ββ Routes βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 238 |
|
| 239 |
+
@app.get("/", response_model=RootResponse)
|
| 240 |
def root():
|
| 241 |
return {
|
| 242 |
"service": "DiffContext API",
|
|
|
|
| 252 |
}
|
| 253 |
|
| 254 |
|
| 255 |
+
@app.get("/health", response_model=HealthResponse)
|
| 256 |
def health():
|
| 257 |
return {"status": "ok"}
|
| 258 |
|
| 259 |
|
| 260 |
+
|
| 261 |
@app.post("/upload")
|
| 262 |
async def upload_repo(file: UploadFile = File(...)):
|
| 263 |
"""
|
|
|
|
| 443 |
except ImportError:
|
| 444 |
pass
|
| 445 |
|
| 446 |
+
|
| 447 |
+
# ββ Custom OpenAPI schema for ChatGPT Actions ββββββββββββββββββββββββββββββββ
|
| 448 |
+
from fastapi.openapi.utils import get_openapi
|
| 449 |
+
|
| 450 |
+
def custom_openapi():
|
| 451 |
+
if app.openapi_schema:
|
| 452 |
+
return app.openapi_schema
|
| 453 |
+
|
| 454 |
+
schema = get_openapi(
|
| 455 |
+
title="DiffContext API",
|
| 456 |
+
version="1.0.0",
|
| 457 |
+
description="Analyse your Python code's blast radius β which functions break when you change one?",
|
| 458 |
+
routes=app.routes,
|
| 459 |
+
)
|
| 460 |
+
|
| 461 |
+
# Force the mandatory servers URL for GPT Actions
|
| 462 |
+
schema["servers"] = [
|
| 463 |
+
{
|
| 464 |
+
"url": "https://trakshan-diffcontext.hf.space"
|
| 465 |
+
}
|
| 466 |
+
]
|
| 467 |
+
|
| 468 |
+
# Exclude SSE / message endpoints from GPT Actions schema
|
| 469 |
+
paths = schema.get("paths", {})
|
| 470 |
+
paths_to_remove = [p for p in paths if p.startswith("/sse") or p.startswith("/messages")]
|
| 471 |
+
for p in paths_to_remove:
|
| 472 |
+
paths.pop(p, None)
|
| 473 |
+
|
| 474 |
+
app.openapi_schema = schema
|
| 475 |
+
return schema
|
| 476 |
+
|
| 477 |
+
app.openapi = custom_openapi
|
| 478 |
+
|
| 479 |
+
|