-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ad54e9
commit 58d5727
Showing
3 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
interpreter/terminal_interface/profiles/defaults/gemma2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters