Follow these steps to set up a virtual environment for this project:
-
Install Python
Ensure you have Python 3.7 or higher installed on your system. You can download it from python.org. -
Create a Virtual Environment
Open a terminal and navigate to the project directory. Run the following command to create a virtual environment:python -m venv .venv
-
Activate the Virtual Environment
- On macOS/Linux:
source .venv/bin/activate
- On macOS/Linux:
-
Install Dependencies
After activating the virtual environment, install all dependencies listed in therequirements.txtfile:pip install -r requirements.txt
-
Deactivate the Virtual Environment
When you're done working, deactivate the virtual environment by running:deactivate
To securely manage sensitive information like API keys or database credentials, create a .env file in the root directory. You can take reference from the .env.example file provided in the project.
Example .env file content:
DATABASE_URL=mongodb://localhost:27017
OPENAI_API_KEY=your_openai_api_key
ASSISTANT_ID=your_assistant_id
DB_NAME=your_db_nameEnsure the .env file is not committed to version control by adding it to .gitignore:
.envAfter setting up the virtual environment and installing dependencies, you can run the FastAPI application using the following command:
fastapi dev main.pyOnce the server starts, you can access the application at:
- Base URL: http://127.0.0.1:8000
- OpenAPI Documentation: http://127.0.0.1:8000/docs
- Redoc API Documentation: http://127.0.0.1:8000/redoc
Logs are configured to output to both the console and a file named app.log. You can find the logs in the root directory of the project.
- Pydantic: Used for data validation and settings management in FastAPI.
- PyMongo: Used for interacting with MongoDB.
- OpenAI: Used for integrating OpenAI APIs.
- python-dotenv: Used for loading environment variables from a
.envfile.