Spaces:
Sleeping
Sleeping
| 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=["*"], | |
| ) | |
| def greet_json(): | |
| return {"Hello": "World!"} | |
| 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}) | |
| 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"] | |
| } | |