3
3
4
4
import config
5
5
import service_chat
6
+ import util_file
6
7
7
8
# DEV note: NOT using langchain.
8
9
# 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):
16
17
return messages
17
18
18
19
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 )
19
35
20
36
def process_response (rsp , prompt_id ):
21
37
if DOT_GRAPH_START not in rsp :
22
38
return rsp
23
39
parts = rsp .split (DOT_GRAPH_START )
24
40
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
+
29
46
return dot_string
30
47
31
48
def execute_prompt (user_prompt , previous_messages , command_messages , prompt_id ):
0 commit comments