Skip to content

Commit d36692b

Browse files
committed
Add describe-workflow feature
1 parent 8e6f8de commit d36692b

6 files changed

+278
-96
lines changed

README.md

+106-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# gpt-workflow
2-
Generate workflows (for flowcharts or low code) via LLM.
2+
Generate workflows (for flowcharts or low code) in DOT format, from natural language, via an LLM.
3+
4+
Also perform the inverse: describe a given workflow (given in DOT format) in natural language.
35

46
## Approach: generate DOT notation as a simple format to represent a workflow
57

@@ -23,8 +25,6 @@ The DOT script generated by the LLM can be further processed, for example by gen
2325
## Example Execution - generating flows in DOT format from natural language input
2426

2527
```
26-
[[[TEST Simple workflow to model a tree of decisions]]]
27-
---
2828
>> Create a flow that makes a series of decisions about whether to approve a mortgage application
2929
Writing png to '.\temp\dot_graph_1.png'
3030
digraph G {
@@ -60,7 +60,9 @@ digraph G {
6060
decision_employment -> reject;
6161
decision_down_payment -> reject;
6262
}
63-
---
63+
```
64+
65+
```
6466
>> Create a flow that makes a series of decisions about whether to recommend a job interview candidate.
6567
Writing png to '.\temp\dot_graph_2.png'
6668
digraph G {
@@ -96,7 +98,9 @@ digraph G {
9698
decision_skills -> reject;
9799
decision_references -> reject;
98100
}
99-
---
101+
```
102+
103+
```
100104
>> Create a flow that makes a series of decisions about an animal, to decide what kind of animal is it
101105
Writing png to '.\temp\dot_graph_3.png'
102106
digraph G {
@@ -132,52 +136,9 @@ digraph G {
132136
decision_has_fins -> Bear;
133137
Bear [shape=box, label="Bear"];
134138
}
135-
[[[TEST Simple workflow adding an item to a list]]]
136-
---
137-
>> Create a flow that takes a list and adds an item of the same type
138-
Writing png to '.\temp\dot_graph_4.png'
139-
digraph G {
140-
141-
// start
142-
start [shape=ellipse, label="Start"];
143-
144-
// add_item
145-
add_item [shape=box, label="Add Item"];
146-
147-
// end
148-
end [shape=ellipse, label="End"];
149-
150-
// start -> add_item
151-
start -> add_item;
152-
153-
// add_item -> end
154-
add_item -> end;
155-
156-
add_item [shape=box, label="Add Item"];
157-
}
158-
---
159-
>> Create a flow that takes two lists and concatenates them
160-
Writing png to '.\temp\dot_graph_5.png'
161-
digraph G {
162-
163-
// start
164-
start [shape=ellipse, label="Start"];
165-
166-
// concatenate_lists
167-
concatenate_lists [shape=box, label="Concatenate Lists"];
168-
169-
// end
170-
end [shape=ellipse, label="End"];
171-
172-
// start -> concatenate_lists
173-
start -> concatenate_lists;
174-
175-
// concatenate_lists -> end
176-
concatenate_lists -> end;
139+
```
177140

178-
concatenate_lists [shape=box, label="Concatenate Lists"];
179-
}
180-
---
141+
```
181142
>> Create a flow that takes a list and an object. Call another flow to get a boolean result. If the boolean is true, then add the item to the list.
182143
Writing png to '.\temp\dot_graph_6.png'
183144
digraph G {
@@ -214,7 +175,11 @@ digraph G {
214175
215176
call_flow [shape=box, label="Call Flow"];
216177
}
217-
[[[TEST Irrelevant prompts]]]
178+
```
179+
180+
## Example Execution - Handling irrelevant prompts
181+
182+
```
218183
---
219184
>> what is 2 + 5 divided by 10 ?
220185
I'm sorry, but I can only assist with questions related to creating a flow chart.
@@ -226,6 +191,96 @@ I'm sorry, but I can only assist with questions related to creating a flow chart
226191
I'm sorry, but I don't have access to personal information.
227192
```
228193

