Spaces:
Sleeping
Sleeping
Created developer documentation for both subprojects (/backend and /frontend).
Browse files- backend/README.md +109 -0
- frontend/README.md +113 -0
backend/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Backend Documentation
|
| 2 |
+
|
| 3 |
+
This document provides an overview of the backend architecture and components for the AI Maker Space project.
|
| 4 |
+
|
| 5 |
+
## Project Structure
|
| 6 |
+
|
| 7 |
+
```
|
| 8 |
+
backend/
|
| 9 |
+
βββ agents/ # Agent definitions and implementations
|
| 10 |
+
βββ api/ # API endpoints and routes
|
| 11 |
+
βββ core/ # Core functionality and utilities
|
| 12 |
+
βββ prompts/ # Prompt templates and management
|
| 13 |
+
βββ tools/ # Tool implementations for agents
|
| 14 |
+
βββ tests/ # Test suite
|
| 15 |
+
βββ main.py # Application entry point
|
| 16 |
+
βββ .env # Environment variables (not in repo)
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
## Core Components
|
| 20 |
+
|
| 21 |
+
### Vector Store
|
| 22 |
+
|
| 23 |
+
The `VectorStore` class in `core/vector_store.py` implements a singleton pattern for managing document embeddings and vector search functionality. It provides methods for:
|
| 24 |
+
|
| 25 |
+
- Processing and embedding documents
|
| 26 |
+
- Searching for relevant context based on queries
|
| 27 |
+
- Managing the vector database state
|
| 28 |
+
|
| 29 |
+
### Text Processing
|
| 30 |
+
|
| 31 |
+
The `text_utils.py` module provides utilities for:
|
| 32 |
+
|
| 33 |
+
- Loading documents from various formats (PDF, TXT)
|
| 34 |
+
- Splitting text into chunks for processing
|
| 35 |
+
- Text preprocessing and normalization
|
| 36 |
+
|
| 37 |
+
### Embeddings
|
| 38 |
+
|
| 39 |
+
The `embeddings.py` module handles:
|
| 40 |
+
|
| 41 |
+
- Creating embeddings for text chunks
|
| 42 |
+
- Managing embedding models and configurations
|
| 43 |
+
|
| 44 |
+
### Vector Database
|
| 45 |
+
|
| 46 |
+
The `vectordatabase.py` module implements:
|
| 47 |
+
|
| 48 |
+
- Storage and retrieval of vector embeddings
|
| 49 |
+
- Similarity search functionality
|
| 50 |
+
- Database management operations
|
| 51 |
+
|
| 52 |
+
## API Endpoints
|
| 53 |
+
|
| 54 |
+
The backend exposes the following API endpoints:
|
| 55 |
+
|
| 56 |
+
### Upload Endpoints
|
| 57 |
+
|
| 58 |
+
- `POST /upload/pdf` - Upload and process PDF documents
|
| 59 |
+
- `POST /upload/text` - Upload and process text documents
|
| 60 |
+
|
| 61 |
+
### Query Endpoints
|
| 62 |
+
|
| 63 |
+
- `POST /ask` - Query the knowledge base with a question
|
| 64 |
+
|
| 65 |
+
### Agent Endpoints
|
| 66 |
+
|
| 67 |
+
- `POST /agent/run` - Execute an agent with specific parameters
|
| 68 |
+
|
| 69 |
+
## Environment Configuration
|
| 70 |
+
|
| 71 |
+
The application uses environment variables for configuration. See `.env.template` for required variables:
|
| 72 |
+
|
| 73 |
+
- `OPENAI_API_KEY` - API key for OpenAI services
|
| 74 |
+
- `ALLOWED_ORIGINS` - CORS allowed origins (comma-separated)
|
| 75 |
+
- `ENVIRONMENT` - Set to "production" or "development"
|
| 76 |
+
- `DEBUG` - Enable debug mode when set to "true"
|
| 77 |
+
|
| 78 |
+
## Development Setup
|
| 79 |
+
|
| 80 |
+
1. Clone the repository
|
| 81 |
+
2. Create a `.env` file based on `.env.template`
|
| 82 |
+
3. Install dependencies:
|
| 83 |
+
```
|
| 84 |
+
pip install -r requirements.txt
|
| 85 |
+
```
|
| 86 |
+
4. Run the development server:
|
| 87 |
+
```
|
| 88 |
+
uvicorn backend.main:app --reload
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
## Testing
|
| 92 |
+
|
| 93 |
+
Run the test suite with:
|
| 94 |
+
|
| 95 |
+
```
|
| 96 |
+
pytest
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
Tests are organized by component and include:
|
| 100 |
+
- API endpoint tests
|
| 101 |
+
- Core functionality tests
|
| 102 |
+
- Integration tests
|
| 103 |
+
|
| 104 |
+
## Architecture Notes
|
| 105 |
+
|
| 106 |
+
- The application uses FastAPI for the web framework
|
| 107 |
+
- VectorStore implements a singleton pattern to ensure a single instance across the application
|
| 108 |
+
- Document processing is asynchronous to handle large files efficiently
|
| 109 |
+
- The frontend communicates with the backend via REST API endpoints
|
frontend/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Frontend Documentation
|
| 2 |
+
|
| 3 |
+
This document provides an overview of the frontend architecture and components for the AI Maker Space project.
|
| 4 |
+
|
| 5 |
+
## Project Structure
|
| 6 |
+
|
| 7 |
+
```
|
| 8 |
+
frontend/
|
| 9 |
+
βββ public/ # Static assets
|
| 10 |
+
βββ src/ # Source code
|
| 11 |
+
β βββ components/ # React components
|
| 12 |
+
β βββ utils/ # Utility functions
|
| 13 |
+
β βββ App.jsx # Main application component
|
| 14 |
+
β βββ App.css # Application styles
|
| 15 |
+
β βββ index.css # Global styles
|
| 16 |
+
β βββ main.jsx # Application entry point
|
| 17 |
+
βββ .env # Environment variables (not in repo)
|
| 18 |
+
βββ index.html # HTML template
|
| 19 |
+
βββ package.json # Dependencies and scripts
|
| 20 |
+
βββ vite.config.js # Vite configuration
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Core Components
|
| 24 |
+
|
| 25 |
+
### App Component
|
| 26 |
+
|
| 27 |
+
The `App.jsx` component serves as the main container for the application. It manages:
|
| 28 |
+
|
| 29 |
+
- Application state for file upload status
|
| 30 |
+
- Conditional rendering of components based on application state
|
| 31 |
+
- Overall layout and structure
|
| 32 |
+
|
| 33 |
+
### FileUploader Component
|
| 34 |
+
|
| 35 |
+
The `FileUploader.jsx` component handles:
|
| 36 |
+
|
| 37 |
+
- File selection via input element
|
| 38 |
+
- File upload to the backend API
|
| 39 |
+
- Upload status feedback
|
| 40 |
+
- Success callback to trigger chat mode
|
| 41 |
+
|
| 42 |
+
### ChatBox Component
|
| 43 |
+
|
| 44 |
+
The `ChatBox.jsx` component provides:
|
| 45 |
+
|
| 46 |
+
- Text input for questions
|
| 47 |
+
- API endpoint selection (RAG or Agent)
|
| 48 |
+
- Streaming response handling
|
| 49 |
+
- Response display
|
| 50 |
+
|
| 51 |
+
## Environment Configuration
|
| 52 |
+
|
| 53 |
+
The application uses environment variables for configuration. See `.env.template` for required variables:
|
| 54 |
+
|
| 55 |
+
- `VITE_API_URL` - URL of the backend API (defaults to http://localhost:7860)
|
| 56 |
+
|
| 57 |
+
## Development Setup
|
| 58 |
+
|
| 59 |
+
1. Clone the repository
|
| 60 |
+
2. Create a `.env` file based on `.env.template`
|
| 61 |
+
3. Install dependencies:
|
| 62 |
+
```
|
| 63 |
+
npm install
|
| 64 |
+
```
|
| 65 |
+
4. Run the development server:
|
| 66 |
+
```
|
| 67 |
+
npm run dev
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
## Building for Production
|
| 71 |
+
|
| 72 |
+
To build the application for production:
|
| 73 |
+
|
| 74 |
+
```
|
| 75 |
+
npm run build
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
This will generate optimized static files in the `dist` directory.
|
| 79 |
+
|
| 80 |
+
## Customization Points
|
| 81 |
+
|
| 82 |
+
The template includes several TODO comments indicating areas for customization:
|
| 83 |
+
|
| 84 |
+
1. **Branding**: Replace the logo and application title in `App.jsx`
|
| 85 |
+
2. **FileUploader**: Customize or replace the file upload component
|
| 86 |
+
3. **ChatBox**: Modify the chat interface to match your specific use case
|
| 87 |
+
4. **API Endpoints**: Update the API endpoints in the components to match your backend
|
| 88 |
+
|
| 89 |
+
## API Integration
|
| 90 |
+
|
| 91 |
+
The frontend communicates with the backend through the following endpoints:
|
| 92 |
+
|
| 93 |
+
- `POST /upload` - Upload documents for processing
|
| 94 |
+
- `POST /ask` - Query the knowledge base
|
| 95 |
+
- `POST /agent` - Execute an agent
|
| 96 |
+
|
| 97 |
+
## Styling
|
| 98 |
+
|
| 99 |
+
The application uses CSS for styling:
|
| 100 |
+
|
| 101 |
+
- `App.css` - Component-specific styles
|
| 102 |
+
- `index.css` - Global styles and CSS variables
|
| 103 |
+
|
| 104 |
+
## Testing
|
| 105 |
+
|
| 106 |
+
The application includes data-testid attributes for testing purposes. You can use these with testing libraries like React Testing Library.
|
| 107 |
+
|
| 108 |
+
## Architecture Notes
|
| 109 |
+
|
| 110 |
+
- The application uses React 19 with Vite for fast development
|
| 111 |
+
- Components are functional and use React hooks for state management
|
| 112 |
+
- The application supports streaming responses from the backend
|
| 113 |
+
- The UI adapts based on whether a file has been uploaded
|