-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompts_dot_graph_creator.py
63 lines (47 loc) · 2.91 KB
/
prompts_dot_graph_creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from command import Command
# 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.
# BUT the step-by-step approach works really well, at least with Chat-GPT3.5 Turbo.
create_dot_flowchart__expert_template = """You are Workflow Creator Bot, a bot that knows how to create a simple DOT format flow chart.
You are great at answering questions about creating and altering a flow chart.
When you don't know the answer to a question, do not answer.
You are an AI assistant to assist an application developer with the creation of the flow chart via natural language input.
The output MUST be in DOT format as used by the graphviz tool only, based on the following example:
```
digraph G {
// decision_has_feathers
start -> decision_has_feathers;
decision_has_feathers -> decision_can_fly
decision_has_feathers -> decision_has_fins
// decision_can_fly
decision_can_fly -> end_Hawk
decision_can_fly -> end_Penguin
// decision_has_fins
decision_has_fins -> end_Dolphin
decision_has_fins -> end_Bear
decision_has_feathers [shape=Mdiamond, label="Has feathers?"];
decision_can_fly [shape=Mdiamond, label="Can fly?"];
decision_has_fins [shape=Mdiamond, label="Has fins?"];
}
```
IMPORTANT: Nodes of the flow digraph MUST be named to match this whitelist:
- start, decision_<identifier>, end_<identifier>, while_<identifier>, read_items_from_storage_<identifier>, write_items_to_storage_<identifier>, create_list_enumerator_<identifier>, has_list_enumerator_more_items_<identifier>, get_next_item_from_enumerator_<identifier>, variable_<identifier>, parameter_<identifier>, call_flow_<identifier>, other_<identifier>
IMPORTANT: Only output valid DOT format as used by the graphviz tool.
"""
describe_dot_flowchart__expert_template = """
If the user asked for a description or summary of the DOT format flow chart then:
- provide an explanation of the flow, and an overall summary of the flow
- use clear natural language, in a concise, friendly tone.
"""
def getExpertCommandToCreateDot():
return Command('create_dot_workflow', create_dot_flowchart__expert_template, "Good for answering questions about creating a workflow in DOT notation")
def getExpertCommandToDescribeDot():
return 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")
# Each expert is a prompt that knows how to handle one type of user input
EXPERT_COMMANDS = [
getExpertCommandToDescribeDot(),
# Placing this last, so that its IMPORTANT message about whitelist is not ignored (LLMs tend to ignore content in middle)
# An approach like LangChain's MULTI_PROMPT_ROUTER_TEMPLATE would avoid this problem.
getExpertCommandToCreateDot(),
]
def GetPromptToDescribeWorkflow(dotText):
return f"""Descibe this workflow: ```{dotText}```"""