backend/
├── app/ # Contains the main application code
│ ├── Api/ # Contains the API router for handling requests
│ │ └── router.py # Endpoints for FastAPI to test features and handle incoming requests
│ ├── chats/ # Handles chat functionalities
│ ├── Features/ # Contains feature-specific modules
│ │ ├── Feature1/
│ │ │ ├── core.py
│ │ │ ├── tools.py
│ │ │ ├── Prompt/
│ │ │ └── metadata.json
│ │ ├── Feature2/
│ │ │ ├── core.py
│ │ │ ├── tools.py
│ │ │ ├── Prompt/
│ │ │ └── metadata.json
│ ├── services/ # Contains service modules
│ ├── utils/ # Contains utility modules
│ ├── app.yaml # Application configuration file
│ ├── Dependencies.py # Dependency management
│ ├── Main.py # Main entry point for the application
│ └── requirements.txt # Python dependencies
├── Dockerfile # Dockerfile for containerizing the application
└── README.md # Documentation file
cd backend/app
python -m venv env
source env/bin/activate
pip install -r requirements.txt
- A Google Cloud account.
- Access to the Google Cloud Platform console.
- Navigate to the Google Cloud Console.
- Go to IAM & Admin > Service Accounts.
- Click Create Service Account.
- Enter a name and description for the service account.
- Click Create.
- Assign the necessary roles to the service account (e.g., Editor, Viewer).
- Click Continue and then Done to finish creating the service account.
- In the Service Accounts page, click on the newly created service account.
- Go to the Keys tab.
- Click Add Key, then select Create new key.
- Choose JSON as the key type and click Create.
- The key will be downloaded automatically. Save this file securely.
- Rename the downloaded JSON key to
local-auth.json
. - Move or copy this file to your application's directory, specifically inside the
/app
directory.
- Open your command line interface.
- Set the path to the JSON key file by running:
set GOOGLE_APPLICATION_CREDENTIALS=/app/local-auth.json```
set ENV_TYPE="dev"
set PROJECT_ID="Enter your project ID here"
uvicorn main:app --reload
This guide is designed to help contributors set up and run the backend service using Docker. Follow these steps to ensure that your development environment is configured correctly.
NOTE: if you choose to authenticate Google Cloud through the SDK and not with a local serice account key, you must comment out GOOGLE_APPLICATION_CREDENTIALS
in the Dockerfile.
Before you start, ensure you have the following installed:
- Docker
- Python
Obtain a local-auth.json file which contains the Google service account credentials and place it in the root of the app/ directory within your project.
Navigate to the project's root directory and build the Docker image:
docker build -t kai-backend:latest .
Run the Docker container using the following command:
docker run -p 8000:8000 kai-backend:latest
This command starts a detached container that maps port 8000 of the container to port 8000 on the host.
The Docker container uses several key environment variables:
- GOOGLE_APPLICATION_CREDENTIALS points to /app/local-auth.json.
- ENV_TYPE set to "sandbox" for development.
- PROJECT_ID specifies your Google Cloud project ID.
- LangChain API integration is configured via:
LANGCHAIN_TRACING_V2
LANGCHAIN_ENDPOINT
LANGCHAIN_API_KEY
LANGCHAIN_PROJECT
- Ensure these variables are correctly configured in your Dockerfile or passed as additional parameters to your Docker run command if needed.
You can access the backend by visiting:
http://localhost:8000
After your container starts, you should see the FastAPI landing page, indicating that the application is running successfully.