Added new feedback endpoint
Browse files- backend/app/main.py +20 -2
backend/app/main.py
CHANGED
@@ -3,7 +3,8 @@ from fastapi.staticfiles import StaticFiles
|
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from fastapi.responses import FileResponse
|
5 |
from pydantic import BaseModel
|
6 |
-
from backend.app.problem_generator import
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
@@ -21,6 +22,11 @@ class UrlInput(BaseModel):
|
|
21 |
class UserQuery(BaseModel):
|
22 |
user_query: str
|
23 |
|
|
|
|
|
|
|
|
|
|
|
24 |
@app.post("/api/crawl/")
|
25 |
async def crawl_documentation(input_data: UrlInput):
|
26 |
print(f"Received url {input_data.url}")
|
@@ -28,9 +34,21 @@ async def crawl_documentation(input_data: UrlInput):
|
|
28 |
|
29 |
@app.post("/api/problems/")
|
30 |
async def generate_problems(query: UserQuery):
|
31 |
-
problems =
|
32 |
return {"Problems": problems}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Serve static files
|
35 |
app.mount("/static", StaticFiles(directory="/app/static/static"), name="static")
|
36 |
|
|
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from fastapi.responses import FileResponse
|
5 |
from pydantic import BaseModel
|
6 |
+
from backend.app.problem_generator import ProblemGenerationPipeline
|
7 |
+
from typing import Dict, List
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
|
|
22 |
class UserQuery(BaseModel):
|
23 |
user_query: str
|
24 |
|
25 |
+
class FeedbackInput(BaseModel):
|
26 |
+
user_query: str
|
27 |
+
problems: list[str]
|
28 |
+
user_answers: list[str]
|
29 |
+
|
30 |
@app.post("/api/crawl/")
|
31 |
async def crawl_documentation(input_data: UrlInput):
|
32 |
print(f"Received url {input_data.url}")
|
|
|
34 |
|
35 |
@app.post("/api/problems/")
|
36 |
async def generate_problems(query: UserQuery):
|
37 |
+
problems = ProblemGenerationPipeline().generate_problems(query.user_query)
|
38 |
return {"Problems": problems}
|
39 |
|
40 |
+
@app.post("/api/feedback/")
|
41 |
+
async def submit_feedback(feedback: FeedbackInput):
|
42 |
+
# check if problems len is equal to user_answers len
|
43 |
+
if len(feedback.problems) != len(feedback.user_answers):
|
44 |
+
raise HTTPException(status_code=400, detail="Problems and user answers must have the same length")
|
45 |
+
|
46 |
+
for problem, user_answer in zip(feedback.problems, feedback.user_answers):
|
47 |
+
print(f"Problem: {problem}")
|
48 |
+
print(f"User answer: {user_answer}")
|
49 |
+
|
50 |
+
return {"status": "success"}
|
51 |
+
|
52 |
# Serve static files
|
53 |
app.mount("/static", StaticFiles(directory="/app/static/static"), name="static")
|
54 |
|