No project description provided
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptflow_starter_template-0.1.2.tar.gz.
File metadata
- Download URL: promptflow_starter_template-0.1.2.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.0 CPython/3.12.9 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ed650ce24d83c378b15e7c3ac25359176061744028d763c98f66353879dd8e5
|
|
| MD5 |
3494a55b6ade184a688854ffc665ccc2
|
|
| BLAKE2b-256 |
cd8d4962a975bb4902ceeef225e9c713f1deb7c4c7401736b7c9faff9e04bc6f
|
File details
Details for the file promptflow_starter_template-0.1.2-py3-none-any.whl.
File metadata
- Download URL: promptflow_starter_template-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.0 CPython/3.12.9 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33a78979551a478099d49fe7502fec7a3af9e4c05443ef37d4eaa23e267a8b93
|
|
| MD5 |
c549d95af44cb9836f2000c597f0e1d3
|
|
| BLAKE2b-256 |
3d8d830de224d4e748d16c813380757fe5d320c97e36b7f7b4ed499a0cbcc1ad
|