TroyDoesAI commited on
Commit
829a2a0
1 Parent(s): e18bcfd

Upload example_of_how_to_use_my_model_requires_response_to_include_the_cue_tripleTicknewlinegraph_then_LR_RL_TD_TB_to_select_various_types_of_graphs_it_knows.txt

Browse files

How to use my model, please ensure the response includes
"
### Response:
```mermaid
graph TB
"

It is critical because I have it trained to work in my pipeline that anytime I put "```mermaid" it knows to create a mermaid block of anything in its context.

example_of_how_to_use_my_model_requires_response_to_include_the_cue_tripleTicknewlinegraph_then_LR_RL_TD_TB_to_select_various_types_of_graphs_it_knows.txt ADDED
@@ -0,0 +1,375 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
2
+
3
+ ### Instruction:
4
+ Create the detailed flow diagram utilizing mermaid js syntax separating functions from main logic:
5
+
6
+ ### Input:
7
+ #!/bin/bash
8
+ #set -x
9
+
10
+ log_file="bito_usage_log.txt"
11
+ prompt_folder="AI_Prompts"
12
+ total_input_token_count=0
13
+ total_output_token_count=0
14
+ lang_csv="programming_languages.csv"
15
+ skip_list_csv="skip_list.csv"
16
+
17
+ function bito_response_ok() {
18
+ echo "Validating response from Bito command..." >&2
19
+ [[ $1 -ne 0 || $2 == Whoops* || -z $2 ]] && return 1 || return 0
20
+ }
21
+
22
+ function update_token_usage() {
23
+ echo "Updating session token counts..." >&2
24
+ local tokens=$(echo "$1 $2" | wc -w | awk '{print int($1 * 1.34)}')
25
+ total_input_token_count=$((total_input_token_count + tokens))
26
+ total_output_token_count=$((total_output_token_count + tokens))
27
+ }
28
+
29
+ function log_token_usage_and_session_duration() {
30
+ echo "Finalizing session log with token usage and duration..." >&2
31
+ local duration=$(( $(date +%s) - start_time ))
32
+ echo "-----------------------------------------" | tee -a "$log_file"
33
+ echo "$(date "+%Y-%m-%d %H:%M:%S") - Total Token Usage for Session" | tee -a "$log_file"
34
+ echo "Total Input Tokens = $total_input_token_count" | tee -a "$log_file"
35
+ echo "Total Output Tokens = $total_output_token_count" | tee -a "$log_file"
36
+ echo "Session Duration: $((duration / 3600))h $(((duration % 3600) / 60))m $((duration % 60))s" | tee -a "$log_file"
37
+ echo "-----------------------------------------" | tee -a "$log_file"
38
+ }
39
+
40
+ function check_tools_and_files() {
41
+ echo "Ensuring all necessary tools and files are available..." >&2
42
+ local required_tools=("bito" "code2flow" "dot")
43
+ local required_files=("high_level_doc_prompt.txt" "system_introduction_prompt.txt")
44
+
45
+ for tool in "${required_tools[@]}"; do
46
+ if ! command -v "$tool" &> /dev/null; then
47
+ echo -e "\nError: Tool $tool is required but not found."
48
+ case "$tool" in
49
+ "bito")
50
+ echo " Install Bito CLI on MAC and Linux with:"
51
+ echo " sudo curl https://alpha.bito.ai/downloads/cli/install.sh -fsSL | bash"
52
+ echo " On Archlinux, install with yay or paru: yay -S bito-cli or paru -S bito-cli"
53
+ echo " For Windows, download and install the MSI from Bito's website."
54
+ echo " Follow the instructions provided by the installer."
55
+ ;;
56
+ "code2flow")
57
+ echo " Install Code2Flow from: https://github.com/scottrogowski/code2flow"
58
+ echo " Ensure it's accessible in your PATH."
59
+ ;;
60
+ "dot")
61
+ echo " Install Graphviz (dot) from: https://graphviz.org/download/"
62
+ echo " Ensure it's accessible in your PATH."
63
+ ;;
64
+ esac
65
+ exit 1
66
+ fi
67
+ done
68
+
69
+ for file in "${required_files[@]}"; do
70
+ if [ ! -f "$prompt_folder/$file" ]; then
71
+ echo -e "\nError: Missing required file: $prompt_folder/$file"
72
+ exit 1
73
+ fi
74
+ done
75
+ echo -e "All required tools and files are present. Proceeding...\n" >&2
76
+ }
77
+
78
+ function read_skip_list() {
79
+ echo "Loading exclusion patterns from skip list..." >&2
80
+ if [ -f "$skip_list_csv" ]; then
81
+ skip_list=()
82
+ while IFS=, read -r skip_item; do
83
+ skip_list+=("$skip_item")
84
+ done < "$skip_list_csv"
85
+ else
86
+ echo "Skip list file $skip_list_csv not found."
87
+ exit 1
88
+ fi
89
+ }
90
+
91
+ function is_skippable() {
92
+ echo "Evaluating if the path $1 should be excluded..." >&2
93
+ local path=$1
94
+ local skip_dirs_files=("logs" "node_modules" "dist" "target" "bin" "package-lock.json" "data.json" "build" ".gradle" ".idea" "gradle" "extension.js" "vendor.js" "ngsw.json" "polyfills.js" "init" ".gv")
95
+
96
+ for skip_item in "${skip_dirs_files[@]}"; do
97
+ if [[ "$path" == *"$skip_item"* ]]; then
98
+ return 0
99
+ fi
100
+ done
101
+
102
+ if [[ $(basename "$path") == .* ]]; then
103
+ return 0
104
+ fi
105
+
106
+ return 1
107
+ }
108
+
109
+ function call_bito_with_retry() {
110
+ echo "Initiating Bito command with retry for prompt file $2..." >&2
111
+ local input_text=$1 prompt_file_path=$2 error_message=$3
112
+ local attempt=1 MAX_RETRIES=5 RETRY_DELAY=10 output
113
+
114
+ while [ $attempt -le $MAX_RETRIES ]; do
115
+ echo "Attempt $attempt: Calling Bito for prompt '$prompt_file_path'..." >&2
116
+ output=$(echo -e "$input_text" | bito -p "$prompt_file_path")
117
+ local ret_code=$?
118
+
119
+ if ! bito_response_ok "$ret_code" "$output"; then
120
+ echo "Attempt $attempt: $error_message Retrying in $RETRY_DELAY seconds..." >&2
121
+ sleep $RETRY_DELAY
122
+ ((attempt++))
123
+ else
124
+ echo "Bito call successful on attempt $attempt." >&2
125
+ echo "$output"
126
+ update_token_usage "$input_text" "$output"
127
+ return 0
128
+ fi
129
+ done
130
+
131
+ echo "Failed to call Bito after $MAX_RETRIES attempts. $error_message" >&2
132
+ return 1
133
+ }
134
+
135
+ function create_module_documentation() {
136
+ local path_to_module="$1"
137
+ local documentation_directory="$2"
138
+ echo "Generating documentation for the module at $path_to_module..." >&2
139
+
140
+ if is_skippable "$path_to_module"; then
141
+ echo "Skipped $path_to_module as it's on the exclusion list."
142
+ return
143
+ fi
144
+
145
+ local name_of_module=$(basename "$path_to_module")
146
+ local content_of_module=$(<"$path_to_module")
147
+
148
+ local high_level_documentation
149
+ high_level_documentation=$(call_bito_with_retry "Module: $name_of_module\n---\n$content_of_module" "$prompt_folder/high_level_doc_prompt.txt" "High-level documentation creation failed for module: $name_of_module")
150
+ local ret_code=$?
151
+ if ! bito_response_ok "$ret_code" "$high_level_documentation"; then
152
+ echo "High-level documentation creation failed for module: $name_of_module"
153
+ return 1
154
+ fi
155
+
156
+ update_token_usage "$content_of_module" "$high_level_documentation"
157
+
158
+ local markdown_documentation_file="$documentation_directory/${name_of_module}_Doc.md"
159
+ echo -e "## Module: $name_of_module\n$high_level_documentation" >> "$markdown_documentation_file"
160
+
161
+ # Generate the flow chart for the module
162
+ generate_flow_chart "$path_to_module" "$documentation_directory/flowmaps"
163
+
164
+ # Add link to the flow chart in the documentation
165
+ local flow_chart_name=$(basename "$path_to_module" | cut -f 1 -d '.')
166
+ echo -e "\n![Flow Chart of $flow_chart_name](./flowmaps/${flow_chart_name}_FlowChart.png)\n" >> "$markdown_documentation_file"
167
+
168
+ echo -e "Documentation saved to $markdown_documentation_file\n\n" >&2
169
+ }
170
+
171
+ function extract_module_details_and_call_bito() {
172
+ local filename=$1 prompt_file_path=$2 lines=() current_module="" current_objectives="" current_operational_sequence="" capture_objectives=false capture_operational_sequence=false combined_output=""
173
+
174
+ echo "Compiling objectives and details for module in $filename..." >&2
175
+
176
+ while IFS= read -r line; do lines+=("$line"); done < "$filename"
177
+
178
+ for line in "${lines[@]}"; do
179
+ if [[ $line =~ ^##\ Module:\ (.*) ]]; then
180
+ if [[ -n $current_module ]]; then
181
+ echo "Processing module: $current_module with objectives and operational sequence" >&2
182
+ combined_output+="Module: $current_module\n---\nPrimary Objectives:\n$current_objectives\nOperational Sequence:\n$current_operational_sequence\n\n"
183
+ fi
184
+ current_module=${BASH_REMATCH[1]}
185
+ current_objectives="" current_operational_sequence=""
186
+ capture_objectives=false capture_operational_sequence=false
187
+ elif [[ $line =~ ^-\ \*\*Primary\ Objectives\*\*: ]]; then
188
+ capture_objectives=true
189
+ capture_operational_sequence=false
190
+ current_objectives+=$(echo $line | sed 's/.*\*\*Primary Objectives\*\*: //')$'\n'
191
+ elif [[ $line =~ ^-\ \*\*Operational\ Sequence\*\*: ]]; then
192
+ capture_operational_sequence=true
193
+ capture_objectives=false
194
+ current_operational_sequence+=$(echo $line | sed 's/.*\*\*Operational Sequence\*\*: //')$'\n'
195
+ elif $capture_objectives && [[ $line =~ ^-\ .+ ]]; then
196
+ current_objectives+=$(echo $line | sed 's/^-\ //')$'\n'
197
+ elif $capture_operational_sequence && [[ $line =~ ^-\ .+ ]]; then
198
+ current_operational_sequence+=$(echo $line | sed 's/^-\ //')$'\n'
199
+ elif [[ $line == "## "* || $line == "" ]]; then
200
+ capture_objectives=false capture_operational_sequence=false
201
+ fi
202
+ done
203
+
204
+ if [[ -n $current_module ]]; then
205
+ echo "Processing module: $current_module with objectives and operational sequence" >&2
206
+ combined_output+="Module: $current_module\n---\nPrimary Objectives:\n$current_objectives\nOperational Sequence:\n$current_operational_sequence\n\n"
207
+ fi
208
+
209
+ if bito_output=$(call_bito_with_retry "$combined_output" "$prompt_file_path" "Failed for module: $current_module"); then
210
+ echo "Bito call successful for module: $current_module" >&2
211
+ echo "$bito_output"
212
+ update_token_usage "$combined_output" "$bito_output"
213
+ else
214
+ echo "Failed to call bito for module: $current_module with adequate content." >&2
215
+ return 1
216
+ fi
217
+ }
218
+
219
+ function create_find_command() {
220
+ local lang_file="$1"
221
+ local folder_to_document="$2"
222
+ echo "Assembling command to locate relevant files in $folder_to_document..." >&2
223
+ local find_command="find \"$folder_to_document\" -type f"
224
+
225
+ while IFS= read -r ext; do
226
+ find_command="$find_command -o -name \"*.$ext\""
227
+ done < "$lang_file"
228
+
229
+ find_command="${find_command/-o /\\( } \)"
230
+ echo "$find_command"
231
+ }
232
+
233
+ function generate_flow_chart() {
234
+ local module_file="$1"
235
+ local flowchart_folder="$2"
236
+
237
+ # Check if the flowchart folder exists, if not, create it
238
+ if [ ! -d "$flowchart_folder" ]; then
239
+ echo "Creating flowchart directory: $flowchart_folder"
240
+ mkdir -p "$flowchart_folder"
241
+ fi
242
+
243
+ # Define the name of the flow chart file based on the module name
244
+ local module_name=$(basename "$module_file" | cut -f 1 -d '.')
245
+ local flowchart_file="$flowchart_folder/${module_name}_FlowChart.png"
246
+
247
+ # Call code2flow to generate the flow chart
248
+ code2flow "$module_file" -o "$flowchart_file" --hide-legend --no-trimming --verbose --skip-parse-errors
249
+
250
+ # Check if the flow chart was successfully generated
251
+ if [ -f "$flowchart_file" ]; then
252
+ echo "Flow chart created for module: $module_name"
253
+ else
254
+ echo "Failed to create flow chart for module: $module_name" >&2
255
+ fi
256
+ }
257
+
258
+ function generate_flow_chart_for_system() {
259
+ local source_folder="$1"
260
+ local output_file="$2"
261
+
262
+ # Check if the source folder exists
263
+ if [ ! -d "$source_folder" ]; then
264
+ echo "Source folder $source_folder does not exist" >&2
265
+ return 1
266
+ fi
267
+
268
+ # Check if the output directory exists, if not, create it
269
+ local output_dir=$(dirname "$output_file")
270
+ if [ ! -d "$output_dir" ]; then
271
+ echo "Creating directory for system flowchart: $output_dir"
272
+ mkdir -p "$output_dir"
273
+ fi
274
+
275
+ # Generate a flowchart for the entire system
276
+ echo "Generating system flowchart..."
277
+ code2flow "$source_folder" -o "$output_file" --hide-legend --no-trimming --verbose --skip-parse-errors
278
+
279
+ # Check if the flowchart was successfully generated
280
+ if [ -f "$output_file" ]; then
281
+ echo "System flowchart created successfully"
282
+ else
283
+ echo "Failed to create system flowchart" >&2
284
+ return 1
285
+ fi
286
+ }
287
+
288
+ # Capture Start Time
289
+ start_time=$(date +%s)
290
+
291
+ function main() {
292
+ echo "Verifying prerequisites before documentation generation..." >&2
293
+
294
+ # Check if required tools and files are present
295
+ check_tools_and_files
296
+
297
+ # Check if a folder name is provided as a command line argument
298
+ if [ $# -eq 0 ]; then
299
+ echo "Please provide a folder name as a command line argument" >&2
300
+ exit 1
301
+ fi
302
+
303
+ folder_to_document="$1"
304
+ docs_folder="doc_"$(basename "$folder_to_document")
305
+
306
+ # Check if the folder to document exists
307
+ if [ ! -d "$folder_to_document" ]; then
308
+ echo "Folder $folder_to_document does not exist" >&2
309
+ exit 1
310
+ fi
311
+
312
+ # Create a directory for the generated documentation if it doesn't exist
313
+ if [ ! -d "$docs_folder" ]; then
314
+ mkdir "$docs_folder"
315
+ fi
316
+
317
+ # Read the skip list from the CSV file
318
+ read_skip_list
319
+
320
+ # Define the path to the aggregated markdown file
321
+ aggregated_md_file="$docs_folder/High_Level_Doc.md"
322
+
323
+ # Clear existing aggregated markdown file if it exists
324
+ [ -f "$aggregated_md_file" ] && > "$aggregated_md_file"
325
+
326
+ # Use create_find_command to dynamically generate the find command with specified extensions
327
+ module_files=$(eval $(create_find_command "$lang_csv" "$folder_to_document"))
328
+
329
+ # Check if module_files is empty and display a warning if no files are found
330
+ if [ -z "$module_files" ]; then
331
+ echo "Warning: No files found for documentation generation." >&2
332
+ return
333
+ fi
334
+
335
+ # Generate high-level documentation for each found module file
336
+ for module_file in $module_files; do
337
+ # Create documentation for the module, including flow chart
338
+ create_module_documentation "$module_file" "$docs_folder"
339
+ done
340
+
341
+ # Aggregate individual markdown files into a main document
342
+ echo "# Module Overview" > "$aggregated_md_file"
343
+ for md_file in "$docs_folder"/*_Doc.md; do
344
+ if [ "$md_file" != "$aggregated_md_file" ]; then
345
+ cat "$md_file" >> "$aggregated_md_file"
346
+ fi
347
+ done
348
+
349
+ local introduction_and_summary=$(extract_module_details_and_call_bito "$aggregated_md_file" "$prompt_folder/system_introduction_prompt.txt")
350
+
351
+ # Prepend the introduction and summary to the aggregated Markdown file
352
+ local temp_file=$(mktemp)
353
+ mv "$aggregated_md_file" "$temp_file"
354
+ echo -e "# Introduction :\n" > "$aggregated_md_file"
355
+ echo "$introduction_and_summary" >> "$aggregated_md_file"
356
+
357
+ # Generate and append the system flow chart
358
+ generate_flow_chart_for_system "$folder_to_document" "$docs_folder/flowmaps/system_flowchart.png"
359
+ echo -e "\n# System Flowchart\n\n![System Flowchart](./flowmaps/system_flowchart.png)\n" >> "$aggregated_md_file"
360
+
361
+ # Append the rest of the original aggregated content
362
+ cat "$temp_file" >> "$aggregated_md_file"
363
+ rm "$temp_file"
364
+
365
+ # Log session duration and token usage
366
+ log_token_usage_and_session_duration
367
+
368
+ echo "Documentation generated in $docs_folder"
369
+ }
370
+
371
+ main "$@"
372
+
373
+ ### Response:
374
+ ```mermaid
375
+ graph