File size: 1,172 Bytes
868c437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from fastapi import FastAPI, Depends, HTTPException, status

from langserve import add_routes
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv

from backend.chains.router import educational_assistant_chain, chat_chain_with_history, content_generation_chain
from backend.schemas.api_models import ChatInput

load_dotenv()

app = FastAPI(
    title="DirectEd AI Assistant Server",
    version="1.0",
    description="A multi-functional API server for the DirectEd AI assistant.",
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"],
)


add_routes(
    app,
    chat_chain_with_history,
    path="/api/assistant/chat",
)

add_routes(
    app,
    content_generation_chain,
    path="/api/assistant/content/generate",
)

@app.get("/api/assistant/analytics")
def get_analytics():
    """Placeholder endpoint for retrieving usage analytics."""
    return {"status": "ok", "message": "Analytics endpoint is under development."}


@app.get("/")
def read_root():
    """Health check endpoint."""
    return {"status": "DirectEd AI Assistant is running"}