-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (31 loc) · 1.05 KB
/
Copy pathmain.py
File metadata and controls
36 lines (31 loc) · 1.05 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
import os
from fastapi import FastAPI, UploadFile, File
from rag.retrieval import answer_question
from rag.ingestion import process_uploaded_document
app = FastAPI(
title="PDF RAG Processing",
description="A standalone FastAPI server for PDF Retrieval-Augmented Generation processing."
)
@app.get("/")
def read_root():
return {"message": "Welcome to the PDF RAG Processing API"}
@app.get("/health")
def health_check():
return {"status": "ok"}
@app.post("/ask")
def ask_pdf(question: str, file_name: str = None):
"""
Ask a question against the ingested documents.
Optionally filter by file_name.
"""
response = answer_question(question, file_name)
return {"response": response}
@app.post("/upload")
def upload_pdf(file: UploadFile = File(...)):
"""
Upload a PDF document to be ingested into Azure AI Search
and stored in Azure Blob Storage.
"""
file_data = file.file.read()
process_uploaded_document(file.filename, file_data)
return {"message": f"Successfully uploaded and ingested {file.filename}"}