Spaces:
Running
Running
Update api.py
Browse files
api.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
-
from typing import Any, Dict
|
| 4 |
import os
|
| 5 |
|
| 6 |
from process_aware_rag import ProcessAwareRAG
|
|
@@ -8,8 +8,14 @@ from process_aware_rag import ProcessAwareRAG
|
|
| 8 |
app = FastAPI(title="Legal Process Guide API", version="1.0.0")
|
| 9 |
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
class QueryRequest(BaseModel):
|
| 12 |
query: str
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
class QueryResponse(BaseModel):
|
|
@@ -31,7 +37,8 @@ def health() -> Dict[str, str]:
|
|
| 31 |
|
| 32 |
@app.post("/query", response_model=QueryResponse)
|
| 33 |
def query_endpoint(req: QueryRequest) -> QueryResponse:
|
| 34 |
-
|
|
|
|
| 35 |
return QueryResponse(
|
| 36 |
response=result["response"],
|
| 37 |
classification=result["classification"],
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
+
from typing import Any, Dict, List
|
| 4 |
import os
|
| 5 |
|
| 6 |
from process_aware_rag import ProcessAwareRAG
|
|
|
|
| 8 |
app = FastAPI(title="Legal Process Guide API", version="1.0.0")
|
| 9 |
|
| 10 |
|
| 11 |
+
class Message(BaseModel):
|
| 12 |
+
role: str # "user" or "assistant"
|
| 13 |
+
content: str
|
| 14 |
+
|
| 15 |
+
|
| 16 |
class QueryRequest(BaseModel):
|
| 17 |
query: str
|
| 18 |
+
history: List[Message] = [] # user sends past chat messages
|
| 19 |
|
| 20 |
|
| 21 |
class QueryResponse(BaseModel):
|
|
|
|
| 37 |
|
| 38 |
@app.post("/query", response_model=QueryResponse)
|
| 39 |
def query_endpoint(req: QueryRequest) -> QueryResponse:
|
| 40 |
+
# Pass query + history into RAG
|
| 41 |
+
result = app.state.rag.process_query(req.query, [m.dict() for m in req.history])
|
| 42 |
return QueryResponse(
|
| 43 |
response=result["response"],
|
| 44 |
classification=result["classification"],
|