Bot commited on
Commit
ff65373
·
1 Parent(s): 35b84a4

Fix docstrings for smolagents v1.26

Browse files
Files changed (1) hide show
  1. app.py +48 -19
app.py CHANGED
@@ -13,8 +13,12 @@ HF_TOKEN = os.environ.get("HF_TOKEN", None)
13
  @tool
14
  def execute_python(code: str) -> str:
15
  """Python code execute karo.
16
- Args: code: Python code
17
- Returns: Output
 
 
 
 
18
  """
19
  fname = f"/tmp/agent_{datetime.now().strftime('%Y%m%d_%H%M%S')}.py"
20
  with open(fname, "w") as f:
@@ -32,9 +36,14 @@ def execute_python(code: str) -> str:
32
 
33
  @tool
34
  def create_file(filename: str, content: str) -> str:
35
- """Create file with content.
36
- Args: filename, content
37
- Returns: Status
 
 
 
 
 
38
  """
39
  os.makedirs(os.path.dirname(os.path.abspath(filename)) or ".", exist_ok=True)
40
  with open(filename, "w") as f:
@@ -43,9 +52,13 @@ def create_file(filename: str, content: str) -> str:
43
 
44
  @tool
45
  def read_file(filename: str) -> str:
46
- """Read file content.
47
- Args: filename
48
- Returns: Content
 
 
 
 
49
  """
50
  if not os.path.exists(filename):
51
  return f"Not found: {filename}"
@@ -54,9 +67,13 @@ def read_file(filename: str) -> str:
54
 
55
  @tool
56
  def run_shell(command: str) -> str:
57
- """Run Linux shell command.
58
- Args: command
59
- Returns: Output
 
 
 
 
60
  """
61
  r = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=30)
62
  o = ""
@@ -66,18 +83,26 @@ def run_shell(command: str) -> str:
66
 
67
  @tool
68
  def install_package(pkg: str) -> str:
69
- """Install Python package via pip.
70
- Args: pkg: Package name
71
- Returns: Output
 
 
 
 
72
  """
73
  r = subprocess.run(["pip3", "install", pkg], capture_output=True, text=True, timeout=60)
74
  return (r.stdout + "\n" + r.stderr).strip() or "Installed"
75
 
76
  @tool
77
  def list_files(path: str = ".") -> str:
78
- """List files in directory.
79
- Args: path: Directory path
80
- Returns: File listing
 
 
 
 
81
  """
82
  try:
83
  files = os.listdir(path)
@@ -94,7 +119,11 @@ def list_files(path: str = ".") -> str:
94
  return f"Error: {str(e)}"
95
 
96
  # Agent setup
97
- model = InferenceClientModel(model_id="Qwen/Qwen2.5-72B-Instruct", token=HF_TOKEN)
 
 
 
 
98
  tools = [
99
  DuckDuckGoSearchTool(), execute_python, create_file,
100
  read_file, run_shell, install_package, list_files,
@@ -126,7 +155,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
126
  gr.HTML("""
127
  <div style="text-align:center;margin-bottom:10px">
128
  <h1 style="background:linear-gradient(135deg,#667eea,#764ba2);-webkit-background-clip:text;-webkit-text-fill-color:transparent;font-size:2em">AIAGENT</h1>
129
- <p style="color:#666">Code Web Files Shell</p>
130
  </div>
131
  """)
132
  chatbot = gr.Chatbot(height=450, bubble_full_width=False, avatar_images=(None, "AI"))
 
13
  @tool
14
  def execute_python(code: str) -> str:
15
  """Python code execute karo.
16
+
17
+ Args:
18
+ code: Python code to execute.
19
+
20
+ Returns:
21
+ Output string with results or error.
22
  """
23
  fname = f"/tmp/agent_{datetime.now().strftime('%Y%m%d_%H%M%S')}.py"
24
  with open(fname, "w") as f:
 
36
 
37
  @tool
38
  def create_file(filename: str, content: str) -> str:
39
+ """Create a file with content.
40
+
41
+ Args:
42
+ filename: File path like hello.py.
43
+ content: Content to write.
44
+
45
+ Returns:
46
+ Success message.
47
  """
48
  os.makedirs(os.path.dirname(os.path.abspath(filename)) or ".", exist_ok=True)
49
  with open(filename, "w") as f:
 
52
 
53
  @tool
54
  def read_file(filename: str) -> str:
55
+ """Read content of a file.
56
+
57
+ Args:
58
+ filename: File path to read.
59
+
60
+ Returns:
61
+ File content or error.
62
  """
63
  if not os.path.exists(filename):
64
  return f"Not found: {filename}"
 
67
 
68
  @tool
69
  def run_shell(command: str) -> str:
70
+ """Run a Linux shell command.
71
+
72
+ Args:
73
+ command: Shell command to execute.
74
+
75
+ Returns:
76
+ Command output.
77
  """
78
  r = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=30)
79
  o = ""
 
83
 
84
  @tool
85
  def install_package(pkg: str) -> str:
86
+ """Install a Python package with pip.
87
+
88
+ Args:
89
+ pkg: Package name like requests.
90
+
91
+ Returns:
92
+ Installation output.
93
  """
94
  r = subprocess.run(["pip3", "install", pkg], capture_output=True, text=True, timeout=60)
95
  return (r.stdout + "\n" + r.stderr).strip() or "Installed"
96
 
97
  @tool
98
  def list_files(path: str = ".") -> str:
99
+ """List files in a directory.
100
+
101
+ Args:
102
+ path: Directory path, default is current.
103
+
104
+ Returns:
105
+ File listing as string.
106
  """
107
  try:
108
  files = os.listdir(path)
 
119
  return f"Error: {str(e)}"
120
 
121
  # Agent setup
122
+ model = InferenceClientModel(
123
+ model_id="Qwen/Qwen2.5-72B-Instruct",
124
+ token=HF_TOKEN
125
+ )
126
+
127
  tools = [
128
  DuckDuckGoSearchTool(), execute_python, create_file,
129
  read_file, run_shell, install_package, list_files,
 
155
  gr.HTML("""
156
  <div style="text-align:center;margin-bottom:10px">
157
  <h1 style="background:linear-gradient(135deg,#667eea,#764ba2);-webkit-background-clip:text;-webkit-text-fill-color:transparent;font-size:2em">AIAGENT</h1>
158
+ <p style="color:#666">Python Code | Web Search | Files | Shell</p>
159
  </div>
160
  """)
161
  chatbot = gr.Chatbot(height=450, bubble_full_width=False, avatar_images=(None, "AI"))