Skip to content

Commit 3bc71fc

Browse files
committed
Write out dot for diagnostics. Tidy output
1 parent d36692b commit 3bc71fc

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ I'm sorry, but I don't have access to personal information.
194194
## Example Execution - Describing a given workflow
195195

196196
```
197+
>> Descibe this workflow:
197198
digraph G {
198199
199200
// start
@@ -238,6 +239,7 @@ Overall, this flow chart helps guide the decision-making process for loan approv
238239
```
239240

240241
```
242+
>> Descibe this workflow:
241243
digraph G {
242244
243245
// start

core.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import config
55
import service_chat
6+
import util_file
67

78
# DEV note: NOT using langchain.
89
# Tried using langchain but it's validation gets in the way of more complex prompts.
@@ -16,16 +17,32 @@ def create_command_messages(expert_commands):
1617
return messages
1718

1819
DOT_GRAPH_START = "digraph G"
20+
DOT_SECTION_DELIMITER = "```"
21+
22+
def generate_output_file_path(prompt_id, extension):
23+
return os.path.join(config.PATH_TO_PNG_OUTDIR, f"dot_graph_{prompt_id}.{extension}")
24+
25+
def generate_png_from_dot(dot_string, prompt_id):
26+
graphs = pydot.graph_from_dot_data(dot_string)
27+
path_to_png = generate_output_file_path(prompt_id, "png")
28+
print(f"Writing png to '{path_to_png}'")
29+
graphs[0].write_png(path_to_png)
30+
31+
def write_dot_to_file(dot_string, prompt_id):
32+
path_to_dot = generate_output_file_path(prompt_id, "dot")
33+
print(f"Writing dot to '{path_to_dot}'")
34+
util_file.write_text_to_file(dot_string, path_to_dot)
1935

2036
def process_response(rsp, prompt_id):
2137
if DOT_GRAPH_START not in rsp:
2238
return rsp
2339
parts = rsp.split(DOT_GRAPH_START)
2440
dot_string = DOT_GRAPH_START + parts[1]
25-
graphs = pydot.graph_from_dot_data(dot_string)
26-
path_to_png = os.path.join(config.PATH_TO_PNG_OUTDIR, f"dot_graph_{prompt_id}.png")
27-
print(f"Writing png to '{path_to_png}'")
28-
graphs[0].write_png(path_to_png)
41+
if DOT_SECTION_DELIMITER in dot_string:
42+
dot_string = dot_string.split(DOT_SECTION_DELIMITER)[0]
43+
write_dot_to_file(dot_string, prompt_id)
44+
generate_png_from_dot(dot_string, prompt_id)
45+
2946
return dot_string
3047

3148
def execute_prompt(user_prompt, previous_messages, command_messages, prompt_id):

util_file.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def write_text_to_file(text, filepath):
2+
with open(filepath, "w", encoding='utf-8') as f:
3+
f.write(text)

0 commit comments

Comments
 (0)