Skip to content

[BUG] <title>LLM Generates Inconsistent and Mixed Content Types in Response </title> #1345

Open
@TheChii

Description

Description

When providing a specific prompt to the LLM, the response includes multiple types of content (JSON, XML, plain text, HTML, Markdown, and shell script) in a single output, which is not expected.

Steps to Reproduce

  1. Open the LLM interface.

  2. Provide the following prompt:
    document.addEventListener('DOMContentLoaded', () => {
    const editorContainer = document.querySelector('.editor-content');
    // Load tabs and editors from localStorage
    let tabsData = JSON.parse(localStorage.getItem('tabs')) || [
    { index: 0, content: '' }
    ];
    let tabIndex = tabsData.length - 1;

    function createNewTab() {
    tabIndex++;
    const newTab = document.createElement('button');
    newTab.className = 'tab';
    newTab.textContent = Tab ${tabIndex + 1};
    newTab.setAttribute('data-index', tabIndex);

     const addTabButton = document.querySelector('.add-tab');
     addTabButton.before(newTab);
    
     const newLineNumberContainer = document.createElement('div');
     newLineNumberContainer.className = 'line-numbers hidden';
     newLineNumberContainer.id = `lineNumbers${tabIndex}`;
     editorContainer.appendChild(newLineNumberContainer);
    
     const newCodeEditor = document.createElement('textarea');
     newCodeEditor.className = 'code-editor hidden';
     newCodeEditor.id = `codeEditor${tabIndex}`;
     newCodeEditor.placeholder = 'Start typing your code here...';
     editorContainer.appendChild(newCodeEditor);
    
     return { newTab, newLineNumberContainer, newCodeEditor };
    

    }

    function updateLineNumbers(index) {
    const editor = document.getElementById(codeEditor${index});
    const lines = editor.value.split('\n').length;
    let lineNumbersHTML = '';

     for (let i = 1; i <= lines; i++) {
         lineNumbersHTML += `<span>${i}</span><br>`;
     }
    
     document.getElementById(`lineNumbers${index}`).innerHTML = lineNumbersHTML;
    

    }

    function setActiveTab(tabIndex) {
    // Hide all editors and line numbers
    document.querySelectorAll('.code-editor').forEach(editor => editor.classList.add('hidden'));
    document.querySelectorAll('.line-numbers').forEach(lineNumbers => lineNumbers.classList.add('hidden'));

     // Show the selected editor and line numbers
     const activeEditor = document.getElementById(`codeEditor${tabIndex}`);
     const activeLineNumbers = document.getElementById(`lineNumbers${tabIndex}`);
    
     if (activeEditor && activeLineNumbers) {
         activeEditor.classList.remove('hidden');
         activeLineNumbers.classList.remove('hidden');
    
         // Update line numbers for the active editor
         updateLineNumbers(tabIndex);
     }
    
     // Update active tab styling
     document.querySelectorAll('.tab').forEach(tab => tab.classList.remove('active'));
     document.querySelector(`.tab[data-index="${tabIndex}"]`).classList.add('active');
    

    }

    document.querySelector('.tabs').addEventListener('click', (event) => {
    if (event.target.classList.contains('tab')) {
    const tabIndex = parseInt(event.target.getAttribute('data-index'), 10);
    setActiveTab(tabIndex);
    }
    });

    // Initial call to set up the first tab
    setActiveTab(tabsData[0].index);

    // Add new tab functionality
    const addTabButton = document.querySelector('.add-tab');
    addTabButton.addEventListener('click', () => {
    const { newTab, newLineNumberContainer, newCodeEditor } = createNewTab();

     // Set up event listeners for the new tab
     newTab.addEventListener('click', () => {
         const newIndex = parseInt(newTab.getAttribute('data-index'), 10);
         setActiveTab(newIndex);
     });
    
     newCodeEditor.addEventListener('input', () => {
         updateLineNumbers(tabIndex);
         saveTabsState();
     });
    
     // Activate the new tab immediately after adding it
     setActiveTab(tabIndex);
     saveTabsState();
    

    });

    // Run button functionality
    const runButton = document.querySelector('.run-button');
    runButton.addEventListener('click', () => {
    const activeTabIndex = parseInt(document.querySelector('.tab.active').getAttribute('data-index'), 10);
    const activeEditor = document.getElementById(codeEditor${activeTabIndex});
    const codeContent = activeEditor.value;

     try {
         // Open the code in a new browser tab
         const newTab = window.open();
         newTab.document.open();
         newTab.document.write(codeContent);
         newTab.document.close();
     } catch (error) {
         console.error("Error running code:", error);
     }
    

    });

    // Save tabs state on input change
    document.querySelectorAll('.code-editor').forEach(editor => {
    editor.addEventListener('input', () => {
    saveTabsState();
    });
    });

    // Save tabs state when the window is about to be unloaded
    window.addEventListener('beforeunload', () => {
    saveTabsState();
    });
    });

Expected Behavior

The LLM should generate a single, coherent response that matches the input prompt, such as a properly formatted JavaScript code snippet or an explanation related to the provided code.

Actual Behavior

The LLM generates a response that includes multiple types of content, such as:

json
y
{
"message": "Your JSON response has been successfully generated!",
"status": "success"
}
xml

Your XML response has been successfully generated! success Run HTML

Your plain text response has been successfully generated!
html

<title>Response</title>

Your HTML response has been successfully generated!

Run HTML markdown # Your Markdown response has been successfully generated! bash echo "Your shell script response has been successfully generated!"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions