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 .env
file in your project. WARNING: make sure it is found in .gitignore
. Save the above Variables in the .env
file using the exact provided names.
Install the python-dotenv
package (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 are dev
and prod
. The default is dev
.To run the server in the dev
environment (default), use the following command:
python server.py
Or explicitly specify the environment:
python server.py --env dev
This 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 prod
This will start the server on 127.0.0.1
(localhost) at port 8001
.