Skip to content

Commit

Permalink
Added interpreter.forbidden_commands
Browse files Browse the repository at this point in the history
`interpreter.forbidden_commands` is a list of commands disallowed by default.
  • Loading branch information
KillianLucas committed Jul 24, 2023
1 parent 761115c commit 1ed6100
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 268 deletions.
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
# Open Interpreter

A lightweight, open-source implementation of OpenAI's code interpreter.
A minimal, open-source implementation of OpenAI's code interpreter.

```python
interpreter.chat('Hey, can you add subtitles to video.mp4 on my Desktop?')
```
```
Absolutely. First, let's check if any speech-to-text libraries are installed...
```

<br>

![Banner Image](https://i.ibb.co/ZHfB9sm/open-interpreter-banner.png)

<p align="right">
<sub><i>Illustration by Open Interpreter. Inspired by <a href="https://rubywjchen.com/">Ruby Chen's</a> GPT-4 artwork.</i></sub>
</p>
![Interpreter Demo](https://github.com/KillianLucas/open-interpreter/assets/63927363/a1597f66-d298-4172-bc0b-35b36e1479eb)

## What is this?

Expand Down Expand Up @@ -157,13 +144,17 @@ We then stream the model's messages, code, and your system's outputs to the term

Only the last `model_max_tokens` of the conversation are shown to the model, so conversations can be any length, but older messages may be forgotten.

Sure, here's an updated version:

## Safety Notice

Since generated code is executed in your local environment, it can interact with your files and system settings, potentially leading to unexpected outcomes like data loss or security risks.

- Be cautious when requesting commands that modify files or system settings.
- Watch Open Interpreter like a self-driving car, and be prepared to end the process by closing your terminal.
- Regularly back up your data and work in a virtual environment.
- Open Interpreter utilizes `interpreter.forbidden_commands`, a list of commands identified as potentially harmful and disallowed by default. You can modify this list, but do so with caution.
- Consider running the Open Interpreter in a restricted environment like Google Colab or Replit. These environments are more isolated, reducing the risks associated with executing arbitrary code.

## Contributing

Expand All @@ -174,3 +165,9 @@ As an open-source project, we are extremely open to contributions, whether it be
Open Interpreter is licensed under the MIT License. You are permitted to use, copy, modify, distribute, sublicense and sell copies of the software.

**Note**: This software is not affiliated with OpenAI.

![Banner Image](https://i.ibb.co/ZHfB9sm/open-interpreter-banner.png)

<p align="right">
<sub><i>Illustration by Open Interpreter. Inspired by <a href="https://rubywjchen.com/">Ruby Chen's</a> GPT-4 artwork.</i></sub>
</p>
14 changes: 13 additions & 1 deletion interpreter/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def flush(self):
def isatty(self):
return False

def exec_and_capture_output(code, max_output_chars):
def exec_and_capture_output(code, max_output_chars, forbidden_commands):
# Store the original stdout and stderr
old_stdout = sys.stdout
old_stderr = sys.stderr
Expand Down Expand Up @@ -117,6 +117,18 @@ def custom_showtraceback(*args, **kwargs):

return rich_stdout.data.strip()

# Check for forbidden_commands
lines = code.split('\n')
for line in lines:
if line.strip() in forbidden_commands:
message = f"Command '{line}' is not permitted. Modify `interpreter.forbidden_commands` to override."
rich_stdout.write(message)

live.refresh() # Sometimes this can happen so quickly, it doesn't auto refresh in time
shell.ast_node_interactivity = "last_expr_or_assign" # Restore last

return rich_stdout.data.strip()

# If syntax is correct, execute the code
with redirect_stdout(rich_stdout), redirect_stderr(rich_stdout), live:
shell.run_cell(code)
Expand Down
Loading

0 comments on commit 1ed6100

Please sign in to comment.