{"id":27974161,"url":"https://github.com/slfagrouche/campusmind-backend","last_synced_at":"2026-02-27T00:03:41.985Z","repository":{"id":291534656,"uuid":"977887987","full_name":"slfagrouche/CampusMind-Backend","owner":"slfagrouche","description":"FastAPI-based API powering CampusMind, an AI-driven assistant for CUNY and SUNY students. Features multi-agent architecture, RAG, and MongoDB to deliver reliable academic info on transfers, professors, and courses.","archived":false,"fork":false,"pushed_at":"2025-05-05T07:21:22.000Z","size":5267,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T00:12:08.836Z","etag":null,"topics":["agentic-ai","backend","fastapi","pydantic","python3"],"latest_commit_sha":null,"homepage":"https://edumind-cuny-suny-ai-agent.vercel.app/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slfagrouche.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-05T06:10:42.000Z","updated_at":"2025-05-05T07:21:25.000Z","dependencies_parsed_at":"2025-05-05T08:35:04.011Z","dependency_job_id":null,"html_url":"https://github.com/slfagrouche/CampusMind-Backend","commit_stats":null,"previous_names":["slfagrouche/edumind-backend"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slfagrouche%2FCampusMind-Backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slfagrouche%2FCampusMind-Backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slfagrouche%2FCampusMind-Backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slfagrouche%2FCampusMind-Backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slfagrouche","download_url":"https://codeload.github.com/slfagrouche/CampusMind-Backend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973693,"owners_count":21834108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agentic-ai","backend","fastapi","pydantic","python3"],"created_at":"2025-05-08T00:12:13.101Z","updated_at":"2026-02-27T00:03:41.947Z","avatar_url":"https://github.com/slfagrouche.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CampusMind-CUNY-SUNY-AI-Agent-Backend-APIS\n\nThis is a FastAPI-based API'S for the CampusMind-CUNY-SUNY-AI-Agent, a specialized chatbot that provides information about CUNY and SUNY colleges, including details about transfers, professors, recommendations, and general information.\n\n👉 **[Try the live demo](https://edumind-cuny-suny-ai-agent.vercel.app/)**\n\n![API Architecture](demo.png)\n\n## 🎯 The Problem We're Solving\n\nStudents in New York face several challenges when navigating the CUNY and SUNY systems:\n\n- **Scattered Information**: Details about professors and courses are spread across multiple platforms\n- **Outdated Data**: Official websites often contain outdated or incomplete professor information\n- **Time-Consuming Research**: Students waste hours trying to find reliable professor reviews and course details\n- **Decision Paralysis**: With so many options across 60+ campuses, students struggle to make informed decisions\n\nThis AI-powered solution brings all this information together in one place, providing students with reliable, up-to-date information they can trust.\n\n## 🧠 API Architecture\n\nThe CUNY/SUNY AI Assistant API is built with a focus on performance, scalability, and responsible AI design:\n\n- **Multi-Agent System**: Specialized AI agents for different types of queries:\n  - Transfer Agent: Handles transfer-related queries between institutions\n  - Professor Agent: Provides information about professors, courses, and ratings\n  - Recommendation Agent: Offers school recommendations based on student interests\n  - Browser Agent: General information retrieval for queries that don't fit other categories\n\n- **Retrieval Augmented Generation (RAG)**: \n  - Knowledge base built from official CUNY/SUNY documentation\n  - FAISS vector store for semantic search\n  - DuckDuckGo integration for real-time web search\n  - MongoDB integration for structured professor and school data\n\n- **LLM Provider Management**:\n  - Load-balanced across multiple LLM providers (Groq, Cerebras, Together AI)\n  - Fallback mechanisms for API reliability\n  - Metadata tracking for model usage and attribution\n\n- **Responsible AI**:\n  - Content safety filtering for both queries and responses\n  - Comprehensive policy enforcement\n  - Source attribution for all information\n  - Clear metadata about model usage\n\n## 🚀 Technical Stack\n\n### Backend Framework\n- **FastAPI**: High-performance API with automatic OpenAPI documentation\n- **Uvicorn**: ASGI server for production deployment\n- **Pydantic**: For data validation and schema management\n\n### AI \u0026 Machine Learning\n- **LangChain \u0026 LangGraph**: For agent orchestration and workflow\n- **FAISS**: Vector database for similarity search\n- **HuggingFace Embeddings**: For semantic understanding\n- **Multiple LLM Providers**:\n  - Groq (llama-3.1-8b-instant)\n  - Cerebras (llama-4-scout-17b-16e-instruct)\n  - Together AI (meta-llama/Llama-3-8b-chat-hf)\n\n### Data Storage \u0026 Retrieval\n- **MongoDB**: For professor and school information\n- **FAISS Vector Store**: For document embeddings\n- **PDF Processing**: Extract information from handbooks and official documents\n\n### Monitoring \u0026 Operations\n- **Opik/Comet**: For LLM usage tracking and monitoring\n- **Docker**: Containerization for deployment\n- **Hugging Face Spaces**: Hosting platform\n\n## 📦 API Documentation\n\nThe API provides two main endpoints:\n\n### 1. General Query Endpoint\n\n**Endpoint:** `POST /query`\n\n**Request:**\n```json\n{\n  \"query\": \"What are the transfer requirements from CUNY to SUNY?\",\n  \"user_id\": \"optional-tracking-id\"\n}\n```\n\n**Response:**\n```json\n{\n  \"agent_type\": \"transfer\",\n  \"response\": \"The AI-generated text response about transfer requirements...\",\n  \"sources\": {\n    \"knowledge_base\": [{\n      \"content\": \"...\",\n      \"metadata\": {\n        \"source\": \"StudentHandbook.pdf\",\n        \"page\": 42\n      }\n    }],\n    \"search\": [{\n      \"source\": \"DuckDuckGo\",\n      \"content\": \"...\"\n    }]\n  },\n  \"original_query\": \"What are the transfer requirements from CUNY to SUNY?\",\n  \"system_metadata\": {\n    \"model_used\": \"llama-3.1-8b-instant\",\n    \"provider\": \"groq\",\n    \"embedding_model\": \"sentence-transformers/all-mpnet-base-v2\",\n    \"timestamp\": \"2023-10-15T14:25:33.123Z\"\n  }\n}\n```\n\n### 2. Professor-Specific Query Endpoint\n\n**Endpoint:** `POST /professor`\n\n**Request:**\n```json\n{\n  \"first_name\": \"John\",\n  \"last_name\": \"Smith\",\n  \"college_name\": \"SUNY Albany\",\n  \"question\": \"What courses does he teach?\",\n  \"user_id\": \"optional-tracking-id\"\n}\n```\n\n**Response:**\n```json\n{\n  \"agent_type\": \"professor\",\n  \"response\": \"Professor John Smith at SUNY Albany teaches the following courses...\",\n  \"sources\": {\n    \"professor_db\": {\n      \"professor_info\": {\n        \"name\": \"John Smith\",\n        \"school\": \"SUNY Albany\",\n        \"department\": \"Computer Science\",\n        \"courses\": [\"CS101\", \"CS202\", \"Advanced Algorithms\"],\n        \"rating\": 4.5\n      },\n      \"reviews\": [\n        {\n          \"rating\": 5,\n          \"date\": \"Spring 2023\",\n          \"comment\": \"Excellent professor, very clear explanations\",\n          \"course\": \"CS101\"\n        }\n      ]\n    },\n    \"knowledge_base\": [...],\n    \"search\": [...]\n  },\n  \"original_query\": \"What courses does Professor John Smith at SUNY Albany teach?\",\n  \"system_metadata\": {\n    \"model_used\": \"llama-3.1-8b-instant\",\n    \"provider\": \"groq\",\n    \"embedding_model\": \"sentence-transformers/all-mpnet-base-v2\",\n    \"timestamp\": \"2023-10-15T14:26:45.789Z\"\n  }\n}\n```\n\n## 🐳 Docker Deployment\n\nThe API is containerized using Docker for easy deployment and scalability.\n\n### Dockerfile\n\n```dockerfile\nFROM python:3.10-slim\n\nWORKDIR /app\n\n# Install dependencies\nCOPY requirements.txt .\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy application code\nCOPY ./app /app/app\n\n# Make port 7860 available (Hugging Face Spaces default port)\nEXPOSE 7860\n\n# Run the application with Uvicorn\nCMD [\"uvicorn\", \"app.main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"7860\"]\n```\n\n### Environment Variables\n\nThe API requires several environment variables to be set:\n\n- `MONGO_URI`: MongoDB connection string\n- `GROQ_API_KEY`: API key for Groq LLM service\n- `TOGETHER_API_KEY`: API key for Together AI service\n- `CEREBRAS_API_KEY`: API key for Cerebras AI service\n- `COMET_API_KEY`: API key for Comet.ml/Opik integration\n\n### Local Development with Docker\n\n1. Build the Docker image:\n   ```bash\n   docker build -t cuny-suny-ai-assistant .\n   ```\n\n2. Run the container with environment variables:\n   ```bash\n   docker run -p 8000:7860 \\\n     -e MONGO_URI=your_mongo_uri \\\n     -e GROQ_API_KEY=your_groq_key \\\n     -e TOGETHER_API_KEY=your_together_key \\\n     -e CEREBRAS_API_KEY=your_cerebras_key \\\n     cuny-suny-ai-assistant\n   ```\n\n3. Access the API at `http://localhost:8000/docs`\n\n## 🚀 Hugging Face Spaces Deployment\n\nThis API is deployed on Hugging Face Spaces, which provides a scalable environment for AI applications.\n\n### Deployment Configuration\n\nThe `README.md` in the Hugging Face Space repository includes the following front-matter configuration:\n\n```yaml\n---\ntitle: CUNY/SUNY AI Assistant\nemoji: 🎓\ncolorFrom: blue\ncolorTo: indigo\nsdk: docker\npinned: false\n---\n```\n\n### Secrets Management\n\nAPI keys and connection strings are stored as **Repository Secrets** in the Hugging Face Space settings:\n\n1. Navigate to your Space settings\n2. Click on \"Repository secrets\"\n3. Add each required environment variable\n\n⚠️ **IMPORTANT**: Never commit API keys directly in your code or Dockerfile.\n\n## 🛡️ Responsible AI Implementation\n\n### Content Safety\n\nThe system includes a comprehensive content safety filter that:\n\n1. **Pre-checks queries** for policy violations before processing\n2. **Post-checks responses** to ensure outputs conform to safety guidelines\n3. **Returns safe alternatives** when responses might violate policies\n\n### Custom Policy Implementation\n\nThe content safety filter uses a detailed policy (defined in `app/policies.py`) that covers:\n\n- **O1: Illegal or harmful activities**: Preventing generation of content related to illegal activities, violence, etc.\n- **O2: Child safety**: Protecting minors by filtering inappropriate content\n- **O3: Privacy and personal data**: Refusing to provide non-public personal data\n- **O4: Political and societal content**: Maintaining neutrality on controversial topics\n- **O5: Financial and legal advice**: Disclaiming professional financial or legal advice\n- **O6: cation-specific concerns**: Special considerations for the cation domain\n\n### Source Attribution\n\nAll information provided includes source attributions:\n\n- **Knowledge base sources**: Document name and page number\n- **Web search results**: Search provider and snippet\n- **Database information**: Data origin with timestamps\n- **Model metadata**: Clear indication of which AI model generated the response\n\n## 🔧 Getting Started\n\n### Prerequisites\n\n- Python 3.8+\n- MongoDB instance\n- API keys for LLM providers (Groq, Together AI, Cerebras)\n- PDF files for knowledge base (student handbooks)\n\n### Local Development\n\n1. Clone the repository:\n   ```bash\n   https://github.com/slfagrouche/CampusMind-Backend.git\n   cd CampusMind-Backend\n   ```\n\n2. Create a virtual environment:\n   ```bash\n   python -m venv venv\n   source venv/bin/activate  # On Windows: venv\\Scripts\\activate\n   ```\n\n3. Install dependencies:\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n4. Create a `.env` file with your environment variables:\n   ```\n   MONGO_URI=your_mongo_uri\n   GROQ_API_KEY=your_groq_key\n   TOGETHER_API_KEY=your_together_key\n   CEREBRAS_API_KEY=your_cerebras_key\n   COMET_API_KEY=your_comet_key\n   ```\n\n5. Run the development server:\n   ```bash\n   uvicorn app.main:app --reload\n   ```\n\n6. Access the API documentation at `http://localhost:8000/docs`\n\n## 📈 Future Enhancements\n\n- **Enhanced Personalization**: Tailoring recommendations based on user preferences and history\n- **Expanded Database**: Adding more professors and courses from additional CUNY/SUNY campuses\n- **Improved RAG**: Expanding the knowledge base with more official documents\n- **Multi-language Support**: Adding support for languages commonly spoken in NY\n- **Mobile App Integration**: Dedicated mobile apps for iOS and Android\n\n## 🔗 Related Projects\n\n### Frontend Repository\nThe frontend for this project is available at [slfagrouche/CampusMind-CUNY-SUNY-AI-Agent](https://github.com/slfagrouche/CampusMind-Frontend).\n\nFeatures include:\n- Modern React interface with TypeScript\n- Tailwind CSS for responsive design\n- Professor search functionality\n- Chat interface for general queries\n- Source attribution display\n\n## 📝 License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📬 Contact\n\nHave questions or feedback? Reach out via:\n- GitHub Issues \n- Email: SaidLfagrouche@gmail.com\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslfagrouche%2Fcampusmind-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslfagrouche%2Fcampusmind-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslfagrouche%2Fcampusmind-backend/lists"}