Files
wehub-resource-sync e768098d0e
Flake8 Lint / flake8 (push) Waiting to run
Spell check CI / Spell_Check (push) Waiting to run
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:52 +08:00
..

Basic chat

A prompt that uses the chat API to answer questions with chat history, leveraging promptflow connection.

Prerequisites

Install promptflow-devkit:

pip install promptflow-devkit

What you will learn

In this flow, you will learn

  • how to compose a chat flow.
  • prompt template format of chat api. Message delimiter is a separate line containing role name and colon: "system:", "user:", "assistant:". See OpenAI Chat for more about message role.
    system:
    You are a chatbot having a conversation with a human.
    
    user:
    {{question}}
    
  • how to consume chat history in prompt.
    {% for item in chat_history %}
    {{item.role}}:
    {{item.content}}
    {% endfor %}
    

Getting started

Create connection for prompty 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 for more details. If you want to use "OpenAI" connection type, you need to create an OpenAI account first. Please refer to OpenAI for more details.

# 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>

Note in chat.prompty we are using connection named open_ai_connection.

# show registered connection
pf connection show --name open_ai_connection

Run prompty

  • Test flow: single turn
# run chat flow with default question in flow.flex.yaml
pf flow test --flow chat.prompty

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

# run chat flow with sample.json
pf flow test --flow chat.prompty --inputs sample.json
  • Test flow: multi turn
# start test in chat ui
pf flow test --flow chat.prompty --ui
  • Create run with multiple lines data
# using environment from .env file (loaded in user code: hello.py)
pf run create --flow chat.prompty --data ./data.jsonl --column-mapping question='${data.question}' --stream

You can also skip providing column-mapping if provided data has same column name as the flow. Reference here for default behavior when column-mapping not provided in CLI.

  • List and show run meta
# list created run
pf run list

# get a sample run name

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

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