summarize / app.py
irashperera's picture
Enhance FastAPI application with RAG chatbot integration
942b420
raw
history blame
1.17 kB
from fastapi import FastAPI
from langgraph.agents.summarize_agent.graph import graph
from langgraph.agents.rag_agent.graph import graph as rag_graph
from fastapi import Request
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# cors
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def greet_json():
return {"Hello": "World!"}
@app.post("/summarize")
async def summarize(request: Request):
data = await request.json()
urls = data.get("urls")
codes = data.get("codes")
notes = data.get("notes")
return graph.invoke({"urls": urls, "codes": codes, "notes": notes})
@app.post("/chat")
async def chat(request: Request):
data = await request.json()
user_input = data.get("message", "")
chat_history = data.get("chat_history", [])
# Invoke the RAG chatbot graph
result = rag_graph.invoke({
"user_input": user_input,
"chat_history": chat_history
})
return {
"response": result["response"],
"chat_history": result["chat_history"]
}