promptflow-starter-template
This project, promptflow-starter-template, uses a modern tech stack to develop applications with Large Language Models (LLMs) and the Promptflow framework. The key technologies are:
- Promptflow: Microsoft Promptflow LLM Framework.
- FastAPI: High-performance API framework.
- Poetry: Dependency management and packaging.
- Docker: Containerization platform.
- Visual Studio Code: Code editor with development container support.
- PyPi: Your promptflow can be packaged and pushed to PyPi or your own Python registry (JFrog Artifactory).
Purpose
The promptflow-starter-template simplifies setting up and managing LLM tools, making integration easier. It packages promptflow with Poetry and runs it with FastAPI in a Docker container.
Usage
To use the promptflow-starter-template, follow these steps:
Prerequisites
- An Azure subscription - Create one for free here.
- An Azure OpenAI Service resource with either gpt-4o or the gpt-4o-mini models deployed. We recommend using standard or global standard model deployment types for initial exploration. For more information about model deployment, see the resource deployment guide.
Steps
-
Setup the .devcontainer/devcontainer.env: Create a
.devcontainer/devcontainer.envfile with the following content:OPENAI_API_KEY=your_openai_api_key OPENAI_API_BASE=your_openai_api_base_url
Replace
your_openai_api_keywith your actual OpenAI API key andyour_openai_api_base_urlwith your Azure OpenAI API base URL. -
Verify that the connection.yaml matches your deployment: Create a
connection.yamlfile with the following content:$schema: https://azuremlschemas.azureedge.net/promptflow/latest/AzureOpenAIConnection.schema.json name: open_ai_connection type: azure_open_ai module: promptflow.connections api_key: "${env.OPENAI_API_KEY}" api_base: "<user-input>" api_version: "2024-10-01-preview" api_type: "azure"
Replace
<user-input>with your Azure OpenAI API base URL. -
Build and run the development container: Open the project in Visual Studio Code and use the Remote - Containers extension to build and run the development container. This will automatically install the dependencies and set up the environment. It will also add the connection automatically.
-
Rename the project directory and update
pyproject.toml: Rename thepromptflow_starter_templatedirectory to your desired package name. Then, open thepyproject.tomlfile and update thename,authors,description,versionfield under[tool.poetry]to match your new package information.
You are now ready to start developing with the promptflow-starter-template.
Run the FastAPI endpoint
To run the FastAPI endpoint, use the following command:
uvicorn promptflow_starter_template.api:app --host 0.0.0.0 --port 5000 --workers 4
Note: Replace promptflow_starter_template with the package name from step 4.
Deployment steps
- Set up PyPi and GitHub Actions:
To publish your package to PyPi and automate the process with GitHub Actions, follow these steps:
Ensure you add your PyPi token to the GitHub repository secrets as
PYPI_API_TOKEN.
You have now set up your project for publishing to PyPi and automated the process with GitHub Actions.
-
Build and push Docker images: To build and push Docker images for your project, you can use the following commands:
There are two Dockerfiles in this project:
DockerfileandDockerfile.fastapi. TheDockerfileis used for python packagin, while theDockerfile.fastapiis specifically for the FastAPI production ready application. Thus, only the FastAPI Docker image needs to be pushed to the GitHub Container Registry to use it later. -
Add PYPI_API_TOKEN to .devcontainers/devcontainer.env
-
Build the Python package:
docker build --build-arg PYPI_API_TOKEN=$PYPI_API_TOKEN -t ghcr.io/fabianschurig/promptflow-starter-template/build:latest .
-
Build the Docker image using the package from previous step:
docker build -t ghcr.io/fabianschurig/promptflow-starter-template/fastapi:latest -f Dockerfile.fastapi --build-arg PACKAGE_INSTALL_NAME=promptflow-starter-template --build-arg PACKAGE_IMPORT_NAME=promptflow_starter_template .
-
Run the docker container:
docker run -e OPENAI_API_KEY=$OPENAI_API_KEY -e OPENAI_API_BASE=$OPENAI_API_BASE -p 5000:5000 ghcr.io/fabianschurig/promptflow-starter-template/fastapi:latest
-
Push the Docker image to GitHub Container Registry:
docker push ghcr.io/fabianschurig/promptflow-starter-template/fastapi:latest
-
Use the Docker compose Set environment variables to
.envif they are not set yet in the.devcontainer/devcontainer.env. Those are used when doingdocker compose up:HOST=0.0.0.0 PORT=5000 WORKERS=4 OPENAI_API_VERSION=2024-10-01-preview PACKAGE_INSTALL_NAME=promptflow-starter-template PACKAGE_IMPORT_NAME=promptflow_starter_template
Metadata
Release files for promptflow-starter-template 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| promptflow_starter_template-0.1.2.tar.gz | 6.3 kB | Without provenance | Details for promptflow_starter_template-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptflow_starter_template-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for promptflow_starter_template-0.1.2-py3-none-any.whl |
Total release size: 14.7 kB
Release files / promptflow_starter_template-0.1.2.tar.gz
| Download URL | promptflow_starter_template-0.1.2.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ed650ce24d83c378b15e7c3ac25359176061744028d763c98f66353879dd8e5
|
|
BLAKE2b-256 checksum How to use checksums |
cd8d4962a975bb4902ceeef225e9c713f1deb7c4c7401736b7c9faff9e04bc6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.0 CPython/3.12.9 Linux/6.8.0-1021-azure
|
Release files / promptflow_starter_template-0.1.2-py3-none-any.whl
| Download URL | promptflow_starter_template-0.1.2-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33a78979551a478099d49fe7502fec7a3af9e4c05443ef37d4eaa23e267a8b93
|
|
BLAKE2b-256 checksum How to use checksums |
3d8d830de224d4e748d16c813380757fe5d320c97e36b7f7b4ed499a0cbcc1ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.0 CPython/3.12.9 Linux/6.8.0-1021-azure
|
Security for promptflow-starter-template 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.