Skip to content

Commit

Permalink
typo in interpreter/code_interpreters/languages/python.py
Browse files Browse the repository at this point in the history
  • Loading branch information
unaidedelf8777 committed Oct 21, 2023
1 parent 295ddfa commit 8884506
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion interpreter/code_interpreters/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Python(SubprocessCodeInterpreter):

def __init__(self, **kwargs):
super().__init__(**kwargs)
if 'use_docker' in kwargs and kwargs['use_docker']:
if 'use_containers' in kwargs and kwargs['use_containers']:
self.start_cmd = "python3 -i -q -u"
else:
executable = sys.executable
Expand Down
45 changes: 45 additions & 0 deletions interpreter/llm/get_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Function to enable / disable different lang based on operating system. """
import platform
import copy

BASE_FUNCTION_SCHEMA = {
"name": "execute",
"description":
"Executes code on the user's machine, **in the users local environment**, and returns the output",
"parameters": {
"type": "object",
"properties": {
"language": {
"type": "string",
"description":
"The programming language (required parameter to the `execute` function)",
"enum": ["python", "R", "shell", "javascript", "html",]
},
"code": {
"type": "string",
"description": "The code to execute (required)"
}
},
"required": ["language", "code"]
},
}

def get_schema():
# Detect the operating system
os_type = platform.system().lower()

# Define the base languages that are common to all supported operating systems
base_languages = ["python", "R", "shell", "javascript", "html"]

# Copy the schema to avoid modifying the original
corrected_schema = copy.deepcopy(BASE_FUNCTION_SCHEMA)

# Add 'powershell' if the OS is Windows, 'applescript' if macOS, or none if it's another OS
if os_type == 'windows':
base_languages.append('powershell')
elif os_type == 'darwin': # Darwin is the system name for macOS
base_languages.append('applescript')

corrected_schema['parameters']['properties']['language']['enum'] = base_languages

return corrected_schema
27 changes: 3 additions & 24 deletions interpreter/llm/setup_openai_coding_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,10 @@
from ..utils.parse_partial_json import parse_partial_json
from ..utils.convert_to_openai_messages import convert_to_openai_messages
from ..utils.display_markdown_message import display_markdown_message
from .get_schema import get_schema
import tokentrim as tt


function_schema = {
"name": "execute",
"description":
"Executes code on the user's machine, **in the users local environment**, and returns the output",
"parameters": {
"type": "object",
"properties": {
"language": {
"type": "string",
"description":
"The programming language (required parameter to the `execute` function)",
"enum": ["python", "R", "shell", "applescript", "javascript", "html", "powershell"]
},
"code": {
"type": "string",
"description": "The code to execute (required)"
}
},
"required": ["language", "code"]
},
}

def setup_openai_coding_llm(interpreter):
"""
Takes an Interpreter (which includes a ton of LLM settings),
Expand Down Expand Up @@ -68,7 +47,7 @@ def coding_llm(messages):
'model': interpreter.model,
'messages': messages,
'stream': True,
'functions': [function_schema]
'functions': [get_schema()]
}

# Optional inputs
Expand Down Expand Up @@ -135,4 +114,4 @@ def coding_llm(messages):
if code_delta:
yield {"code": code_delta}

return coding_llm
return coding_llm

0 comments on commit 8884506

Please sign in to comment.