Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flex flow, Prompty & Tracing examples #1741

Merged
merged 174 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
35f2297
code-first example first version
wangchao1230 Jan 15, 2024
16dedad
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Jan 15, 2024
3c52a44
update
wangchao1230 Jan 15, 2024
312d19c
update
wangchao1230 Jan 15, 2024
5518ab2
update output
D-W- Jan 16, 2024
082a356
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Jan 16, 2024
7a285b5
update requirements
D-W- Jan 26, 2024
fdbc354
update remote
D-W- Jan 26, 2024
9a8694a
update sample
D-W- Jan 26, 2024
42033e0
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Jan 31, 2024
dbb4fe7
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Jan 31, 2024
114e50c
snapshot
wangchao1230 Jan 31, 2024
bdc37bb
snapshot
wangchao1230 Jan 31, 2024
fc503a2
update dag entry
D-W- Jan 31, 2024
7437165
add trace tutorial
wangchao1230 Feb 1, 2024
f725eba
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 1, 2024
6530929
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 1, 2024
1563431
snap
wangchao1230 Feb 1, 2024
97bf47a
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 1, 2024
931f6c0
snapshot
wangchao1230 Feb 1, 2024
515b926
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
D-W- Feb 1, 2024
bb8969f
update
wangchao1230 Feb 1, 2024
5cf176a
update
D-W- Feb 1, 2024
5fd7420
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
D-W- Feb 1, 2024
f605e8e
change sample to use env var
D-W- Feb 1, 2024
3cc8ef7
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 1, 2024
c183b9c
update precommit
D-W- Feb 1, 2024
fa0cd9f
update private version
D-W- Feb 1, 2024
785288b
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
D-W- Feb 1, 2024
2a18f63
resolve comments
wangchao1230 Feb 2, 2024
46b09c6
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
wangchao1230 Feb 2, 2024
5852896
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 4, 2024
a19a961
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 4, 2024
8721fbf
fix cspell
wangchao1230 Feb 4, 2024
a29a276
fix cspell
wangchao1230 Feb 4, 2024
b4406b4
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 4, 2024
c8d225d
add langchain example
wangchao1230 Feb 4, 2024
39e5844
update langchain example
wangchao1230 Feb 4, 2024
eb177fe
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 5, 2024
c9d84e4
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 6, 2024
541ebc4
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 7, 2024
d8d5979
add new eval flow example
wangchao1230 Feb 7, 2024
5e9ba1d
update quickstart.ipynb
wangchao1230 Feb 7, 2024
14da12a
update
wangchao1230 Feb 7, 2024
d50c055
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 7, 2024
556e59d
fix comment
wangchao1230 Feb 7, 2024
d9b51b1
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
wangchao1230 Feb 7, 2024
b52f392
User class init for eval
brynn-code Feb 7, 2024
8ea01f2
add eval flow for basic chat
wangchao1230 Feb 7, 2024
e0fca91
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
wangchao1230 Feb 7, 2024
f33ed80
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 18, 2024
50bee16
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 18, 2024
cd51a3a
update to dataclass
D-W- Feb 19, 2024
25dc341
update env var
D-W- Feb 20, 2024
38da090
update `start_trace` import as it is exposed
zhengfeiwang Feb 20, 2024
cd65eac
rename imports
wangchao1230 Feb 20, 2024
f85b0d9
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
wangchao1230 Feb 20, 2024
1d336fd
update
wangchao1230 Feb 20, 2024
6c594ac
re-org all eager flow to singler folder
wangchao1230 Feb 21, 2024
f5965d7
update paths
wangchao1230 Feb 21, 2024
d6dea4b
update
wangchao1230 Feb 22, 2024
fdd4082
add readme for trace
lisagreenview Feb 22, 2024
61022fc
update
wangchao1230 Feb 23, 2024
4d5e437
update trace readme
lisagreenview Feb 26, 2024
5f48fb8
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
lisagreenview Feb 26, 2024
fc5a681
update trace README
lisagreenview Feb 26, 2024
c1a9287
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 28, 2024
f9b4ee8
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Feb 29, 2024
ab8e66c
fix ci
wangchao1230 Feb 29, 2024
b5b47c7
fix flake8
wangchao1230 Mar 1, 2024
ed3c8e3
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 6, 2024
30ee5ed
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 7, 2024
ee10fdb
change to promptflow.tracing
wangchao1230 Mar 8, 2024
17d0f10
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 8, 2024
a17489c
refine the env vars
wangchao1230 Mar 8, 2024
7ef7a93
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 14, 2024
cabdb9d
update
wangchao1230 Mar 14, 2024
2cbb6dc
Merge branch 'main' into clwan/eager-mode-sample
zhengfeiwang Mar 15, 2024
466280b
add tracing example
zhengfeiwang Mar 15, 2024
2b530b4
rename as flex flows
wangchao1230 Mar 15, 2024
f81d85f
move and update gpt3.5
zhengfeiwang Mar 18, 2024
4d57c66
refine
wangchao1230 Mar 18, 2024
5ef35bc
refine
wangchao1230 Mar 18, 2024
b73e193
update autogen sample
wangchao1230 Mar 20, 2024
b58a0be
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 20, 2024
a804f6e
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 20, 2024
fe1ea6d
update
wangchao1230 Mar 20, 2024
98479aa
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 29, 2024
2cd2193
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Mar 30, 2024
06353b9
update
wangchao1230 Apr 1, 2024
85f6f16
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 1, 2024
bd52262
update requirements.txt
wangchao1230 Apr 1, 2024
358dcff
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 1, 2024
e8884e0
update
wangchao1230 Apr 2, 2024
de62421
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 3, 2024
150a409
fix typo
wangchao1230 Apr 3, 2024
6b7bbc9
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 8, 2024
49ecec5
update
wangchao1230 Apr 8, 2024
b119649
gen workflow and readme
wangchao1230 Apr 8, 2024
146494d
update .env logic in workflow
wangchao1230 Apr 8, 2024
9d65262
update .env logic in workflow
wangchao1230 Apr 8, 2024
c6db71e
refine samples
wangchao1230 Apr 8, 2024
e98f075
refine samples
wangchao1230 Apr 8, 2024
43ec860
refine samples
wangchao1230 Apr 8, 2024
83d4e01
refine samples
wangchao1230 Apr 8, 2024
54d998a
update workflow
wangchao1230 Apr 8, 2024
c5021f0
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 10, 2024
998ac5a
flow.dag.yaml to flow.flex.yaml
wangchao1230 Apr 10, 2024
21e6e85
refine
wangchao1230 Apr 10, 2024
2c4d396
update sample.json
wangchao1230 Apr 10, 2024
422c4ac
update sample
wangchao1230 Apr 10, 2024
d5d6039
refine trace doc
wangchao1230 Apr 11, 2024
e2bece6
update class based flex flow example
wangchao1230 Apr 11, 2024
a1cd2e4
make IO in events
zhengfeiwang Apr 11, 2024
8358d60
snapshot
wangchao1230 Apr 11, 2024
c1c26e0
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
wangchao1230 Apr 11, 2024
133707b
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 11, 2024
39c6f34
snapshot
wangchao1230 Apr 12, 2024
c8ba56c
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 12, 2024
432219c
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 12, 2024
3ce8bdc
snapshot
wangchao1230 Apr 12, 2024
27ea88c
addd workflows for prompty examples
wangchao1230 Apr 12, 2024
635346b
snapshot
wangchao1230 Apr 12, 2024
41cb38c
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 12, 2024
9e3f66d
snapshot
wangchao1230 Apr 12, 2024
6133664
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 12, 2024
1737051
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 12, 2024
e39e74a
update
wangchao1230 Apr 12, 2024
da2d3b4
update
wangchao1230 Apr 12, 2024
e4dee41
snapshot
wangchao1230 Apr 12, 2024
933e53a
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 12, 2024
5107ee2
update deployment version
wangchao1230 Apr 12, 2024
12503c1
snapshot
wangchao1230 Apr 12, 2024
baa1f8c
snapshot
wangchao1230 Apr 12, 2024
7ba0264
snapshot
wangchao1230 Apr 12, 2024
acf91b6
snapshot
wangchao1230 Apr 12, 2024
4c6f1d6
refine env in workflow
wangchao1230 Apr 12, 2024
0552ff0
fix error
lalala123123 Apr 12, 2024
792a0ea
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
lalala123123 Apr 12, 2024
63eca71
fix error
lalala123123 Apr 12, 2024
8acf989
refine env in workflow
wangchao1230 Apr 12, 2024
a254a9c
fix sample
wangchao1230 Apr 12, 2024
274eba0
refine workflow
wangchao1230 Apr 12, 2024
4f29e64
update
wangchao1230 Apr 12, 2024
b6bda7b
update
wangchao1230 Apr 12, 2024
3256f60
multi container
wangchao1230 Apr 12, 2024
5a71759
fix
wangchao1230 Apr 12, 2024
fb45083
fix
wangchao1230 Apr 12, 2024
b8166f1
update
wangchao1230 Apr 15, 2024
653a77a
update trace ui screenshots
zhengfeiwang Apr 15, 2024
f73c95a
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
zhengfeiwang Apr 15, 2024
387f884
update
wangchao1230 Apr 15, 2024
e35d2b7
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 15, 2024
652be1c
fix sample ci
wangchao1230 Apr 15, 2024
3e2e7f9
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
wangchao1230 Apr 15, 2024
1dfad62
resolve comments
wangchao1230 Apr 15, 2024
5fede0c
refine docs
wangchao1230 Apr 15, 2024
9f3a3bc
refine doc
wangchao1230 Apr 15, 2024
e652653
refine prompty sample
wangchao1230 Apr 16, 2024
96e19b1
refine trace doc
wangchao1230 Apr 16, 2024
3542fe6
Flex flow with connection examples (#2799)
D-W- Apr 16, 2024
05f20d9
refine sample
wangchao1230 Apr 16, 2024
420dcef
refine sample
wangchao1230 Apr 16, 2024
726016b
fix ci
wangchao1230 Apr 16, 2024
377597e
fix CI
D-W- Apr 16, 2024
082a524
firstName -> first_name
wangchao1230 Apr 16, 2024
e0a595f
Merge branch 'clwan/eager-mode-sample' of https://github.com/microsof…
wangchao1230 Apr 16, 2024
8361a73
fix
wangchao1230 Apr 16, 2024
04e43b0
Merge branch 'main' into clwan/eager-mode-sample
wangchao1230 Apr 16, 2024
261675c
update
wangchao1230 Apr 16, 2024
7fe18ed
resolve PM comments
wangchao1230 Apr 17, 2024
18de662
update requirements
0mza987 Apr 17, 2024
048136f
trigger the examples
0mza987 Apr 17, 2024
4722cc0
update
wangchao1230 Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions examples/flows/chat/chat-basic-code-first/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Basic chat (code-first)
This example shows how to create a basic chat flow using code-first approach. It demonstrates how to create a chatbot that can remember previous interactions and use the conversation history to generate next message.

Tools used in this flow:
- `llm` tool

## Prerequisites

Install promptflow sdk and other dependencies in this folder:
```bash
pip install -r requirements.txt
```

## What you will learn

In this flow, you will learn
- how to compose a chat flow.
- prompt template format of LLM tool chat api. Message delimiter is a separate line containing role name and colon: "system:", "user:", "assistant:".
See <a href="https://platform.openai.com/docs/api-reference/chat/create#chat/create-role" target="_blank">OpenAI Chat</a> for more about message role.
```jinja
system:
You are a chatbot having a conversation with a human.

user:
{{question}}
```
- how to consume chat history in prompt.
```jinja
{% for item in chat_history %}
user:
{{item.inputs.question}}
assistant:
{{item.outputs.answer}}
{% endfor %}
```

## Getting started

### 1 Create connection for LLM tool to use
Go to "Prompt flow" "Connections" tab. Click on "Create" button, select one of LLM tool supported connection types and fill in the configurations.

Currently, there are two connection types supported by LLM tool: "AzureOpenAI" and "OpenAI". If you want to use "AzureOpenAI" connection type, you need to create an Azure OpenAI service first. Please refer to [Azure OpenAI Service](https://azure.microsoft.com/en-us/products/cognitive-services/openai-service/) for more details. If you want to use "OpenAI" connection type, you need to create an OpenAI account first. Please refer to [OpenAI](https://platform.openai.com/) for more details.

```bash
# Override keys with --set to avoid yaml file changes
pf connection create --file ../../../connections/azure_openai.yml --set api_key=<your_api_key> api_base=<your_api_base> --name open_ai_connection
```

Note in [flow.dag.yaml](flow.dag.yaml) we are using connection named `open_ai_connection`.
```bash
# show registered connection
pf connection show --name open_ai_connection
```

### 2 Start chatting

```bash
# run chat flow with default question in flow.dag.yaml
pf flow test --flow .

# run chat flow with new question
pf flow test --flow . --inputs question="What's Azure Machine Learning?"

# start a interactive chat session in CLI
pf flow test --flow . --interactive

# start a interactive chat session in CLI with verbose info
pf flow test --flow . --interactive --verbose
```

12 changes: 12 additions & 0 deletions examples/flows/chat/chat-basic-code-first/chat.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
system:
You are a helpful assistant.

{% for item in chat_history %}
user:
{{item.inputs.question}}
assistant:
{{item.outputs.answer}}
{% endfor %}

user:
{{question}}
2 changes: 2 additions & 0 deletions examples/flows/chat/chat-basic-code-first/data.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"question": "What is Prompt flow?"}
{"question": "What is ChatGPT?"}
3 changes: 3 additions & 0 deletions examples/flows/chat/chat-basic-code-first/flow.dag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json
path: flow.py
entry: flow_entry
53 changes: 53 additions & 0 deletions examples/flows/chat/chat-basic-code-first/flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from dataclasses import dataclass
from jinja2 import Template
from pathlib import Path
from promptflow import trace, PFClient
from promptflow.tools.aoai import chat


BASE_DIR = Path(__file__).absolute().parent


@trace
def load_prompt(jinja2_template: str, question: str, chat_history: list) -> str:
"""Load prompt function."""
with open(BASE_DIR / jinja2_template, "r", encoding="utf-8") as f:
tmpl = Template(f.read(), trim_blocks=True, keep_trailing_newline=True)
prompt = tmpl.render(question=question, chat_history=chat_history)
return prompt


@dataclass
class Result:
answer: str


@trace
def flow_entry(question: str='What is ChatGPT?', chat_history: list = []) -> Result:
"""Flow entry function."""
from promptflow._sdk._configuration import Configuration

prompt = load_prompt("chat.jinja2", question, chat_history)
config = Configuration.get_instance()
# TODO: create your own config.json
workspace_config = config._get_workspace_from_config(path="./config.json")
wangchao1230 marked this conversation as resolved.
Show resolved Hide resolved
config.set_config(
Configuration.CONNECTION_PROVIDER,
"azureml:" + workspace_config
)
pf = PFClient()
connection = pf.connections.get("open_ai_connection", with_secrets=True) # TODO: add connection to function inputs
output = chat(
wangchao1230 marked this conversation as resolved.
Show resolved Hide resolved
connection=connection,
prompt=prompt,
deployment_name="gpt-35-turbo",
wangchao1230 marked this conversation as resolved.
Show resolved Hide resolved
max_tokens=256,
temperature=0.7,
)
# TODO: Result(answer=output)
return dict(answer=output)


if __name__ == "__main__":
result = flow_entry("What's Azure Machine Learning?", [])
print(result)
2 changes: 2 additions & 0 deletions examples/flows/chat/chat-basic-code-first/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--extra-index-url https://azuremlsdktestpypi.azureedge.net/test-promptflow/
promptflow[azure]==0.0.116642424
3 changes: 3 additions & 0 deletions examples/flows/standard/basic-code-first/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AZURE_OPENAI_API_KEY=<your_AOAI_key>
AZURE_OPENAI_API_BASE=<your_AOAI_endpoint>
AZURE_OPENAI_API_TYPE=azure
125 changes: 125 additions & 0 deletions examples/flows/standard/basic-code-first/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Basic standard flow (code-first)
wangchao1230 marked this conversation as resolved.
Show resolved Hide resolved
A basic standard flow using code-first approach calls Azure OpenAI with connection info stored in environment variables.

## Prerequisites

Install promptflow sdk and other dependencies:
```bash
pip install -r requirements.txt
```

## Run flow

- Prepare your Azure Open AI resource follow this [instruction](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal) and get your `api_key` if you don't have one.

- Setup environment variables

Ensure you have put your azure open ai endpoint key in [.env](.env) file. You can create one refer to this [example file](.env.example).

```bash
cat .env
```

- Test flow/node
```bash
# test with default input value in flow.dag.yaml
pf flow test --flow .

# test with flow inputs
pf flow test --flow . --inputs text="Java Hello World!"

```

- Create run with multiple lines data
```bash
# using environment from .env file (loaded in user code: hello.py)
pf run create --flow . --data ./data.jsonl --column-mapping text='${data.text}' --stream
```

You can also skip providing `column-mapping` if provided data has same column name as the flow.
Reference [here](https://aka.ms/pf/column-mapping) for default behavior when `column-mapping` not provided in CLI.

- List and show run meta
```bash
# list created run
pf run list

# get a sample run name

name=$(pf run list -r 10 | jq '.[] | select(.name | contains("basic_code_first")) | .name'| head -n 1 | tr -d '"')
# show specific run detail
pf run show --name $name

# show output
pf run show-details --name $name

# visualize run in browser
pf run visualize --name $name
```

## Run flow with connection
Storing connection info in .env with plaintext is not safe. We recommend to use `pf connection` to guard secrets like `api_key` from leak.

- Show or create `open_ai_connection`
```bash
# create connection from `azure_openai.yml` file
# Override keys with --set to avoid yaml file changes
pf connection create --file ../../../connections/azure_openai.yml --set api_key=<your_api_key> api_base=<your_api_base>

# check if connection exists
pf connection show -n open_ai_connection
```

- Test using connection secret specified in environment variables
**Note**: we used `'` to wrap value since it supports raw value without escape in powershell & bash. For windows command prompt, you may remove the `'` to avoid it become part of the value.

```bash
# test with default input value in flow.dag.yaml
pf flow test --flow . --environment-variables AZURE_OPENAI_API_KEY='${open_ai_connection.api_key}' AZURE_OPENAI_API_BASE='${open_ai_connection.api_base}'
```

- Create run using connection secret binding specified in environment variables, see [run.yml](run.yml)
```bash
# create run
pf run create --flow . --data ./data.jsonl --stream --environment-variables AZURE_OPENAI_API_KEY='${open_ai_connection.api_key}' AZURE_OPENAI_API_BASE='${open_ai_connection.api_base}' --column-mapping text='${data.text}'
# create run using yaml file
pf run create --file run.yml --stream

# show outputs
name=$(pf run list -r 10 | jq '.[] | select(.name | contains("basic_variant_0")) | .name'| head -n 1 | tr -d '"')
pf run show-details --name $name
```

## Run flow in cloud with connection
- Assume we already have a connection named `open_ai_connection` in workspace.
```bash
# set default workspace
az account set -s <your_subscription_id>
az configure --defaults group=<your_resource_group_name> workspace=<your_workspace_name>
```

- Create run
```bash
# run with environment variable reference connection in azureml workspace
pfazure run create --flow . --data ./data.jsonl --environment-variables AZURE_OPENAI_API_KEY='${open_ai_connection.api_key}' AZURE_OPENAI_API_BASE='${open_ai_connection.api_base}' --column-mapping text='${data.text}' --stream --runtime example-runtime-ci
# run using yaml file
pfazure run create --file run.yml --stream --runtime example-runtime-ci
```

- List and show run meta
```bash
# list created run
pfazure run list -r 3

# get a sample run name
name=$(pfazure run list -r 100 | jq '.[] | select(.name | contains("basic_code_first")) | .name'| head -n 1 | tr -d '"')

# show specific run detail
pfazure run show --name $name

# show output
pfazure run show-details --name $name

# visualize run in browser
pfazure run visualize --name $name
```
3 changes: 3 additions & 0 deletions examples/flows/standard/basic-code-first/data.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"text": "Python Hello World!"}
{"text": "C Hello World!"}
{"text": "C# Hello World!"}
3 changes: 3 additions & 0 deletions examples/flows/standard/basic-code-first/flow.dag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json
path: flow.py
entry: flow_entry
32 changes: 32 additions & 0 deletions examples/flows/standard/basic-code-first/flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from jinja2 import Template
from pathlib import Path
from promptflow import trace

from hello import my_llm_tool

BASE_DIR = Path(__file__).absolute().parent


@trace
def load_prompt(jinja2_template: str, text: str) -> str:
"""Load prompt function."""
with open(BASE_DIR / jinja2_template, "r", encoding="utf-8") as f:
prompt = Template(
f.read(), trim_blocks=True, keep_trailing_newline=True
).render(text=text)
return prompt


@trace
def flow_entry(text: str = "Hello World!") -> str:
"""Flow entry function."""
prompt = load_prompt("hello.jinja2", text)
output = my_llm_tool(
prompt=prompt, deployment_name="text-davinci-003", max_tokens=120
)
return output


if __name__ == "__main__":
result = flow_entry("Hello, world!")
print(result)
2 changes: 2 additions & 0 deletions examples/flows/standard/basic-code-first/hello.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{# Please replace the template with your own prompt. #}
Write a simple {{text}} program that displays the greeting message when executed.
Loading
Loading