Skip to content

Commit 8e8affe

Browse files
committed
get started with Prompt flow
1 parent a3ce554 commit 8e8affe

File tree

9 files changed

+997
-19
lines changed

9 files changed

+997
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Here are the preferred tools for development.
4040
| [8_streamlit_azure_openai_batch](./apps/8_streamlit_azure_openai_batch/README.md) | Call Azure OpenAI Batch API with Streamlit | ![8_streamlit_azure_openai_batch](./docs/images/8_streamlit_azure_openai_batch.main.png) |
4141
| [9_streamlit_azure_document_intelligence](./apps/9_streamlit_azure_document_intelligence/README.md) | Call Azure AI Document Intelligence API with Streamlit | ![9_streamlit_azure_document_intelligence](./docs/images/9_streamlit_azure_document_intelligence.main.png) |
4242
| [10_streamlit_batch_transcription](./apps/10_streamlit_batch_transcription/README.md) | Call Batch Transcription API with Streamlit | ![10_streamlit_batch_transcription](./docs/images/10_streamlit_batch_transcription.main.png) |
43+
| [11_promptflow](./apps/11_promptflow/README.md) | Get started with Prompt flow | No Image |
4344
| [99_streamlit_examples](./apps/99_streamlit_examples/README.md) | Code samples for Streamlit | ![99_streamlit_examples](./docs/images/99_streamlit_examples.explaindata.png) |
4445

4546
## How to run

apps/11_promptflow/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/.promptflow/*

apps/11_promptflow/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Getting Started with Prompt flow
2+
3+
This application explains how to get started with [Prompt flow](https://github.com/microsoft/promptflow), a Python library that provides a simple and easy way to build conversational AI applications.
4+
5+
## Prerequisites
6+
7+
- Python 3.10 or later
8+
- Azure OpenAI Service
9+
10+
## Overview
11+
12+
Prompt flow is a suite of development tools designed to streamline the end-to-end development cycle of LLM-based AI applications, from ideation, prototyping, testing, evaluation to production deployment and monitoring. It makes prompt engineering much easier and enables you to build LLM apps with production quality.
13+
14+
## Usage
15+
16+
1. Get the API key for Azure OpenAI Service
17+
1. Copy [.env.template](../../.env.template) to `.env` in the same directory
18+
1. Set credentials in `.env`
19+
1. Run scripts in the [apps/11_promptflow](./) directory
20+
21+
Set up the environment and install dependencies:
22+
23+
```shell
24+
# Create a virtual environment
25+
$ python -m venv .venv
26+
27+
# Activate the virtual environment
28+
$ source .venv/bin/activate
29+
30+
# Install dependencies
31+
$ pip install -r requirements.txt
32+
```
33+
34+
## Examples
35+
36+
[Prompt flow > Quick start](https://microsoft.github.io/promptflow/how-to-guides/quick-start.html) provides a quick start guide to Prompt flow.
37+
38+
### [chat_minimal](https://github.com/microsoft/promptflow/tree/main/examples/flex-flows/chat-minimal)
39+
40+
**Run as normal Python script**
41+
42+
```shell
43+
$ python apps/11_promptflow/chat_minimal/main.py
44+
```
45+
46+
**Run from CLI**
47+
48+
```shell
49+
$ cd apps/11_promptflow/chat_minimal
50+
51+
# Test flow
52+
$ pf flow test \
53+
--flow main:chat \
54+
--inputs question="What's the capital of France?"
55+
56+
# Test flow: multi turn, access to http://localhost:{EPHEMERAL_PORT}
57+
$ pf flow test \
58+
--flow main:chat \
59+
--ui
60+
61+
# Create run with multiple lines data
62+
$ pf run create \
63+
--flow main:chat \
64+
--data ./data.jsonl \
65+
--column-mapping question='${data.question}' \
66+
--stream
67+
```
68+
69+
## References
70+
71+
- [Prompt flow > repos](https://github.com/microsoft/promptflow)
72+
- [Prompt flow > documents](https://microsoft.github.io/promptflow/)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: Minimal Chat
3+
model:
4+
api: chat
5+
configuration:
6+
type: azure_openai
7+
azure_deployment: gpt-4o
8+
parameters:
9+
temperature: 0.2
10+
max_tokens: 1024
11+
inputs:
12+
question:
13+
type: string
14+
sample:
15+
question: "What is Prompt flow?"
16+
---
17+
18+
system:
19+
You are a helpful assistant.
20+
21+
user:
22+
{{question}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"question": "What is Prompt flow?"}
2+
{"question": "What is ChatGPT? Please explain with consise statement"}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from pathlib import Path
2+
3+
from dotenv import load_dotenv
4+
from promptflow.core import Prompty
5+
from promptflow.tracing import start_trace, trace
6+
7+
BASE_DIR = Path(__file__).absolute().parent
8+
9+
10+
@trace
11+
def chat(question: str) -> str:
12+
load_dotenv()
13+
prompty = Prompty.load(source=f"{BASE_DIR}/chat.prompty")
14+
return prompty(question=question)
15+
16+
17+
if __name__ == "__main__":
18+
start_trace()
19+
20+
result = chat("What's the capital of France?")
21+
print(result)

0 commit comments

Comments
 (0)