Former-commit-id: 9b35b43054
huggingface
Kye 1 year ago
parent f5c10eb36c
commit 3337ba4d04

@ -422,54 +422,54 @@ class ToolsFactory:
################## => stdout end ################## => stdout end
# import os import os
# import subprocess import subprocess
# import time import time
# from datetime import datetime from datetime import datetime
# from typing import Dict, List from typing import Dict, List
# from swarms.utils.main import ANSI, Color, Style # test from swarms.utils.main import ANSI, Color, Style # test
# class Terminal(BaseToolSet): class Terminal(BaseToolSet):
# def __init__(self): def __init__(self):
# self.sessions: Dict[str, List[SyscallTracer]] = {} self.sessions: Dict[str, List[SyscallTracer]] = {}
# @tool( @tool(
# name="Terminal", name="Terminal",
# description="Executes commands in a terminal." description="Executes commands in a terminal."
# "If linux errno occurs, we have to solve the problem with the terminal. " "If linux errno occurs, we have to solve the problem with the terminal. "
# "Input must be one valid command. " "Input must be one valid command. "
# "Output will be any output from running that command.", "Output will be any output from running that command.",
# scope=ToolScope.SESSION, scope=ToolScope.SESSION,
# ) )
# def execute(self, commands: str, get_session: SessionGetter) -> str: def execute(self, commands: str, get_session: SessionGetter) -> str:
# session, _ = get_session() session, _ = get_session()
# try: try:
# process = subprocess.Popen( process = subprocess.Popen(
# commands, commands,
# shell=True, shell=True,
# stdout=subprocess.PIPE, stdout=subprocess.PIPE,
# stderr=subprocess.PIPE, stderr=subprocess.PIPE,
# ) )
# logger.info(ANSI("Realtime Terminal Output").to(Color.magenta()) + ": ") logger.info(ANSI("Realtime Terminal Output").to(Color.magenta()) + ": ")
# output = "" output = ""
# tracer = StdoutTracer( tracer = StdoutTracer(
# process, process,
# on_output=lambda p, o: logger.info( on_output=lambda p, o: logger.info(
# ANSI(p).to(Style.dim()) + " " + o.strip("\n") ANSI(p).to(Style.dim()) + " " + o.strip("\n")
# ), ),
# ) )
# exitcode, output = tracer.wait_until_stop_or_exit() exitcode, output = tracer.wait_until_stop_or_exit()
# except Exception as e: except Exception as e:
# output = str(e) output = str(e)
# logger.debug( logger.debug(
# f"\nProcessed Terminal, Input Commands: {commands} " f"\nProcessed Terminal, Input Commands: {commands} "
# f"Output Answer: {output}" f"Output Answer: {output}"
# ) )
# return output return output
# if __name__ == "__main__": # if __name__ == "__main__":

Loading…
Cancel
Save