You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from .baseimportCodeBlock, CodeExtractor, CodeResult
11
+
from .baseimportCodeBlock, CodeExecutor, CodeExtractor, CodeResult
11
12
from .markdown_code_extractorimportMarkdownCodeExtractor
12
13
13
14
__all__= (
@@ -25,33 +26,7 @@ class CommandLineCodeResult(CodeResult):
25
26
)
26
27
27
28
28
-
classLocalCommandLineCodeExecutor(BaseModel):
29
-
"""(Experimental) A code executor class that executes code through a local command line
30
-
environment.
31
-
32
-
**This will execute LLM generated code on the local machine.**
33
-
34
-
Each code block is saved as a file and executed in a separate process in
35
-
the working directory, and a unique file is generated and saved in the
36
-
working directory for each code block.
37
-
The code blocks are executed in the order they are received.
38
-
Command line code is sanitized using regular expression match against a list of dangerous commands in order to prevent self-destructive
39
-
commands from being executed which may potentially affect the users environment.
40
-
Currently the only supported languages is Python and shell scripts.
41
-
For Python code, use the language "python" for the code block.
42
-
For shell scripts, use the language "bash", "shell", or "sh" for the code
43
-
block.
44
-
45
-
Args:
46
-
timeout (int): The timeout for code execution. Default is 60.
47
-
work_dir (str): The working directory for the code execution. If None,
48
-
a default working directory will be used. The default working
49
-
directory is the current directory ".".
50
-
system_message_update (str): The system message update for agent that
51
-
produces code to run on this executor.
52
-
Default is `LocalCommandLineCodeExecutor.DEFAULT_SYSTEM_MESSAGE_UPDATE`.
53
-
"""
54
-
29
+
classLocalCommandLineCodeExecutor(CodeExecutor):
55
30
DEFAULT_SYSTEM_MESSAGE_UPDATE: ClassVar[
56
31
str
57
32
] ="""
@@ -64,12 +39,51 @@ class LocalCommandLineCodeExecutor(BaseModel):
64
39
If you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user.
65
40
"""
66
41
67
-
timeout: int=Field(default=60, ge=1, description="The timeout for code execution.")
68
-
work_dir: str=Field(default=".", description="The working directory for the code execution.")
69
-
system_message_update: str=Field(
70
-
default=DEFAULT_SYSTEM_MESSAGE_UPDATE,
71
-
description="The system message update for agent that produces code to run on this executor.",
0 commit comments