194+
## Example Execution - Describing a given workflow
195+
196+
```
197+
digraph G {
198+
199+
// start
200+
start [shape=ellipse, label="Start"];
201+
202+
// decision_credit_score
203+
start -> decision_credit_score;
204+
decision_credit_score [shape=Mdiamond, label="Credit Score > 700?"];
205+
206+
// decision_income
207+
decision_credit_score -> decision_income;
208+
decision_income [shape=Mdiamond, label="Income > $50,000?"];
209+
210+
// decision_employment
211+
decision_income -> decision_employment;
212+
decision_employment [shape=Mdiamond, label="Employment > 2 years?"];
213+
214+
// decision_down_payment
215+
decision_employment -> decision_down_payment;
216+
decision_down_payment [shape=Mdiamond, label="Down Payment > 20%?"];
217+
218+
// approve
219+
decision_down_payment -> approve;
220+
approve [shape=box, label="Approve"];
221+
222+
// reject
223+
decision_credit_score -> reject;
224+
reject [shape=box, label="Reject"];
225+
226+
decision_income -> reject;
227+
decision_employment -> reject;
228+
decision_down_payment -> reject;
229+
}
230+
231+
This flow chart represents a decision-making process for approving or rejecting a loan application.
232+
233+
The process starts at the "Start" node and then moves to the "Credit Score > 700?" decision node. If the credit score is greater than 700, the flow moves to the "Income > $50,000?" decision node. If the income is greater than $50,000, the flow moves to the "Employment > 2 years?" decision node. If the employment is greater than 2 years, the flow moves to the "Down Payment > 20%?" decision node. If the down payment is greater than 20%, the flow reaches the "Approve" node, indicating that the loan application should be approved.
234+
235+
However, if at any point in the process a condition is not met, the flow moves to the "Reject" node, indicating that the loan application should be rejected.
236+
237+
Overall, this flow chart helps guide the decision-making process for loan approval based on various criteria such as credit score, income, employment, and down payment.
238+
```
239+
240+
```
241+
digraph G {
242+
243+
// start
244+
start [shape=ellipse, label="Start"];
245+
246+
// decision_has_feathers
247+
start -> decision_has_feathers;
248+
decision_has_feathers [shape=Mdiamond, label="Has feathers?"];
249+
250+
// decision_can_fly
251+
decision_has_feathers -> decision_can_fly;
252+
decision_can_fly [shape=Mdiamond, label="Can fly?"];
253+
254+
// decision_has_fins
255+
decision_has_feathers -> decision_has_fins;
256+
decision_has_fins [shape=Mdiamond, label="Has fins?"];
257+
258+
// Hawk
259+
decision_can_fly -> Hawk;
260+
Hawk [shape=box, label="Hawk"];
261+
262+
// Penguin
263+
decision_can_fly -> Penguin;
264+
Penguin [shape=box, label="Penguin"];
265+
266+
// Dolphin
267+
decision_has_fins -> Dolphin;
268+
Dolphin [shape=box, label="Dolphin"];
269+
270+
// Bear
271+
decision_has_fins -> Bear;
272+
Bear [shape=box, label="Bear"];
273+
}
274+
275+
This flow chart represents a decision-making process to determine the characteristics of different animals based on whether they have feathers, can fly, or have fins.
276+
277+
The process starts at the "Start" node and then moves to the "Has feathers?" decision node. If the animal has feathers, the flow moves to the "Can fly?" decision node. If the animal can fly, the flow reaches the "Hawk" node, indicating that the animal is a hawk. However, if the animal cannot fly, the flow reaches the "Penguin" node, indicating that the animal is a penguin.
278+
279+
If the animal does not have feathers, the flow moves to the "Has fins?" decision node. If the animal has fins, the flow reaches the "Dolphin" node, indicating that the animal is a dolphin. However, if the animal does not have fins, the flow reaches the "Bear" node, indicating that the animal is a bear.
280+
281+
Overall, this flow chart helps classify animals based on their characteristics, specifically whether they have feathers, can fly, or have fins
282+
```
283+
229284
## Dependencies
230285

231286
- Requires an LLM - by default, uses OpenAI's ChatGPT.

config__database_schema_creator.py

-42
This file was deleted.

main_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from config__database_schema_creator import EXPERT_COMMANDS
1+
from prompts__dot_graph_creator import EXPERT_COMMANDS
22
import core
33

44
command_messages = core.create_command_messages(EXPERT_COMMANDS)

