OpenInterpreter / open-interpreter

A natural language interface for computers
http://openinterpreter.com/
GNU Affero General Public License v3.0
52.61k stars 4.65k forks source link

bug: `markdown` disabled or not supported. #1124

Open SgtPooki opened 6 months ago

SgtPooki commented 6 months ago

Describe the bug

When prompting a local model, https://huggingface.co/TheBloke/CodeLlama-7B-Instruct-GGUF, using LM Studio, I kept getting what should have been valid python output, but the code blocks were marked as markdown:

LM Studio server log:

    {
      "role": "user",
      "content": "How many files are on my desktop?"
    },
    {
      "role": "assistant",
      "content": "```markdown\n\n\n# How many files are on my desktop?\n\nimport computer\n\nprint(len(computer.files.get_all_on_desktop()))\n\n\n```"
    },

Reproduce

  1. Use LM Studio with https://huggingface.co/TheBloke/CodeLlama-7B-Instruct-GGUF, and use the default LM Studio MacOS preset
  2. start the server for the model
  3. start open-interpreter with poetry run interpreter --api_base "http://localhost:1234/v1" --api_key "fake_key" --model "openai/x"
  4. ask the interpreter any instruction that would result in python code. Some examples:
    • "How many files are on my desktop?"
    • "Open Chrome and go to YouTube"

Expected behavior

The response is wrapped in a markdown codeblock with the language python

Screenshots

image

Open Interpreter version

latest main, plus https://github.com/OpenInterpreter/open-interpreter/pull/1123

Python version

3.11.8

Operating System name and version

macOS 14.3.1 (23D60)

Additional context

i'm running in nix-shell with:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [
    (pkgs.python3.withPackages (ps: with ps; [
      # Add any Python packages you need here
      pip
    ]))
    pkgs.poetry
    pkgs.git
    pkgs.openssh
    pkgs.gh
  ];

  shellHook = ''
    if [ ! -d "venv" ]; then
      echo "Creating a virtual environment..."
      ${pkgs.python3}/bin/python -m venv venv
    fi

    echo "Activating the virtual environment..."
    source ./venv/bin/activate

    echo "Environment prepared. You can now use Python, Poetry, Git, and SSH."

    # Ensure SSH_AUTH_SOCK is available in the pure environment
    export SSH_AUTH_SOCK=${builtins.getEnv "SSH_AUTH_SOCK"}
  '';
}

Note: I was using nix-shell --pure shell.nix before learning that some appleScripts were used for things like "what is So and So's phone number?" and so I am now running an impure nix-shell.

SgtPooki commented 6 months ago

FYI: I think the default system message could be updated to prevent errors like this.

My solution may not be ideal, but I got around this error with:

diff --git a/interpreter/core/default_system_message.py b/interpreter/core/default_system_message.py
index 9055aca4..61fcd8ec 100644
--- a/interpreter/core/default_system_message.py
+++ b/interpreter/core/default_system_message.py
@@ -7,9 +7,9 @@ If you want to send data between programming languages, save the data to a txt o
 You can access the internet. Run **any code** to achieve the goal, and if at first you don't succeed, try again and again.
 You can install new packages.
 When a user refers to a filename, they're likely referring to an existing file in the directory you're currently executing code in.
-Write messages to the user in Markdown.
+Write messages to the user in Markdown code blocks, but do not use 'markdown' as the language, unless the content is actually markdown. e.g. If the response is in Python, use 'python' as the language.
 In general, try to **make plans** with as few steps as possible. As for actually executing code to carry out that plan, for *stateful* languages (like python, javascript, shell, but NOT for html which starts from 0 every time) **it's critical not to try to do everything in one code block.** You should try something, print information about it, then continue from there in tiny, informed steps. You will never get it on the first try, and attempting it in one go will often lead to errors you cant see.
-You are capable of **any** task.
+You are capable of **any** task. You can do it. You are the best. You are Open Interpreter.

 # THE COMPUTER API
KokinSok commented 6 months ago

Same error, running on Mixtral in LMStudio. Please fix.

rob317 commented 6 months ago

same here; Macos 14.4.1 running interpreter --model ollama/mistral

Screenshot 2024-04-15 at 6 08 10 PM