Skip to content
Open

Deep #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Environment variables template
# Copy this file to .env and fill in your actual values

# MongoDB Connection
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/database?retryWrites=true&w=majority

# Google Gemini API
GEMINI_API_KEY=your_gemini_api_key_here

# Node.js Environment
NODE_ENV=production

# Next.js Environment
NEXT_PUBLIC_API_URL=http://localhost:8001
NEXT_PUBLIC_FASTAPI_URL=http://localhost:8000
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode
.idx
.github
.env
.
17 changes: 17 additions & 0 deletions .vercelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Exclude other services from Vercel deployment
server/
FastAPI/
.github/
docker-compose.yml
**/Dockerfile
**/.dockerignore
railway.yml

# Standard ignores
node_modules
.next
.env.local
.env.development.local
.env.test.local
.env.production.local
*.log
16 changes: 16 additions & 0 deletions FastAPI/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
.git
.gitignore
README.md
Dockerfile
.dockerignore
.env
.pytest_cache
.coverage
htmlcov/
.venv
venv/
3 changes: 3 additions & 0 deletions FastAPI/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
client_secret.json
token.json
34 changes: 34 additions & 0 deletions FastAPI/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use Python 3.11 slim image
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements first for better caching
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create non-root user for security
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser

# Expose port
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1

# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
78 changes: 78 additions & 0 deletions FastAPI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Doubt Solver Agent


## Setup Instructions

1. **Clone the repository:**
```bash
git clone <repository-url>
cd <repository-name>
```

2. **Install dependencies:**
```bash
pip install -r requirements.txt
```

3. **Create a `.env` file in the root directory and add your Gemini API key:**
```
GEMINI_API_KEY=your_api_key_here
MONGO_URI = "mongodb://localhost:27017"
```
4. **Paste Google Oauth2 file as `client_secret.json` and `token.json` in the root directory (Required while Google Meet Creation)**

5. **Run the application locally:**
```bash
uvicorn main:app --reload --port 5000
```

6. **Access the application at** `http://localhost:5000`

## Project Structure

```
.
├── README.md
├── requirements.txt
├── .env
├── main.py
├── src/
│ ├── db.py
│ ├── chat.py
│ ├── crud.py
│ ├── meet.py
│ └── models.py
```

## API Endpoints

- `POST /api/query`: Submit a question to the tutoring system
- Request body: `{"query": "your question here"}`
- Response: `{"response": "system's response"}`

## MongoDB Initialization

To use this application, you must have MongoDB running locally. Follow these steps to ensure MongoDB is set up correctly:

1. **Install MongoDB**
- Download and install MongoDB Community Edition from: https://www.mongodb.com/try/download/community
- Follow the installation instructions for your operating system.

2. **Start the MongoDB server**
- On most systems, you can start MongoDB with:
```bash
mongod
```
- By default, MongoDB will run on `mongodb://localhost:27017`.

3. **Automatic Collection Creation**
- When you start the FastAPI server, the application will automatically check for and create the following collections if they do not exist:
- `teachers`
- `students`
- `chats`
- This logic is handled in `src/db.py`.

4. **Verify Connection**
- Ensure your MongoDB server is running **before** starting the FastAPI server. If MongoDB is not running, the application will not be able to connect to the database.

If you need to change the MongoDB connection URI, update the `MONGO_DETAILS` variable in `src/db.py`.
89 changes: 89 additions & 0 deletions FastAPI/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from typing import List
from src.models import TeacherModel, StudentModel, ChatModel, ChatEntry
from src.crud import (
get_all_teachers,
get_all_students,
get_chat_by_roll,
update_chat_by_roll,
add_chat_entry
)
from pydantic import BaseModel
from src.chat import DoubtAgent
from dotenv import load_dotenv
load_dotenv()
import os

GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
app = FastAPI()

# Health check endpoint
@app.get("/health")
async def health_check():
return {"status": "healthy", "service": "NeuroGrade FastAPI"}

# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"], # Add your frontend URL
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

@app.get("/")
def read_root():
return {"message": "NeuroGrade Chat API is running"}

@app.get("/teachers", response_model=List[TeacherModel])
def read_teachers():
return get_all_teachers()

@app.get("/students", response_model=List[StudentModel])
def read_students():
return get_all_students()

@app.get("/chats/{stud_roll}", response_model=ChatModel)
def read_chat(stud_roll: str):
chat = get_chat_by_roll(stud_roll)
if chat:
return chat
raise HTTPException(status_code=404, detail="Chat not found")

@app.put("/chats/{stud_roll}", response_model=bool)
def update_chat(stud_roll: str, chats: List[ChatEntry]):
updated = update_chat_by_roll(stud_roll, chats)
if updated:
return True
raise HTTPException(status_code=404, detail="Chat not found or not updated")

# Request model for agent endpoint
class AgentRequest(BaseModel):
query: str
student_roll: str

@app.post("/agent/ask")
def agent_ask(request: AgentRequest):
# 1. Get history
chat_history_doc = get_chat_by_roll(request.student_roll)
chat_history = chat_history_doc.chats if chat_history_doc else []

# 2. Call agent with history
agent = DoubtAgent(
api_key=GEMINI_API_KEY,
student_roll=request.student_roll,
chat_history=chat_history
)
response = agent.get_response(request.query)

# 3. Store new entry
add_chat_entry(stud_roll=request.student_roll, query=request.query, answer=response)

return {"response": response}

if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5000)


12 changes: 12 additions & 0 deletions FastAPI/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fastapi==0.115.14
google_api_python_client==2.172.0
google_auth_oauthlib==1.2.2
langchain_core==0.3.68
langchain_google_genai==2.1.6
langgraph==0.5.1
protobuf==6.31.1
pydantic==2.11.7
pymongo==4.13.2
python-dotenv==1.1.1
typing_extensions==4.14.1
uvicorn==0.32.1
3 changes: 3 additions & 0 deletions FastAPI/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Multi-agent tutoring system agents package.
"""
Binary file added FastAPI/src/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/chat.cpython-310.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/crud.cpython-310.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/crud.cpython-312.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/db.cpython-310.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/db.cpython-312.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/meet.cpython-310.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added FastAPI/src/__pycache__/models.cpython-312.pyc
Binary file not shown.
Loading