main_web_service.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from urllib.parse import urlparse, parse_qs
44
import threading, socket
55

6-
from config__database_schema_creator import EXPERT_COMMANDS
6+
from prompts__dot_graph_creator import EXPERT_COMMANDS
77
import core
88
import config
99
import config_web

prompts__dot_graph_creator.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from command import Command
2+
3+
# note: Instead of this steps-in-single-prompt approach, we could have an inter-dependent chain, to collect info about the app, THEN try to generate.
4+
# BUT the step-by-step approach works really well, at least with Chat-GPT3.5 Turbo.
5+
6+
create_dot_flowchart__expert_template = """You are Workflow Creator Bot, a bot that knows how to create a simple DOT format flow chart.
7+
You are great at answering questions about creating and altering a flow chart.
8+
9+
When you don't know the answer to a question, do not answer.
10+
11+
You are an AI assistant to assist an application developer with the creation of the flow chart via natural language input.
12+
13+
The output MUST be in DOT format as used by the graphviz tool only, based on the following example:
14+
```
15+
digraph G {
16+
17+
// decision_has_feathers
18+
start -> decision_has_feathers;
19+
decision_has_feathers -> decision_can_fly
20+
decision_has_feathers -> decision_has_fins
21+
22+
// decision_can_fly
23+
decision_can_fly -> Hawk
24+
decision_can_fly -> Penguin
25+
26+
// decision_has_fins
27+
decision_has_fins -> Dolphin
28+
decision_has_fins -> Bear
29+
30+
decision_has_feathers [shape=Mdiamond, label="Has feathers?"];
31+
decision_can_fly [shape=Mdiamond, label="Can fly?"];
32+
decision_has_fins [shape=Mdiamond, label="Has fins?"];
33+
}
34+
```
35+
36+
IMPORTANT: Only output valid DOT format as used by the graphviz tool.
37+
"""
38+
39+
describe_dot_flowchart__expert_template = """
40+
You are Workflow Describer Bot, a bot that knows how to describe a simple DOT format flow chart.
41+
You are great at describing the activity of the workflow, and providing a summary of the general purpose or goal of the workflow.
42+
43+
When you don't know the answer to a question, do not answer.
44+
45+
You are an AI assistant to assist an application developer with providing a description or explanation of a given flow chart that is in DOT format.
46+
47+
The input is in DOT format as used by the graphviz tool. Here is an example:
48+
```
49+
digraph G {
50+
51+
// start
52+
start [shape=ellipse, label="Start"];
53+
54+
// decision_credit_score
55+
start -> decision_credit_score;
56+
decision_credit_score [shape=Mdiamond, label="Credit Score > 700?"];
57+
58+
// decision_income
59+
decision_credit_score -> decision_income;
60+
decision_income [shape=Mdiamond, label="Income > $50,000?"];
61+
62+
// decision_employment
63+
decision_income -> decision_employment;
64+
decision_employment [shape=Mdiamond, label="Employment > 2 years?"];
65+
66+
// decision_down_payment
67+
decision_employment -> decision_down_payment;
68+
decision_down_payment [shape=Mdiamond, label="Down Payment > 20%?"];
69+
70+
// approve
71+
decision_down_payment -> approve;
72+
approve [shape=box, label="Approve"];
73+
74+
// reject
75+
decision_credit_score -> reject;
76+
reject [shape=box, label="Reject"];
77+
78+
decision_income -> reject;
79+
decision_employment -> reject;
80+
decision_down_payment -> reject;
81+
}
82+
```
83+
84+
The output MUST be in clear natural language, in a concise, friendly tone.
85+
"""
86+
87+
# Each expert is a prompt that knows how to handle one type of user input
88+
EXPERT_COMMANDS = [
89+
Command('create_dot_workflow', create_dot_flowchart__expert_template, "Good for answering questions about creating a workflow in DOT notation"),
90+
Command('describe_dot_workflow', describe_dot_flowchart__expert_template, "Good for describing a workflow given in DOT notation, summarizing its activity and its general purpose")
91+
]
92+
93+
def GetPromptToDescribeWorkflow(dotText):
94+
return f"""Descibe this workflow: ```{dotText}```"""

0 commit comments

Comments
 (0)