Welcome to the Python Foundation Model (FM) Playground, an example app to explore how to use Amazon Bedrock with boto3, the AWS SDK for Python.
Important: This application is for educational purposes and not intended for production use.
This repository includes a FastAPI application and a Next.js frontend, both executable locally. Below is a screenshot of the app in action.
us-east-1
and has not been tested in every AWS Region. For more information see AWS Regional Services.resources/bedrock-access-policy.json
(display policy).Ensure you have the following installed:
us-east-1
:
After verifying the prerequisites, follow these steps:
Open a terminal, navigate to a directory of your choice, and execute the following command:
git clone https://github.com/build-on-aws/python-fm-playground.git
It is recommended to use a virtual environment for your Python projects to manage dependencies separately for each project. If you're not already in a virtual environment, navigate to the project directory to create and activate the virtual environment:
cd python-fm-playground
python -m venv .venv
.venvScriptsactivate
cd python-fm-playground
python -m venv .venv
source .venv/bin/activate
In the backend
directory, install the packages required by running the following in the virtual environment:
pip install -r requirements.txt
After successful installation you can start the backend server by executing the following command:
python main.py
Once the server is running, you will see the following output:
INFO: Started server process [14712]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:55500 (Press CTRL+C to quit)
Note: The backend runs on port 55500 by default. See below for port changes.
In a new terminal window, navigate to the frontend
directory and install the packages required by running the following command:
npm install
After successful installation you can start the frontend application by executing the following command:
npm run dev
When the application is running, you will see the following output:
> [email protected] dev
> next dev
▲ Next.js 14.0.0
- Local: http://localhost:3000
✓ Ready in 3.3s
Note: The frontend runs on port 3000 by default. See below for port changes.
To access the application, open http://localhost:3000
in your web browser.
To halt the application, you will need to stop both the backend and frontend processes.
In the terminal where the frontend is running, press Ctrl + C
to terminate the process.
Similarly, in the backend terminal, use the Ctrl + C
shortcut to stop the server.
To deactivate the virtual environment, you can simply close the backend terminal, or execute the following command:
.venvScriptsdeactivate.bat
deactivate
If you encounter any issues, you can forcefully terminate the processes by finding the process ID (PID
) and using the kill
command on Unix-based systems or Task Manager on Windows.
Change the backend port in the following files:
backend/config.py
frontend/app/app.config.js
To run the frontend on a different port:
npm run dev -- --port NEW_PORT
The AWS Region is hard-coded in the application. However, if your local AWS_REGION
environment variable is set to a different region, the application may fail. In this case, please make sure to either unset AWS_REGION
, or set it to us-east-1
.
This library is licensed under the MIT-0 License. See the LICENSE file.
See CONTRIBUTING for more information.