Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Add support for containerized Code execution, and utilities ( upload / download fn ). #459

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should double-check with @KillianLucas whether we want to start bringing in things like VSCode project-level settings before we commit any of them to the repo.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.analysis.typeCheckingMode": "basic"
}
40 changes: 33 additions & 7 deletions interpreter/__init__.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if you meant to make changes to this file?

Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
from .core.core import Interpreter
import sys
from .core.core import Interpreter
from .cli.cli import cli


# This is done so when users `import interpreter`,
# they get an instance of interpreter:

sys.modules["interpreter"] = Interpreter()
def create_interpreter(**kwargs):
"""
Factory function to create an instance of Interpreter with the provided keyword arguments.

Parameters:
**kwargs: Keyword arguments to be set as attributes in the Interpreter instance.

Returns:
An instance of Interpreter initialized with the provided arguments.
"""
# Create a new interpreter instance
new_interpreter = Interpreter()

# Iterate through the provided keyword arguments
for key, value in kwargs.items():
# Check if the attribute exists in the interpreter
if hasattr(new_interpreter, key):
# Check if the provided value is of the correct type
if isinstance(value, type(getattr(new_interpreter, key))):
setattr(new_interpreter, key, value)
else:
print(
f"Type mismatch: '{key}' should be of type {type(getattr(new_interpreter, key))}. Using the default value instead.")

else:
print(
f"Unknown attribute: '{key}'. Ignoring.")


return new_interpreter

# **This is a controversial thing to do,**
# because perhaps modules ought to behave like modules.

# But I think it saves a step, removes friction, and looks good.

# ____ ____ __ __
# / __ \____ ___ ____ / _/___ / /____ _________ ________ / /____ _____
Expand Down
12 changes: 11 additions & 1 deletion interpreter/cli/cli.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside of the new use_containers argument, I'm not sure about the changes in this file.

Maybe they were picked up in a rebase/merge or something?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did do it on purpose. the reasoning was because, if we return a instance when we import, we cant access other things in the package like the containerConfig ( DockerManager ) class. I figured may aswell do this factory fn since making it so that the interpreter class has more methods to get to the container config would be messy.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import appdirs
from ..utils.display_markdown_message import display_markdown_message
from ..terminal_interface.conversation_navigator import conversation_navigator
from ..core.core import Interpreter

arguments = [
{
Expand Down Expand Up @@ -75,6 +76,13 @@
"type": str
},
{
"name": "use_containers",
"nickname": "uc",
"help_text": "optionally use a Docker Container for the interpreters code execution. this will seperate execution from your main computer. this also allows execution on a remote server via the 'DOCKER_HOST' environment variable and the dockerengine api.",
"type": bool
},
{

"name": "safe_mode",
"nickname": "safe",
"help_text": "optionally enable safety mechanisms like code scanning; valid options are off, ask, and auto",
Expand All @@ -83,7 +91,7 @@
}
]

def cli(interpreter):
def cli():

parser = argparse.ArgumentParser(description="Open Interpreter")

Expand All @@ -108,6 +116,8 @@ def cli(interpreter):

args = parser.parse_args()

interpreter = Interpreter()

# This should be pushed into an open_config.py util
# If --config is used, open the config.yaml file in the Open Interpreter folder of the user's config dir
if args.config:
Expand Down
1 change: 1 addition & 0 deletions interpreter/code_interpreters/__init__.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be an editor automated formatting thing, too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was because of the init.py change. we just simply instanciate the interpreter in the function so we don't need to change the CLI entrypoint. everything functions identically to before.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading