server for code genie
code-genie-server/
│
├── server.py # Entry point for the FastAPI server
├── routes/ # API routes # Define API endpoints
├── db/ # Database-related files, Database models, CRUD operations, Database connection management
├── services/ # Business logic and services, Interactions with OpenAI API
├── utils/ # Utility functions
├── tests/ # Unit and integration tests, test_services.py
├── .env # Environment variables
├── requirements.txt # Python dependencies
└── README.md # Project documentation
The following environment variables are stored in .env. Loading and usage of these variables is explained in Usage
MONGODB_USERNAME: The username for MongoDB. Example: rootMONGODB_PASSWORD: The password for MongoDB. Example: 1234MONGODB_HOST: The host for MongoDB. Example: localhostOPENAI_API_KEY: The API Key used to make requests to the OpenAI API. Example: sk-abcdefghijklmnopqrstuvwxyz1234567890abcdSERVER_URL: The online server url. Example: https://online-server-url.onrender.com/
To load environment variables from a .env file in Python, you can use the python-dotenv package. Here’s how you can do it:
-
Save an
.envfile in your project. WARNING: make sure it is found in.gitignore. Save the above Variables in the.envfile using the exact provided names. -
Install the
python-dotenvpackage (if you haven’t already):pip install python-dotenv
-
A brief example on how to load a specific environment variable:
from dotenv import load_dotenv from globals import globals # Load the appropriate .env file if globals.env_status == "dev": load_dotenv('.env.dev') else: load_dotenv('.env.prod') mongodb_host = os.getenv('MONGODB_HOST')
--env: Specifies the environment to run the server in. Valid options aredevandprod. The default isdev.
To run the server in the dev environment (default), use the following command:
python server.pyOr explicitly specify the environment:
python server.py --env devThis will start the server on 127.0.0.1 (localhost) at port 8002.
To run the server in the prod environment, use the following command:
python server.py --env prodThis will start the server on 127.0.0.1 (localhost) at port 8001.