-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
51 lines (39 loc) · 1.36 KB
/
Copy pathapi.py
File metadata and controls
51 lines (39 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Minimal FastAPI wrapper around the OLAP MF query compiler.
Proves the existing engine can run as a web service:
POST /execute → generate(...) → JSON response
"""
import os
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, Field
from engine import generate
app = FastAPI(title="OLAP Query Processing Engine")
class ExecuteRequest(BaseModel):
query: str = Field(
...,
description=(
"Path to a phi-parameter input file (e.g. example_inputs/mf_1.txt), "
"or the raw phi-parameter text itself."
),
)
class ExecuteResponse(BaseModel):
status: str
generated_code: str
@app.post("/execute", response_model=ExecuteResponse)
def execute(request: ExecuteRequest) -> ExecuteResponse:
"""
Receive a query, run the existing compiler, return JSON.
"""
query = request.query.strip()
if not query:
raise HTTPException(status_code=400, detail="query must not be empty")
try:
if os.path.isfile(query):
code = generate(query)
else:
code = generate(phi_text=query)
return ExecuteResponse(status="ok", generated_code=code)
except FileNotFoundError as e:
raise HTTPException(status_code=404, detail=str(e)) from e
except Exception as e:
raise HTTPException(status_code=400, detail=str(e)) from e