Skip to content

Commit 2ea0153

Browse files
committed
poetry run pf flow init --flow playground --type chat
1 parent 8e8affe commit 2ea0153

File tree

8 files changed

+165
-0
lines changed

8 files changed

+165
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.env
2+
__pycache__/
3+
.promptflow/*
4+
!.promptflow/flow.tools.json
5+
.runs/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"package": {},
3+
"code": {
4+
"chat.jinja2": {
5+
"type": "llm",
6+
"inputs": {
7+
"question": {
8+
"type": [
9+
"string"
10+
]
11+
},
12+
"chat_history": {
13+
"type": [
14+
"string"
15+
]
16+
}
17+
},
18+
"description": "Chat with Chatbot"
19+
}
20+
}
21+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Chat flow
2+
Chat flow is designed for conversational application development, building upon the capabilities of standard flow and providing enhanced support for chat inputs/outputs and chat history management. With chat flow, you can easily create a chatbot that handles chat input and output.
3+
4+
## Create connection for LLM tool to use
5+
You can follow these steps to create a connection required by a LLM tool.
6+
7+
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.
8+
9+
```bash
10+
# Override keys with --set to avoid yaml file changes
11+
# Create OpenAI connection
12+
pf connection create --file openai.yaml --set api_key=<your_api_key> --name open_ai_connection
13+
14+
# Create azure OpenAI connection
15+
# pf connection create --file azure_openai.yaml --set api_key=<your_api_key> api_base=<your_api_base> --name open_ai_connection
16+
```
17+
18+
Note in [flow.dag.yaml](flow.dag.yaml) we are using connection named `open_ai_connection`.
19+
```bash
20+
# show registered connection
21+
pf connection show --name open_ai_connection
22+
```
23+
Please refer to connections [document](https://promptflow.azurewebsites.net/community/local/manage-connections.html) and [example](https://github.com/microsoft/promptflow/tree/main/examples/connections) for more details.
24+
25+
## Develop a chat flow
26+
27+
The most important elements that differentiate a chat flow from a standard flow are **Chat Input**, **Chat History**, and **Chat Output**.
28+
29+
- **Chat Input**: Chat input refers to the messages or queries submitted by users to the chatbot. Effectively handling chat input is crucial for a successful conversation, as it involves understanding user intentions, extracting relevant information, and triggering appropriate responses.
30+
31+
- **Chat History**: Chat history is the record of all interactions between the user and the chatbot, including both user inputs and AI-generated outputs. Maintaining chat history is essential for keeping track of the conversation context and ensuring the AI can generate contextually relevant responses. Chat History is a special type of chat flow input, that stores chat messages in a structured format.
32+
33+
- **Chat Output**: Chat output refers to the AI-generated messages that are sent to the user in response to their inputs. Generating contextually appropriate and engaging chat outputs is vital for a positive user experience.
34+
35+
A chat flow can have multiple inputs, but Chat History and Chat Input are required inputs in chat flow.
36+
37+
## Interact with chat flow
38+
39+
Promptflow CLI provides a way to start an interactive chat session for chat flow. Customer can use below command to start an interactive chat session:
40+
41+
```
42+
pf flow test --flow <flow_folder> --interactive
43+
```
44+
45+
After executing this command, customer can interact with the chat flow in the terminal. Customer can press **Enter** to send the message to chat flow. And customer can quit with **ctrl+C**.
46+
Promptflow CLI will distinguish the output of different roles by color, <span style="color:Green">User input</span>, <span style="color:Gold">Bot output</span>, <span style="color:Blue">Flow script output</span>, <span style="color:Cyan">Node output</span>.
47+
48+
> =========================================<br>
49+
> Welcome to chat flow, <You-flow-name>.<br>
50+
> Press Enter to send your message.<br>
51+
> You can quit with ctrl+C.<br>
52+
> =========================================<br>
53+
> <span style="color:Green">User:</span> What types of container software there are<br>
54+
> <span style="color:Gold">Bot:</span> There are several types of container software available, including:<br>
55+
> 1. Docker: This is one of the most popular containerization software that allows developers to package their applications into containers and deploy them across different environments.<br>
56+
> 2. Kubernetes: This is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications.<br>
57+
>
58+
> <span style="color:Green">User:</span> What's the different between them<br>
59+
> <span style="color:Gold">Bot:</span> The main difference between the various container software systems is their functionality and purpose. Here are some key differences between them:<br>
60+
> 1. Docker is more focused on container packaging and deployment, while Kubernetes is more focused on container orchestration and management.<br>
61+
> 2. Kubernetes: Kubernetes is a container orchestration tool that helps manage and deploy containers at scale. It automates the deployment, scaling, and management of containerized applications across multiple hosts.<br>
62+
63+
If customer adds "--verbose" in the pf command, the output of each step will be displayed.
64+
65+
> =========================================<br>
66+
> Welcome to chat flow, Template Chat Flow.<br>
67+
> Press Enter to send your message.<br>
68+
> You can quit with ctrl+C.<br>
69+
> =========================================<br>
70+
> <span style="color:Green">User:</span> What types of container software there are<br>
71+
> <span style="color:Cyan">chat:</span> There are several types of container software available, including:<br>
72+
> 1. Docker: A popular container platform that is widely used in the industry.<br>
73+
> 2. Kubernetes: A container orchestration tool that helps manage and deploy containers at scale.<br>
74+
>
75+
> <span style="color:Gold">Bot:</span> There are several types of container software available, including:<br>
76+
> 1. Docker: A popular container platform that is widely used in the industry.<br>
77+
> 2. Kubernetes: A container orchestration tool that helps manage and deploy containers at scale.<br>
78+
>
79+
> <span style="color:Green">User:</span> What's the different between them<br>
80+
> <span style="color:Cyan">chat:</span> The main differences between container software are in their architecture, feature sets, and use cases. Here are some brief explanations of the differences between the examples I listed:<br>
81+
> 1. Docker: Docker is a container platform that is widely used for building, packaging, and deploying containerized applications. It is known for its ease of use, portability, and large ecosystem of tools and services.<br>
82+
> 2. Kubernetes: Kubernetes is a container orchestration tool that helps manage and deploy containers at scale. It automates the deployment, scaling, and management of containerized applications across multiple hosts.<br>
83+
>
84+
> <span style="color:Gold">Bot:</span> The main differences between container software are in their architecture, feature sets, and use cases. Here are some brief explanations of the differences between the examples I listed:<br>
85+
> 1. Docker: Docker is a container platform that is widely used for building, packaging, and deploying containerized applications. It is known for its ease of use, portability, and large ecosystem of tools and services.<br>
86+
> 2. Kubernetes: Kubernetes is a container orchestration tool that helps manage and deploy containers at scale. It automates the deployment, scaling, and management of containerized applications across multiple hosts.<br>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/AzureOpenAIConnection.schema.json
2+
name: open_ai_connection
3+
type: azure_open_ai
4+
api_key: "<user-input>"
5+
api_base: "<user-input>"
6+
api_type: "azure"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
system:
2+
You are a helpful assistant.
3+
4+
{% for item in chat_history %}
5+
user:
6+
{{item.inputs.question}}
7+
assistant:
8+
{{item.outputs.answer}}
9+
{% endfor %}
10+
11+
user:
12+
{{question}}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json
2+
inputs:
3+
chat_history:
4+
type: list
5+
is_chat_history: true
6+
default: []
7+
question:
8+
type: string
9+
is_chat_input: true
10+
outputs:
11+
answer:
12+
type: string
13+
reference: ${chat.output}
14+
is_chat_output: true
15+
nodes:
16+
- name: chat
17+
type: llm
18+
source:
19+
type: code
20+
path: chat.jinja2
21+
inputs:
22+
deployment_name: gpt-35-turbo
23+
max_tokens: '256'
24+
temperature: '0.7'
25+
chat_history: ${inputs.chat_history}
26+
question: ${inputs.question}
27+
api: chat
28+
connection: open_ai_connection
29+
environment:
30+
python_requirements_txt: requirements.txt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/OpenAIConnection.schema.json
2+
name: open_ai_connection
3+
type: open_ai
4+
api_key: "<user-input>"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
promptflow

0 commit comments

Comments
 (0)