Spaces:
Sleeping
Sleeping
Commit ·
f943b70
0
Parent(s):
Reinitialize repo
Browse files- .gitignore +2 -0
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/app.cpython-313.pyc +0 -0
- __pycache__/auth.cpython-311.pyc +0 -0
- __pycache__/auth.cpython-313.pyc +0 -0
- __pycache__/mongodb.cpython-311.pyc +0 -0
- __pycache__/mongodb.cpython-313.pyc +0 -0
- app/__init__.py +0 -0
- app/__pycache__/__init__.cpython-311.pyc +0 -0
- app/__pycache__/config.cpython-311.pyc +0 -0
- app/__pycache__/main.cpython-311.pyc +0 -0
- app/__pycache__/mongodb.cpython-311.pyc +0 -0
- app/config.py +12 -0
- app/main.py +21 -0
- app/models/__pycache__/chat_logs.cpython-311.pyc +0 -0
- app/models/chat_logs.py +9 -0
- app/mongodb.py +7 -0
- app/routers/__pycache__/chats.cpython-311.pyc +0 -0
- app/routers/analytics.py +0 -0
- app/routers/chats.py +38 -0
- requirements.txt +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
.venv/
|
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (2.85 kB). View file
|
|
|
__pycache__/app.cpython-313.pyc
ADDED
|
Binary file (2.33 kB). View file
|
|
|
__pycache__/auth.cpython-311.pyc
ADDED
|
Binary file (2.32 kB). View file
|
|
|
__pycache__/auth.cpython-313.pyc
ADDED
|
Binary file (2.1 kB). View file
|
|
|
__pycache__/mongodb.cpython-311.pyc
ADDED
|
Binary file (1.6 kB). View file
|
|
|
__pycache__/mongodb.cpython-313.pyc
ADDED
|
Binary file (1.37 kB). View file
|
|
|
app/__init__.py
ADDED
|
File without changes
|
app/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (195 Bytes). View file
|
|
|
app/__pycache__/config.cpython-311.pyc
ADDED
|
Binary file (931 Bytes). View file
|
|
|
app/__pycache__/main.cpython-311.pyc
ADDED
|
Binary file (1.01 kB). View file
|
|
|
app/__pycache__/mongodb.cpython-311.pyc
ADDED
|
Binary file (585 Bytes). View file
|
|
|
app/config.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic_settings import BaseSettings
|
| 2 |
+
|
| 3 |
+
class Settings(BaseSettings):
|
| 4 |
+
mongo_uri: str
|
| 5 |
+
mongo_db_password: str
|
| 6 |
+
mongo_db_name: str
|
| 7 |
+
jwt_secret: str
|
| 8 |
+
|
| 9 |
+
class Config:
|
| 10 |
+
env_file = ".env"
|
| 11 |
+
|
| 12 |
+
settings = Settings()
|
app/main.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from .routers import chats
|
| 4 |
+
|
| 5 |
+
app = FastAPI(title="Auro Dashboard Backend")
|
| 6 |
+
|
| 7 |
+
# CORS — adjust for your frontend origin
|
| 8 |
+
app.add_middleware(
|
| 9 |
+
CORSMiddleware,
|
| 10 |
+
allow_origins=["*"], # replace with your frontend URL for production
|
| 11 |
+
allow_credentials=True,
|
| 12 |
+
allow_methods=["*"],
|
| 13 |
+
allow_headers=["*"],
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# Routers
|
| 17 |
+
app.include_router(chats.router)
|
| 18 |
+
|
| 19 |
+
@app.get("/")
|
| 20 |
+
def root():
|
| 21 |
+
return {"message": "Dashboard Backend is running"}
|
app/models/__pycache__/chat_logs.cpython-311.pyc
ADDED
|
Binary file (683 Bytes). View file
|
|
|
app/models/chat_logs.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app/models/chat_log.py
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
class ChatLog(BaseModel):
|
| 6 |
+
session_id: str
|
| 7 |
+
query: str
|
| 8 |
+
answer: str
|
| 9 |
+
timestamp: datetime
|
app/mongodb.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from motor.motor_asyncio import AsyncIOMotorClient
|
| 2 |
+
from .config import settings
|
| 3 |
+
|
| 4 |
+
client = AsyncIOMotorClient(settings.mongo_uri)
|
| 5 |
+
db = client[settings.mongo_db_name]
|
| 6 |
+
chat_logs = db["ChatLogs"]
|
| 7 |
+
print("Succesfully connected to database")
|
app/routers/__pycache__/chats.cpython-311.pyc
ADDED
|
Binary file (2.26 kB). View file
|
|
|
app/routers/analytics.py
ADDED
|
File without changes
|
app/routers/chats.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, HTTPException, Query
|
| 2 |
+
from ..mongodb import chat_logs
|
| 3 |
+
from ..models.chat_logs import ChatLog
|
| 4 |
+
|
| 5 |
+
router = APIRouter(prefix="/api/chats",tags=["Chats"])
|
| 6 |
+
|
| 7 |
+
@router.get("/recent", response_model=list[ChatLog])
|
| 8 |
+
async def get_recent_chats(limit: int | None= Query(10, ge=1)):
|
| 9 |
+
"""
|
| 10 |
+
Returns the N most recent chat logs for dashboard
|
| 11 |
+
"""
|
| 12 |
+
if limit is None:
|
| 13 |
+
chats_cursor = chat_logs.find().sort("timestamp", -1)
|
| 14 |
+
else:
|
| 15 |
+
chats_cursor = chat_logs.find().sort("timestamp", -1).limit(limit)
|
| 16 |
+
|
| 17 |
+
chats = await chats_cursor.to_list(length=limit if limit else None)
|
| 18 |
+
|
| 19 |
+
if not chats:
|
| 20 |
+
raise HTTPException(status_code=404, detail="No Chat Logs found")
|
| 21 |
+
|
| 22 |
+
return chats
|
| 23 |
+
|
| 24 |
+
@router.get("/stats")
|
| 25 |
+
async def get_chat_stats():
|
| 26 |
+
"""
|
| 27 |
+
Returns basic stats:
|
| 28 |
+
- total_sessions: numbers of unique session_ids
|
| 29 |
+
- total_requests: total number of chat logs
|
| 30 |
+
"""
|
| 31 |
+
total_requests = await chat_logs.count_documents({})
|
| 32 |
+
unique_sessions = await chat_logs.distinct("session_id")
|
| 33 |
+
total_sessions = len(unique_sessions)
|
| 34 |
+
|
| 35 |
+
return {
|
| 36 |
+
"total_sessions": total_sessions,
|
| 37 |
+
"total_requests": total_requests
|
| 38 |
+
}
|
requirements.txt
ADDED
|
File without changes
|