|
3 | 3 | from app.modules.pipeline import run_scraper_pipeline |
4 | 4 | from app.modules.pipeline import run_langgraph_workflow |
5 | 5 | from app.modules.bias_detection.check_bias import check_bias |
| 6 | +from app.modules.chat.get_rag_data import search_pinecone |
| 7 | +from app.modules.chat.llm_processing import ask_llm |
6 | 8 | import asyncio |
7 | 9 | import json |
8 | 10 |
|
9 | 11 | router = APIRouter() |
10 | 12 |
|
| 13 | + |
11 | 14 | class URlRequest(BaseModel): |
12 | 15 | url: str |
13 | 16 |
|
14 | 17 |
|
| 18 | +class ChatQuery(BaseModel): |
| 19 | + message: str |
| 20 | + |
| 21 | + |
15 | 22 | @router.get("/") |
16 | 23 | async def home(): |
17 | 24 | return {"message": "Perspective API is live!"} |
18 | 25 |
|
| 26 | + |
19 | 27 | @router.post("/bias") |
20 | 28 | async def bias_detection(request: URlRequest): |
21 | | - content = await asyncio.to_thread(run_scraper_pipeline,(request.url)) |
22 | | - bias_score = await asyncio.to_thread(check_bias,(content)) |
| 29 | + content = await asyncio.to_thread(run_scraper_pipeline, (request.url)) |
| 30 | + bias_score = await asyncio.to_thread(check_bias, (content)) |
23 | 31 | print(bias_score) |
24 | 32 | return bias_score |
25 | | - |
26 | 33 |
|
27 | 34 |
|
28 | 35 | @router.post("/process") |
29 | 36 | async def run_pipelines(request: URlRequest): |
30 | | - article_text = await asyncio.to_thread(run_scraper_pipeline,(request.url)) |
| 37 | + article_text = await asyncio.to_thread(run_scraper_pipeline, (request.url)) |
31 | 38 | print(json.dumps(article_text, indent=2)) |
32 | | - data = await asyncio.to_thread(run_langgraph_workflow,(article_text)) |
| 39 | + data = await asyncio.to_thread(run_langgraph_workflow, (article_text)) |
33 | 40 | return data |
| 41 | + |
| 42 | + |
| 43 | +@router.post("/chat") |
| 44 | +async def answer_query(request: ChatQuery): |
| 45 | + |
| 46 | + query = request.message |
| 47 | + results = search_pinecone(query) |
| 48 | + answer = ask_llm(query, results) |
| 49 | + print(answer) |
| 50 | + |
| 51 | + return {"answer": answer} |
0 commit comments