File size: 1,168 Bytes
27ccfa6
e0ec272
942b420
e0ec272
948e715
 
e0ec272
 
27ccfa6
 
 
948e715
 
 
 
 
 
 
 
 
27ccfa6
 
e0ec272
 
 
 
 
 
 
948e715
 
 
 
e0ec272
942b420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e0ec272
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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"]
    }