Prompt Flow Devkit
Prompt Flow is a development tool designed to streamline the end-to-end development cycle of Large Language Model (LLM)-based AI applications, covering ideation, prototyping, testing, evaluation, and production deployment. It provides a Python SDK and CLI for building, testing, and managing AI workflows. The current version is 1.18.4, with frequent minor releases delivering new features and improvements.
Warnings
- breaking Prompt Flow versions 1.14.0 and later require Python 3.9 or higher. If you are on an older Python version (e.g., 3.8), you must upgrade your environment before installing or upgrading to `promptflow>=1.14.0`.
- breaking Breaking changes were introduced in connection-related classes (`AzureOpenAIConnection`, `OpenAIConnection`, `TestConnection`, `ConnectionProvider`) in versions 1.10.0 and 1.13.0. This might require updates to existing flow YAMLs or Python code that defines or uses connections.
- gotcha Prompt Flow is under active and rapid development. While minor version increments often introduce new features, they can also include breaking changes to existing APIs (e.g., client methods, flow definition syntax, tool inputs/outputs). Always review the `CHANGELOG.md` file in the GitHub repository when planning an upgrade, especially across minor versions.
Install
-
pip install promptflow
Imports
- tool
from promptflow import tool
- AzureOpenAIConnection
from promptflow.connections import AzureOpenAIConnection
- PromptFlowClient
from promptflow.client import PromptFlowClient
Quickstart
import os
from promptflow import tool
@tool
def summarize_text(text: str, max_length: int = 100) -> str:
"""
A simple tool that summarizes text by truncating it.
In a real Prompt Flow, this might invoke an LLM via a connection.
"""
if len(text) <= max_length:
return text
return text[:max_length-3] + "..."
# You can test a tool directly as a Python function:
long_text = "This is a very long piece of text that needs to be summarized. It contains many words and details."
print(f"Original: {long_text}")
print(f"Summarized: {summarize_text(long_text, max_length=30)}")
# To interact with Prompt Flow programmatically, initialize the client:
# client = PromptFlowClient(subscription_id=os.environ.get("AZURE_SUBSCRIPTION_ID", ""),
# resource_group_name=os.environ.get("AZURE_RESOURCE_GROUP_NAME", ""),
# workspace_name=os.environ.get("AZURE_WORKSPACE_NAME", ""))
# You would then use the client to manage flows, connections, and runs.