Skip to content

Commit

Permalink
Local III 0.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Jun 30, 2024
1 parent 8ad54e9 commit 58d5727
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
60 changes: 60 additions & 0 deletions interpreter/terminal_interface/profiles/defaults/e2b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
This is an Open Interpreter profile.
"""

import e2b

from interpreter import interpreter


class PythonE2B:
"""
This class contains all requirements for being a custom language in Open Interpreter:
- name (an attribute)
- run (a method)
- stop (a method)
- terminate (a method)
Here, we'll use E2B to power the `run` method.
"""

# This is the name that will appear to the LLM.
name = "python"

# Optionally, you can append some information about this language to the system message:
system_message = "# Follow this rule: Every Python code block MUST contain at least one print statement."

# (E2B isn't a Jupyter Notebook, so we added ^ this so it would print things,
# instead of putting variables at the end of code blocks, which is a Jupyter thing.)

def run(self, code):
"""Generator that yields a dictionary in LMC Format."""

# Run the code on E2B
stdout, stderr = e2b.run_code("Python3", code)

# Yield the output
yield {
"type": "console",
"format": "output",
"content": stdout
+ stderr, # We combined these arbitrarily. Yield anything you'd like!
}

def stop(self):
"""Stops the code."""
# Not needed here, because e2b.run_code isn't stateful.
pass

def terminate(self):
"""Terminates the entire process."""
# Not needed here, because e2b.run_code isn't stateful.
pass


# (Tip: Do this before adding/removing languages, otherwise OI might retain the state of previous languages:)
interpreter.computer.terminate()

# Give Open Interpreter its languages. This will only let it run PythonE2B:
interpreter.computer.languages = [PythonE2B]
46 changes: 46 additions & 0 deletions interpreter/terminal_interface/profiles/defaults/gemma2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
This is an Open Interpreter profile. It configures Open Interpreter to run `gemma2` using Ollama.
"""

from interpreter import interpreter

interpreter.system_message = """You are an AI assistant that writes tiny markdown code snippets to answer the user's request. You speak very concisely and quickly, you say nothing irrelevant to the user's request. For example:
User: Open the chrome app.
Assistant: On it.
```python
import webbrowser
webbrowser.open('https://chrome.google.com')
```
User: The code you ran produced no output. Was this expected, or are we finished?
Assistant: No further action is required; the provided snippet opens Chrome.
Now, your turn:""".strip()

# Message templates
interpreter.code_output_template = """I executed that code. This was the output: \n\n{content}\n\nWhat does this output mean? I can't understand it, please help / what code needs to be run next (if anything, or are we done with my query)?"""
interpreter.empty_code_output_template = "I executed your code snippet. It produced no text output. What's next (if anything, or are we done?)"
interpreter.user_message_template = (
"Write a ```python code snippet that would answer this query: `{content}`"
)
interpreter.code_output_sender = "user"

# LLM settings
interpreter.llm.model = "ollama/gemma2"
interpreter.llm.supports_functions = False
interpreter.llm.execution_instructions = False
interpreter.llm.max_tokens = 1000
interpreter.llm.context_window = 7000
interpreter.llm.load() # Loads Ollama models

# Computer settings
interpreter.computer.import_computer_api = False

# Misc settings
interpreter.auto_run = True
interpreter.offline = True

# Final message
interpreter.display_message(
"> Model set to `gemma2`\n\n**Open Interpreter** will require approval before running code.\n\nUse `interpreter -y` to bypass this.\n\nPress `CTRL-C` to exit.\n"
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "open-interpreter"
packages = [
{include = "interpreter"},
]
version = "0.3.3" # Use "-rc1", "-rc2", etc. for pre-release versions
version = "0.3.4" # Use "-rc1", "-rc2", etc. for pre-release versions
description = "Let language models run code"
authors = ["Killian Lucas <killian@openinterpreter.com>"]
readme = "README.md"
Expand Down

0 comments on commit 58d5727

Please sign in to comment.