TroyDoesAI commited on
Commit
b84a5e8
1 Parent(s): 3e973b5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +228 -1
README.md CHANGED
@@ -1,3 +1,230 @@
1
  ---
2
- license: cc-by-sa-4.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: cc-by-4.0
3
  ---
4
+
5
+ # Lets try this Mixtral thing because everyone likes MOE right?
6
+
7
+ [![Chat Image](https://drive.google.com/uc?export=view&id=1tRJDS9oHDgSDDC466soI3NXDzOLkucdQ)](https://drive.google.com/uc?export=view&id=1tRJDS9oHDgSDDC466soI3NXDzOLkucdQ)
8
+
9
+ ## Experiemental Mermaid Model: 3x7B Mermaid Mixtral-3x7b
10
+ Lets see if its any good, this is 1 epoch of a synthetic dataset exclusively created using my dataset augmentation toolkit
11
+ using MermaidMistral 7B and MermaidSolar outputs at factual temp range 0.1 to 0.5.
12
+
13
+ Using my method I have created a dataset of mermaid diagrams from models originally trained by the original 500 hand curated dataset entries at varying temperature ranges.
14
+
15
+ My toolkit is released for others to expand their dataset with more diverse examples.
16
+
17
+ This model is an example of training using this method.
18
+
19
+ Link: https://github.com/Troys-Code/AI_Research/tree/main
20
+
21
+ Send this as the most simple example of how to use my model for code to mermaid flow diagrams.
22
+ The rest of the prompt engineering is up to you.
23
+
24
+ Example to excite the Prompt Engineers out there, Many people have been sending me prompts they use for creating various knowledge graphs, flow diagrams, story board flows, even getting the model to create what if scenario graphs, code flow is its basic skill but it seems like the model is going to keep getting better the more datasets people provide me.
25
+ Example with something a little more advanced, but please be creative and see what you can get it to do.
26
+
27
+
28
+ The model will auto complete from the word graph TB;
29
+
30
+ # Important Note:
31
+ - This is the intution you should understand from how the model likes to perform the best from all my testing so far.
32
+
33
+ Below you can expect a graph such as this:
34
+ ```mermaid
35
+ graph TB;
36
+ A[Start] --> B[Read Input Source];
37
+ B --> C{Input Source Type};
38
+ C -->|File Path| D[Load File Content];
39
+ C -->|String| E[Convert String to List Item];
40
+ D --> F[Create Input Data List];
41
+ E --> F;
42
+
43
+ F --> G[Initialize Generator Object];
44
+ G --> H[Set Temperature Range];
45
+ H --> I[Loop Over Each Prompt];
46
+
47
+ subgraph Generate Response For Each Prompt
48
+ direction TB;
49
+
50
+ I --> J[Get Current Prompt];
51
+ J --> K[Call OpenAI API];
52
+ K --> L{Response Unique?};
53
+ L --> |No| M[Increase Temperature];
54
+ M --> N[Retry With New Temperature];
55
+ L --> |Yes| O[Convert to Image];
56
+ O --> P[Add Entry to All Entries];
57
+ N --> I;
58
+
59
+ end;
60
+
61
+ I --> Q[All Prompts Processed];
62
+ Q --> R[Write Output to File];
63
+ R --> S[End];
64
+
65
+ style J fill:#ddd,stroke:#777;
66
+ style K fill:#ccc,stroke:#777;
67
+ style L fill:#eee,stroke:#777;
68
+ style M fill:#ff9,stroke:#777;
69
+ style N fill:#f99,stroke:#777;
70
+ style O fill:#aaf,stroke:#777;
71
+ style P fill:#fff,stroke:#777;
72
+ ```
73
+ Use my toolkit to inference my model and automate some Knowledge Graphs for your own needs.
74
+
75
+ -----
76
+ ```mermaid
77
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
78
+
79
+ ### Instruction:
80
+ Generate the mermaid code block describing the code in excellent detail so I can look at the diagram and understand every single function or the high level diagram in the same full diagram.
81
+
82
+ ### Input:
83
+ import argparse
84
+ import json
85
+ import os
86
+ import requests
87
+ import subprocess
88
+ import tempfile
89
+
90
+ class MermaidDiagramGenerator:
91
+ def __init__(self, theme='dark', background='transparent'):
92
+ self._theme = theme
93
+ self._background = background
94
+ self._entries_dir = os.path.join(os.getcwd(), 'Entries')
95
+ os.makedirs(self._entries_dir, exist_ok=True)
96
+
97
+ def convert_to_image(self, mermaid_code, entry_number, output_number):
98
+ clean_code = self._remove_mermaid_block_markers(mermaid_code)
99
+ output_filename = f"entry_{entry_number}_{output_number}.png"
100
+ output_path = os.path.join(self._entries_dir, output_filename)
101
+ self._generate_image_from_code(clean_code, output_path)
102
+ return output_path
103
+
104
+ def _remove_mermaid_block_markers(self, code):
105
+ code_lines = code.strip().splitlines()
106
+ if code_lines[0].startswith("```mermaid") and code_lines[-1] == "```":
107
+ return "\n".join(code_lines[1:-1]).strip()
108
+ return code
109
+
110
+ def _generate_image_from_code(self, mermaid_code, output_path):
111
+ with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.mmd') as temp_file:
112
+ temp_file.write(mermaid_code)
113
+ input_path = temp_file.name
114
+ result = subprocess.run(["mmdc", "-i", input_path, "-o", output_path, "-t", self._theme, "-b", self._background], shell=True, check=False)
115
+ os.remove(input_path)
116
+ if result.returncode != 0:
117
+ raise ValueError("Mermaid diagram generation failed.")
118
+
119
+ def read_input(input_source):
120
+ if os.path.isfile(input_source):
121
+ filename, file_extension = os.path.splitext(input_source)
122
+ if file_extension == '.json':
123
+ with open(input_source, 'r') as file:
124
+ return json.load(file)
125
+ elif file_extension == '.txt':
126
+ with open(input_source, 'r') as file:
127
+ return [{"input": file.read()}]
128
+ else:
129
+ return [{"input": input_source}]
130
+
131
+ def generate_response(prompt, base_temperatures, stream, generator, entry_number, unique_outputs):
132
+ # prompt_template = f"{prompt}\n\n```mermaid\n"
133
+
134
+ prompt_template = """
135
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
136
+
137
+ ### Instruction:
138
+ Create the mermaid diagram for the following input:
139
+
140
+ ### Input:
141
+ {input}
142
+
143
+ ### Response:
144
+ ```mermaid
145
+ """.format(input=prompt)
146
+
147
+ url = "http://127.0.0.1:5000/v1/completions"
148
+ headers = {"Content-Type": "application/json"}
149
+ dataset_entries = []
150
+
151
+ for output_number, temp in enumerate(base_temperatures, start=1):
152
+ while True:
153
+ data = {
154
+ "prompt": prompt_template,
155
+ "max_tokens": 4096,
156
+ "temperature": temp,
157
+ "top_p": 1.0,
158
+ "seed": -1,
159
+ "top_k": 4,
160
+ "repetition_penalty": 1.0,
161
+ "guidance_scale": 1.0,
162
+ "typical_p": 1.0,
163
+ "stream": stream,
164
+ }
165
+
166
+ response = requests.post(url, headers=headers, json=data, verify=False)
167
+ response_text = response.json()['choices'][0]['text'].strip()
168
+
169
+ if response_text.endswith("```"): # Check if response ends with ```
170
+ response_text = response_text[:-3].strip() # Remove ``` from the end
171
+
172
+ if response_text not in unique_outputs:
173
+ try:
174
+ image_path = generator.convert_to_image(response_text, entry_number, output_number)
175
+ print(f"Mermaid diagram generated at: {image_path}")
176
+ unique_outputs.add(response_text)
177
+ break
178
+ except ValueError as e:
179
+ print(f"Validation failed, retrying... Error: {e}")
180
+ else:
181
+ temp += 0.1 # Adjust temperature if output is not unique
182
+
183
+ dataset_entry = {
184
+ "input": prompt,
185
+ "output": f"```mermaid\n{response_text}\n```",
186
+ "temperature": temp
187
+ }
188
+ dataset_entries.append(dataset_entry)
189
+
190
+ return dataset_entries
191
+
192
+ def generate_unique_responses(input_data, base_temperatures, stream, generator):
193
+ all_entries = []
194
+ unique_outputs = set()
195
+
196
+ for entry_number, entry in enumerate(input_data, start=1):
197
+ prompt = entry.get("input", "")
198
+ if prompt:
199
+ entries = generate_response(prompt, base_temperatures, stream, generator, entry_number, unique_outputs)
200
+ all_entries.extend(entries) # Extend the list with new entries
201
+
202
+ return all_entries
203
+
204
+ def main(input_source, stream=False):
205
+ generator = MermaidDiagramGenerator()
206
+ input_data = read_input(input_source)
207
+ base_temperatures = [i / 10 for i in range(5, 11)] # Adjusted for batch of unique outputs per input
208
+ output_file = "output.json"
209
+
210
+ all_entries = generate_unique_responses(input_data, base_temperatures, stream, generator)
211
+
212
+ # Write all entries to the JSON file at once
213
+ with open(output_file, "w") as f:
214
+ json.dump(all_entries, f, indent=4) # Dump the entire list of entries into the file
215
+
216
+ if __name__ == "__main__":
217
+ parser = argparse.ArgumentParser(description="Generate unique responses and validate Mermaid diagrams.")
218
+ parser.add_argument('input_source', type=str, help='A multi-line string, path to a .txt file, or a .json file with prompts.')
219
+ parser.add_argument('--stream', action='store_true', help='Use streaming responses.')
220
+ args = parser.parse_args()
221
+
222
+ main(args.input_source, args.stream)
223
+
224
+
225
+ ### Response:
226
+ ```mermaid
227
+ graph TB;
228
+ -----
229
+
230
+ ![Example Of More Advanced Prompting Of My Model Found here](https://huggingface.co/TroyDoesAI/MermaidMixtral-2x7b/raw/main/Advanced_Prompting_Mermaid.txt)