transformers safetensors mixtral text-generation conversational license:cc-by-sa-4.0 autotrain_compatible text-generation-inference endpoints_compatible region:us
---
license: cc-by-sa-4.0
---
---

# Mixtral 2x7b : Mermaid-Dolphin Model Fusion

[[Chat Image](https://drive.google.com/uc?export=view&id=1tRJDS9oHDgSDDC466soI3NXDzOLkucdQ)](https://drive.google.com/uc?export=view&id=1tRJDS9oHDgSDDC466soI3NXDzOLkucdQ)

## Introduction

Welcome to Mixtral, where Mermaids 🧜‍♀️ and Dolphins 🐬collaborate to bring you unparalleled creativity and intelligence in generating mermaid diagrams.

## Model Overview

Mermaid-Dolphin-Mixtral-2x7b merges the capabilities of:

- **Mermaid Models**: These models excel at crafting visually stunning mermaid diagrams, making complex data flows easy to comprehend.
* TroyDoesAI/MermaidMistralDPO
- **Dolphin Models by Eric Hartford**: Renowned for their intelligence and creativity, Dolphin models add a new dimension to Mixtral's capabilities.
* cognitivecomputations/dolphin-2.8-mistral-7b-v02

With Mermaid-Dolphin-Mixtral-2x7b, you can create mermaid diagrams with a blend of creativity and intelligence, making waves 🌊 in data visualization.

## Example Applications
- **Knowledge Graph Generation**: Create intricate knowledge graphs effortlessly.
- **Flow Diagrams**: Visualize complex data flows and processes.
- **Storyboards**: Craft engaging storyboards for your projects.
- **Scenario Planning**: Explore "what if" scenarios with ease.
- **Code Flow Visualization**: Understand code execution paths intuitively.

## Getting Started

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. 
Example with something a little more advanced, but please be creative and see what you can get it to do.

The model will auto complete from the word graph TB;

Example Video : https://drive.google.com/file/d/1cXgRqar-eEpVUJE14BjkciC1km5hSZ6Q/view

# Important Note:
- This is the intution you should understand from how the model likes to perform the best from all my testing so far.

Below you can expect a graph such as this: https://mermaid.live/edit#pako:eNp1lNtu2zAMhl-F0HUaJM2xHrAhzaluc2rSodiUXqg2l2iLJU-Wu6VJ3n207HTugOnCtsSPP2mS9oEFOkTmsY0R8RYerj-sFQD0-MoKY5_g4uIjXPMlihB8FacWVjo1AT7l2LWz9w9lEzzsYzzl9n5mP47kDmEh7PYIAz7RJOVO-lpZVPapjK6skWpzhCEn6wsaEnUnYDVMZGLBtxgVHgMXfMT7BoXFIr2BsMKRBTTMoXzjLiN3Mua-klaKnXxFGKNCI6w2MH_-jsHZd-zIG75CCw8YxRmTGoSlUJtzBW4c49Nr6RjmlDEMRbCFhdFRfNZxlyR9zktcBCMZTGKtEoSRfufl8GyF0lAyUqu3tsBZLVu-C33Lx5RePzWGavk-brZuHXTH-2K3g3mMqudDb-GXiDtHTA5v6XxW8meKn05_kYlDjjN9hCnVLaCCE1cqSUlu6tgZjYw1e3iUdgsz_PUfuBD-gskR5m8tp177kdiUwbkDF7wXhjBUmTJBPXqlbCMxKaGzvCP_FAxVWGpGXrp7ninkJUuye4BJgmGhde-YJX80kpo1T202XhQ1m90CWTpkxYeKnFiFRWgiIUP6mg6Zfc3sFiNcM48eQ2F-rNlanYgTqdWrvQqYZ02KFZbGIQ3EQAqakIh538QuodNYqK9aR2eItsw7sN_Mu6zVq_Va87Lb6DQ7tWa33q6wPfPqzWq70erWO41Wh4xXV81Thb06hXq1Vmu1LlvtRo18mq02eWAoaeKn-dfvfgKnP0nTN9U

Use my toolkit to inference my model and automate some Knowledge Graphs for your own needs.
https://github.com/Troys-Code/AI_Research/tree/main
-----

Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

### Instruction:
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.

### Input:
import argparse
import json
import os
import requests
import subprocess
import tempfile

class MermaidDiagramGenerator:
    def __init__(self, theme='dark', background='transparent'):
        self._theme = theme
        self._background = background
        self._entries_dir = os.path.join(os.getcwd(), 'Entries')
        os.makedirs(self._entries_dir, exist_ok=True)

    def convert_to_image(self, mermaid_code, entry_number, output_number):
        clean_code = self._remove_mermaid_block_markers(mermaid_code)
        output_filename = f"entry_{entry_number}_{output_number}.png"
        output_path = os.path.join(self._entries_dir, output_filename)
        self._generate_image_from_code(clean_code, output_path)
        return output_path

    def _remove_mermaid_block_markers(self, code):
        code_lines = code.strip().splitlines()
        if code_lines[0].startswith("```mermaid") and code_lines[-1] == "```":
            return "\n".join(code_lines[1:-1]).strip()
        return code

    def _generate_image_from_code(self, mermaid_code, output_path):
        with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.mmd') as temp_file:
            temp_file.write(mermaid_code)
            input_path = temp_file.name
        result = subprocess.run(["mmdc", "-i", input_path, "-o", output_path, "-t", self._theme, "-b", self._background], shell=True, check=False)
        os.remove(input_path)
        if result.returncode != 0:
            raise ValueError("Mermaid diagram generation failed.")

def read_input(input_source):
    if os.path.isfile(input_source):
        filename, file_extension = os.path.splitext(input_source)
        if file_extension == '.json':
            with open(input_source, 'r') as file:
                return json.load(file)
        elif file_extension == '.txt':
            with open(input_source, 'r') as file:
                return [{"input": file.read()}]
    else:
        return [{"input": input_source}]

def generate_response(prompt, base_temperatures, stream, generator, entry_number, unique_outputs):
    # prompt_template = f"{prompt}\n\n```mermaid\n"

    prompt_template = """
    Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
    
    ### Instruction:
    Create the mermaid diagram for the following input:

    ### Input:
    {input}
    
    ### Response:
    ```mermaid
    """.format(input=prompt)

    url = "http://127.0.0.1:5000/v1/completions"
    headers = {"Content-Type": "application/json"}
    dataset_entries = []

    for output_number, temp in enumerate(base_temperatures, start=1):
        while True:
            data = {
                "prompt": prompt_template,
                "max_tokens": 4096,
                "temperature": temp,
                "top_p": 1.0,
                "seed": -1,
                "top_k": 4,
                "repetition_penalty": 1.0,
                "guidance_scale": 1.0,
                "typical_p": 1.0,
                "stream": stream,
            }

            response = requests.post(url, headers=headers, json=data, verify=False)
            response_text = response.json()['choices'][0]['text'].strip()

            if response_text.endswith("```"):  # Check if response ends with ```
                response_text = response_text[:-3].strip()  # Remove ``` from the end

            if response_text not in unique_outputs:
                try:
                    image_path = generator.convert_to_image(response_text, entry_number, output_number)
                    print(f"Mermaid diagram generated at: {image_path}")
                    unique_outputs.add(response_text)
                    break
                except ValueError as e:
                    print(f"Validation failed, retrying... Error: {e}")
            else:
                temp += 0.1  # Adjust temperature if output is not unique

        dataset_entry = {
            "input": prompt,
            "output": f"```mermaid\n{response_text}\n```",
            "temperature": temp
        }
        dataset_entries.append(dataset_entry)

    return dataset_entries

def generate_unique_responses(input_data, base_temperatures, stream, generator):
    all_entries = []
    unique_outputs = set()

    for entry_number, entry in enumerate(input_data, start=1):
        prompt = entry.get("input", "")
        if prompt:
            entries = generate_response(prompt, base_temperatures, stream, generator, entry_number, unique_outputs)
            all_entries.extend(entries)  # Extend the list with new entries

    return all_entries

def main(input_source, stream=False):
    generator = MermaidDiagramGenerator()
    input_data = read_input(input_source)
    base_temperatures = [i / 10 for i in range(5, 11)]  # Adjusted for batch of unique outputs per input
    output_file = "output.json"

    all_entries = generate_unique_responses(input_data, base_temperatures, stream, generator)

    # Write all entries to the JSON file at once
    with open(output_file, "w") as f:
        json.dump(all_entries, f, indent=4)  # Dump the entire list of entries into the file

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Generate unique responses and validate Mermaid diagrams.")
    parser.add_argument('input_source', type=str, help='A multi-line string, path to a .txt file, or a .json file with prompts.')
    parser.add_argument('--stream', action='store_true', help='Use streaming responses.')
    args = parser.parse_args()
    
    main(args.input_source, args.stream)


### Response:
```mermaid
graph TB;


![Example Of More Advanced Prompting Of My Model Found here](https://huggingface.co/TroyDoesAI/MermaidMixtral-2x7b/raw/main/Advanced_Prompting_Mermaid.txt)