Skip to content

Commit

Permalink
Enable streaming of code using new streamer of cmd execution and impr…
Browse files Browse the repository at this point in the history
…ove output so ENDOFTURN does better paneling
  • Loading branch information
pseudotensor committed Sep 11, 2024
1 parent 6d888ff commit 80f13eb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion openai_server/autogen_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ def __execute_code_dont_check_setup(self, code_blocks: List[CodeBlock]) -> Comma
exec_func = execute_cmd_stream
else:
exec_func = subprocess.run
from autogen.io import IOStream
iostream = IOStream.get_default()
result = exec_func(
cmd, cwd=self._work_dir, capture_output=True, text=True, timeout=float(self._timeout), env=env
cmd, cwd=self._work_dir, capture_output=True, text=True, timeout=float(self._timeout), env=env,
print_func=iostream.print,
)
iostream.print("\n\n**Completed execution of code blocks.**\n\nENDOFTURN\n\n")
except subprocess.TimeoutExpired:
logs_all += "\n" + TIMEOUT_MSG
# Same exit code as the timeout command on linux.
Expand Down
14 changes: 7 additions & 7 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ def start_process(cmd):


def execute_cmd_stream(cmd=None, script_content=None, cwd=None, env=None, timeout=None, capture_output=True,
text=True, print_tags=False, print_literal=True):
text=True, print_tags=False, print_literal=True, print_func=print):
if script_content is None and cmd is None:
raise ValueError("Either script_content or cmd must be provided")

Expand Down Expand Up @@ -2096,20 +2096,20 @@ def execute_cmd_stream(cmd=None, script_content=None, cwd=None, env=None, timeou
stdout_data.append(out_line)
if print_tags:
if out_line.strip(): # Only print if there's non-whitespace content
print(f"STDOUT: {out_line.strip()}")
print_func(f"STDOUT: {out_line.strip()}")
elif print_literal:
print(out_line, end='')
print_func(out_line, end='')
else:
print(out_line)
print_func(out_line)
if err_line:
stderr_data.append(err_line)
if print_tags:
if err_line.strip(): # Only print if there's non-whitespace content
print(f"STDERR: {err_line.strip()}")
print_func(f"STDERR: {err_line.strip()}")
elif print_literal:
print(err_line, end='')
print_func(err_line, end='')
else:
print(err_line)
print_func(err_line)

# Check for timeout
if timeout and time.time() - start_time > timeout:
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "a9b96271da9b770d1a46ab8d6dca8dc0eb68f43b"
__version__ = "6d888ff05456b6c663055bb66830f15519391fba"

0 comments on commit 80f13eb

Please sign in to comment.