Upload folder using huggingface_hub
Browse files- __pycache__/ask.cpython-312.pyc +0 -0
- __pycache__/generation.cpython-312.pyc +0 -0
- __pycache__/main.cpython-312.pyc +0 -0
- __pycache__/retrieval.cpython-312.pyc +0 -0
- ask.py +19 -0
- generation.py +21 -0
- main.py +34 -0
- retrieval.py +19 -0
- search.py +0 -0
__pycache__/ask.cpython-312.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
__pycache__/generation.cpython-312.pyc
ADDED
|
Binary file (1.26 kB). View file
|
|
|
__pycache__/main.cpython-312.pyc
ADDED
|
Binary file (1.42 kB). View file
|
|
|
__pycache__/retrieval.cpython-312.pyc
ADDED
|
Binary file (1.16 kB). View file
|
|
|
ask.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from services.rag_pipeline import rag_pipeline
|
| 4 |
+
|
| 5 |
+
router = APIRouter()
|
| 6 |
+
|
| 7 |
+
# ์์ฒญ ์คํค๋ง
|
| 8 |
+
class AskRequest(BaseModel):
|
| 9 |
+
query: str
|
| 10 |
+
top_k: int = 5
|
| 11 |
+
|
| 12 |
+
# ์๋ต ์คํค๋ง
|
| 13 |
+
class AskResponse(BaseModel):
|
| 14 |
+
output: str
|
| 15 |
+
|
| 16 |
+
@router.post("/ask", response_model=AskResponse)
|
| 17 |
+
async def ask(request: AskRequest):
|
| 18 |
+
output = rag_pipeline(request.query, top_k=request.top_k)
|
| 19 |
+
return {"output": output}
|
generation.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from generator.prompt_builder import build_prompt
|
| 4 |
+
from generator.llm_inference import generate_answer
|
| 5 |
+
|
| 6 |
+
router = APIRouter()
|
| 7 |
+
|
| 8 |
+
# ์์ฒญ ์คํค๋ง
|
| 9 |
+
class GenerateRequest(BaseModel):
|
| 10 |
+
query: str
|
| 11 |
+
context_docs: list
|
| 12 |
+
|
| 13 |
+
# ์๋ต ์คํค๋ง
|
| 14 |
+
class GenerateResponse(BaseModel):
|
| 15 |
+
output: str
|
| 16 |
+
|
| 17 |
+
@router.post("/generate", response_model=GenerateResponse)
|
| 18 |
+
async def generate(request: GenerateRequest):
|
| 19 |
+
prompt = build_prompt(request.query, request.context_docs)
|
| 20 |
+
output = generate_answer(prompt)
|
| 21 |
+
return {"output": output}
|
main.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from api.retrieval import router as retrieval_router
|
| 4 |
+
from api.generation import router as generation_router
|
| 5 |
+
from api.ask import router as ask_router
|
| 6 |
+
|
| 7 |
+
app = FastAPI(
|
| 8 |
+
title="RAG ๊ธฐ๋ฐ ๋ฌธ์ ์ถ์ ์์คํ
",
|
| 9 |
+
description="๊ณต์ธ์ค๊ฐ์ฌ ์ํ ๋ฌธ์ ์๋ ์์ฑ API",
|
| 10 |
+
version="1.0.0",
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# (์ ํ) CORS ์ค์ - ๋์ค์ Next.js ํ๋ก ํธ ์ฐ๊ฒฐํ ๋ ํ์ํจ
|
| 14 |
+
app.add_middleware(
|
| 15 |
+
CORSMiddleware,
|
| 16 |
+
allow_origins=["*"], # ์ค์ ๋ฐฐํฌ ๋๋ ํ๋ก ํธ ๋๋ฉ์ธ๋ง ํ์ฉ ์ถ์ฒ
|
| 17 |
+
allow_credentials=True,
|
| 18 |
+
allow_methods=["*"],
|
| 19 |
+
allow_headers=["*"],
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# ํฌ์ค ์ฒดํฌ์ฉ ์๋ํฌ์ธํธ
|
| 23 |
+
@app.get("/health")
|
| 24 |
+
async def health_check():
|
| 25 |
+
return {"status": "ok"}
|
| 26 |
+
|
| 27 |
+
# ๊ธฐ๋ณธ ์ธ๋ฑ์ค
|
| 28 |
+
@app.get("/")
|
| 29 |
+
async def root():
|
| 30 |
+
return {"message": "Welcome to the RAG Question Generator API!"}
|
| 31 |
+
|
| 32 |
+
app.include_router(retrieval_router, prefix="/api")
|
| 33 |
+
app.include_router(generation_router, prefix="/api")
|
| 34 |
+
app.include_router(ask_router, prefix="/api")
|
retrieval.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from retriever.vectordb import search_documents
|
| 4 |
+
|
| 5 |
+
router = APIRouter()
|
| 6 |
+
|
| 7 |
+
# ์์ฒญ๋ฐ์ ๋ฐ์ดํฐ ํฌ๋งท ์ ์
|
| 8 |
+
class SearchRequest(BaseModel):
|
| 9 |
+
query: str
|
| 10 |
+
top_k: int = 5 # ๊ธฐ๋ณธ์ ์ผ๋ก ์์ 5๊ฐ ๊ฒ์
|
| 11 |
+
|
| 12 |
+
# ์๋ต ๋ฐ์ดํฐ ํฌ๋งท ์ ์
|
| 13 |
+
class SearchResponse(BaseModel):
|
| 14 |
+
documents: list
|
| 15 |
+
|
| 16 |
+
@router.post("/search", response_model=SearchResponse)
|
| 17 |
+
async def search(request: SearchRequest):
|
| 18 |
+
docs = search_documents(request.query, top_k=request.top_k)
|
| 19 |
+
return {"documents": docs}
|
search.py
ADDED
|
File without changes
|