Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into to-overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
unaidedelf8777 committed Oct 5, 2023
2 parents 03fb194 + 61a38c3 commit 2e1f7bf
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 66 deletions.
19 changes: 0 additions & 19 deletions .vscode/launch.json

This file was deleted.

13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<h1 align="center">● Open Interpreter</h1>

![banner 2](https://github.com/KillianLucas/open-interpreter/assets/63927363/c1aec011-6d3c-4960-ab55-749326b8a7c9)

<p align="center">
<a href="https://discord.gg/6p3fD6rBVm">
<img alt="Discord" src="https://img.shields.io/discord/1146610656779440188?logo=discord&style=flat&logoColor=white"/>
</a>
<a href="README_JA.md"><img src="https://img.shields.io/badge/ドキュメント-日本語-white.svg" alt="JA doc"/></a>
<a href="README_ZH.md"><img src="https://img.shields.io/badge/文档-中文版-white.svg" alt="ZH doc"/></a>
<a href="README_IN.md"><img src="https://img.shields.io/badge/Document-Hindi-white.svg" alt="IN doc"/></a>
<a href="README_IN.md"><img src="https://img.shields.io/badge/Hindi-white.svg" alt="IN doc"/></a>
<img src="https://img.shields.io/static/v1?label=license&message=MIT&color=white&style=flat" alt="License"/>
<br><br>
<b>Let language models run code on your computer.</b><br>
<b>Open Interpreter</b> lets language models run code on your computer.<br>
An open-source, locally running implementation of OpenAI's Code Interpreter.<br>
<br><a href="https://openinterpreter.com">Get early access to the desktop application.</a><br>
<br><a href="https://openinterpreter.com">Get early access to the desktop app</a>‎ ‎ |‎ ‎ <b><a href="https://docs.openinterpreter.com/">Read our new docs</a></b><br>
</p>

<br>

![poster](https://github.com/KillianLucas/open-interpreter/assets/63927363/08f0d493-956b-4d49-982e-67d4b20c4b56)

<br>

```shell
pip install open-interpreter
```
Expand Down
26 changes: 16 additions & 10 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<br>
<br>
<b>让语言模型在您的计算机上运行代码。</b><br>
在本地实现开源的OpenAI的代码解释器。<br>
在本地实现的开源OpenAI的代码解释器。<br>
<br><a href="https://openinterpreter.com">登记以提前获取Open Interpreter(开放解释器)桌面应用程序</a><br>
</p>

Expand Down Expand Up @@ -57,7 +57,7 @@ pip install open-interpreter

### 终端

安装后,简单地运行 `interpreter`
安装后,运行 `interpreter`

```shell
interpreter
Expand Down Expand Up @@ -151,10 +151,14 @@ print(interpreter.system_message)

### 更改模型

`gpt-3.5-turbo` 下,使用快速模式:
Open Interpreter使用[LiteLLM](https://docs.litellm.ai/docs/providers/)连接到语言模型。

您可以通过设置模型参数来更改模型:

```shell
interpreter --fast
interpreter --model gpt-3.5-turbo
interpreter --model claude-2
interpreter --model command-nightly
```

在 Python 环境下,您需要手动设置模型:
Expand Down Expand Up @@ -202,12 +206,14 @@ interpreter.azure_api_type = "azure"

为了帮助贡献者检查和调试 Open Interpreter,`--debug` 模式提供了详细的日志。

您可以使用 `interpreter --debug` 来激活调试模式,或者直接在聊天时输入
您可以使用 `interpreter --debug` 来激活调试模式,或者直接在终端输入

```shell
$ interpreter
...
> %debug # <- 开启调试模式
> %debug true <- 开启调试模式

> %debug false <- 关闭调试模式
```

### 使用 .env 配置
Expand All @@ -230,13 +236,13 @@ INTERPRETER_CLI_USE_AZURE=False

由于生成的代码是在本地环境中运行的,因此会与文件和系统设置发生交互,从而可能导致本地数据丢失或安全风险等意想不到的结果。

**⚠️ 所以在执行任何代码之前,Open Interpreter 都会要求用户确认是否运行**
**⚠️ 所以在执行任何代码之前,Open Interpreter 都会询问用户是否运行**

您可以运行 `interpreter -y` 或设置 `interpreter.auto_run = True` 来绕过此确认,此时:

- 在运行请求修改本地文件或系统设置的命令时要谨慎。
- 请像驾驶自动驾驶汽车一样留意 Open Interpreter,并随时做好通过关闭终端来结束进程的准备。
- 考虑在 Google Colab 或 Replit 等受限环境中运行 Open Interpreter。主要是这些环境更加独立,从而降低执行任意代码导致出现问题的风险。
- 请像驾驶自动驾驶汽车一直握着方向盘一样留意 Open Interpreter,并随时做好通过关闭终端来结束进程的准备。
- 考虑在 Google Colab 或 Replit 等受限环境中运行 Open Interpreter的主要原因是这些环境更加独立,从而降低执行任意代码导致出现问题的风险。

## 它是如何工作的?

Expand All @@ -258,6 +264,6 @@ Open Interpreter 采用 MIT 许可授权。您可以使用、复制、修改、

> 拥有一个像您的指尖一样快速工作的初级程序员...可以使新的工作流程变得轻松高效,同时也能让新的受众群体享受到编程的好处。
>
> _OpenAI 的代码解释器发布_
> _OpenAI 的代码解释器发布宣传语_
<br>
5 changes: 4 additions & 1 deletion interpreter/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def cli():
if arg["type"] == bool:
parser.add_argument(f'-{arg["nickname"]}', f'--{arg["name"]}', dest=arg["name"], help=arg["help_text"], action='store_true', default=None)
else:
parser.add_argument(f'-{arg["nickname"]}', f'--{arg["name"]}', dest=arg["name"], help=arg["help_text"], type=arg["type"])
choices = arg["choices"] if "choices" in arg else None
default = arg["default"] if "default" in arg else None

parser.add_argument(f'-{arg["nickname"]}', f'--{arg["name"]}', dest=arg["name"], help=arg["help_text"], type=arg["type"], choices=choices, default=default)

# Add special arguments
parser.add_argument('--config', dest='config', action='store_true', help='open config.yaml file in text editor')
Expand Down
7 changes: 7 additions & 0 deletions interpreter/code_interpreters/create_code_interpreter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
import inspect
import os
import uuid
Expand All @@ -7,6 +8,9 @@
from .language_map import language_map


=======
from .language_map import language_map
>>>>>>> upstream/main

# Global dictionary to store the session IDs by the weak reference of the calling objects
SESSION_IDS_BY_OBJECT = weakref.WeakKeyDictionary()
Expand Down Expand Up @@ -40,6 +44,7 @@ def create_code_interpreter(language, use_containers=False):
# Case in-sensitive
language = language.lower()

<<<<<<< HEAD
caller_object = None

if use_containers:
Expand Down Expand Up @@ -72,6 +77,8 @@ def create_code_interpreter(language, use_containers=False):
session_id = f"ses-{str(uuid.uuid4())}"
SESSION_IDS_BY_OBJECT[caller_object] = session_id

=======
>>>>>>> upstream/main
try:
# Retrieve the specific CodeInterpreter class based on the language
CodeInterpreter = language_map[language]
Expand Down
8 changes: 8 additions & 0 deletions interpreter/code_interpreters/languages/applescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
from ..subprocess_code_interpreter import SubprocessCodeInterpreter

class AppleScript(SubprocessCodeInterpreter):
<<<<<<< HEAD

file_extension = "applescript"
proper_name = "AppleScript"

def __init__(self, **kwargs):
super().__init__(**kwargs)

=======
file_extension = "applescript"
proper_name = "AppleScript"

def __init__(self):
super().__init__()
>>>>>>> upstream/main
self.start_cmd = os.environ.get('SHELL', '/bin/zsh')

def preprocess_code(self, code):
Expand Down
5 changes: 5 additions & 0 deletions interpreter/code_interpreters/languages/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ class HTML(BaseCodeInterpreter):
file_extension = "html"
proper_name = "HTML"

<<<<<<< HEAD
def __init__(self, **kwargs):
super().__init__(**kwargs) # include kwargs though they dont do anything in this case.
# This is just so we dont need more logic in the create interpreter function
=======
def __init__(self):
super().__init__()
>>>>>>> upstream/main

def run(self, code):
# Create a temporary HTML file with the content
Expand Down
8 changes: 8 additions & 0 deletions interpreter/code_interpreters/languages/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
import re

class JavaScript(SubprocessCodeInterpreter):
<<<<<<< HEAD

file_extension = "js"
proper_name = "JavaScript"

def __init__(self, **kwargs):
super().__init__(**kwargs)

=======
file_extension = "js"
proper_name = "JavaScript"

def __init__(self):
super().__init__()
>>>>>>> upstream/main
self.start_cmd = "node -i"

def preprocess_code(self, code):
Expand Down
9 changes: 9 additions & 0 deletions interpreter/code_interpreters/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re

class Python(SubprocessCodeInterpreter):
<<<<<<< HEAD

file_extension = "py"
proper_name = "Python"
Expand All @@ -14,6 +15,14 @@ def __init__(self, **kwargs):
self.start_cmd = "python3 -i -q -u"
else:
self.start_cmd = sys.executable + " -i -q -u"
=======
file_extension = "py"
proper_name = "Python"

def __init__(self):
super().__init__()
self.start_cmd = sys.executable + " -i -q -u"
>>>>>>> upstream/main

def preprocess_code(self, code):
return preprocess_python(code)
Expand Down
8 changes: 8 additions & 0 deletions interpreter/code_interpreters/languages/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
import re

class R(SubprocessCodeInterpreter):
<<<<<<< HEAD


file_extension = "r"
proper_name = "R"

def __init__(self, **kwargs):
super().__init__(**kwargs)
=======
file_extension = "r"
proper_name = "R"

def __init__(self):
super().__init__()
>>>>>>> upstream/main
self.start_cmd = "R -q --vanilla" # Start R in quiet and vanilla mode

def preprocess_code(self, code):
Expand Down
8 changes: 8 additions & 0 deletions interpreter/code_interpreters/languages/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
import os

class Shell(SubprocessCodeInterpreter):
<<<<<<< HEAD

file_extension = "sh"
proper_name = "Shell"
=======
file_extension = "sh"
proper_name = "Shell"

def __init__(self):
super().__init__()
>>>>>>> upstream/main

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down
2 changes: 0 additions & 2 deletions interpreter/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,10 @@ def _streaming_chat(self, message=None, display=True):
if not os.path.exists(self.conversation_history_path):
os.makedirs(self.conversation_history_path)
# Write or overwrite the file

with open(os.path.join(self.conversation_history_path, self.conversation_filename), 'w') as f:
json.dump(self.messages, f)

return

raise Exception("`interpreter.chat()` requires a display. Set `display=True` or pass a message into `interpreter.chat(message)`.")

def _respond(self):
Expand Down
2 changes: 1 addition & 1 deletion interpreter/llm/setup_local_text_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup_local_text_llm(interpreter):
DEFAULT_CONTEXT_WINDOW = 2000
DEFAULT_MAX_TOKENS = 1000

repo_id = interpreter.model.split("huggingface/")[1]
repo_id = interpreter.model.replace("huggingface/", "")

if "TheBloke/CodeLlama-" not in repo_id:
# ^ This means it was prob through the old --local, so we have already displayed this message.
Expand Down
6 changes: 3 additions & 3 deletions interpreter/terminal_interface/terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def terminal_interface(interpreter, message):

should_scan_code = False

if not interpreter.scan_code == "off":
if interpreter.scan_code == "auto":
if not interpreter.safe_mode == "off":
if interpreter.safe_mode == "auto":
should_scan_code = True
elif interpreter.scan_code == 'ask':
elif interpreter.safe_mode == 'ask':
response = input(" Would you like to scan this code? (y/n)\n\n ")
print("") # <- Aesthetic choice

Expand Down
13 changes: 8 additions & 5 deletions interpreter/utils/scan_code.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import subprocess
from yaspin import yaspin
from yaspin.spinners import Spinners

from .temporary_file import create_temporary_file, cleanup_temporary_file
from ..code_interpreters.language_map import language_map
Expand Down Expand Up @@ -52,15 +54,16 @@ def scan_code(code, language, interpreter):
# pinned to an old semgrep version that has issues with reading the semgrep registry
# while scanning a single file like the temporary one we generate
# if guarddog solves [#249](https://github.com/DataDog/guarddog/issues/249) we can change this approach a bit
scan = subprocess.run(
f"cd {temp_path} && semgrep scan --config auto --quiet --error {file_name}",
shell=True,
)
with yaspin(text=" Scanning code...").green.right.binary as loading:
scan = subprocess.run(
f"cd {temp_path} && semgrep scan --config auto --quiet --error {file_name}",
shell=True,
)

if scan.returncode == 0:
language_name = get_language_proper_name(language)
print(
f" {'Code Scaner: ' if interpreter.safe_mode == 'auto' else ''}No issues were found in this {language_name} code."
f" {'Code Scaner: ' if interpreter.safe_mode == 'auto' else ''} No issues were found in this {language_name} code."
)
print("")

Expand Down
Loading

0 comments on commit 2e1f7bf

Please sign in to comment.