sskorol commited on
Commit
8f9943c
·
verified ·
1 Parent(s): 17f2a3a

Fixed incompatible shell args

Browse files

It seems like some types are not supported by tools. Added more straightforward typing.

Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -5,52 +5,63 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import subprocess
8
- from typing import Dict, Optional, Union
9
 
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
  def execute_shell_command(
14
- command: Union[str, list],
15
- shell: bool = False,
16
  cwd: Optional[str] = None,
17
- env: Optional[Dict[str, str]] = None,
18
  timeout: Optional[int] = None
19
- ) -> tuple[str, str, int]:
20
  """
21
  Execute a shell command and return its output.
22
 
23
  Args:
24
- command: Command to execute (string or list of arguments)
25
- shell: If True, command is executed through shell
26
  cwd: Working directory for command execution
27
- env: Dictionary of environment variables
28
  timeout: Timeout in seconds
29
 
30
  Returns:
31
- tuple containing (stdout, stderr, return_code)
32
  """
33
  try:
 
34
  process = subprocess.Popen(
35
  command,
36
  stdout=subprocess.PIPE,
37
  stderr=subprocess.PIPE,
38
  shell=shell,
39
  cwd=cwd,
40
- env=env,
41
  universal_newlines=True
42
  )
43
-
 
44
  stdout, stderr = process.communicate(timeout=timeout)
45
  return_code = process.returncode
46
 
47
- return stdout, stderr, return_code
 
 
 
 
48
 
49
  except subprocess.TimeoutExpired:
50
  process.kill()
51
- raise TimeoutError(f"Command timed out after {timeout} seconds")
 
 
 
 
52
  except Exception as e:
53
- raise RuntimeError(f"Error executing command: {str(e)}")
 
 
 
 
54
 
55
  @tool
56
  def get_current_time_in_timezone(timezone: str) -> str:
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import subprocess
8
+ from typing import Dict, Optional
9
 
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
  def execute_shell_command(
14
+ command: str,
15
+ shell: bool = True,
16
  cwd: Optional[str] = None,
 
17
  timeout: Optional[int] = None
18
+ ) -> Dict[str, str]:
19
  """
20
  Execute a shell command and return its output.
21
 
22
  Args:
23
+ command: Command to execute as a string
24
+ shell: Whether to execute command through shell
25
  cwd: Working directory for command execution
 
26
  timeout: Timeout in seconds
27
 
28
  Returns:
29
+ Dictionary containing stdout, stderr, and return_code
30
  """
31
  try:
32
+ # Run the command with specified parameters
33
  process = subprocess.Popen(
34
  command,
35
  stdout=subprocess.PIPE,
36
  stderr=subprocess.PIPE,
37
  shell=shell,
38
  cwd=cwd,
 
39
  universal_newlines=True
40
  )
41
+
42
+ # Get command output with optional timeout
43
  stdout, stderr = process.communicate(timeout=timeout)
44
  return_code = process.returncode
45
 
46
+ return {
47
+ "stdout": stdout,
48
+ "stderr": stderr,
49
+ "return_code": str(return_code) # Convert to string for consistency
50
+ }
51
 
52
  except subprocess.TimeoutExpired:
53
  process.kill()
54
+ return {
55
+ "stdout": "",
56
+ "stderr": f"Command timed out after {timeout} seconds",
57
+ "return_code": "-1"
58
+ }
59
  except Exception as e:
60
+ return {
61
+ "stdout": "",
62
+ "stderr": f"Error executing command: {str(e)}",
63
+ "return_code": "-1"
64
+ }
65
 
66
  @tool
67
  def get_current_time_in_timezone(timezone: str) -> str: