LamiaYT commited on
Commit
8401485
·
1 Parent(s): 5696ad8
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -5,7 +5,6 @@ import requests
5
  import inspect
6
  import pandas as pd
7
  from smolagents import CodeAgent
8
- from smolagents.tools import PythonInterpreterTool
9
  import json
10
  import tempfile
11
  import urllib.parse
@@ -31,6 +30,19 @@ class HfApiModel:
31
  outputs = self.pipe(prompt, max_new_tokens=512, do_sample=True)
32
  return outputs[0]["generated_text"]
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  class DuckDuckGoSearchTool:
35
  name = "duckduckgo_search"
36
  description = "Use DuckDuckGo to search the web."
 
5
  import inspect
6
  import pandas as pd
7
  from smolagents import CodeAgent
 
8
  import json
9
  import tempfile
10
  import urllib.parse
 
30
  outputs = self.pipe(prompt, max_new_tokens=512, do_sample=True)
31
  return outputs[0]["generated_text"]
32
 
33
+ class PythonInterpreterTool:
34
+ name = "python_interpreter"
35
+ description = "Evaluate Python code for logic, data, and math."
36
+
37
+ def __call__(self, code: str) -> str:
38
+ try:
39
+ local_vars = {}
40
+ exec(code, {"__builtins__": {}}, local_vars)
41
+ return repr(local_vars)
42
+ except Exception as e:
43
+ return f"Python execution error: {e}"
44
+
45
+
46
  class DuckDuckGoSearchTool:
47
  name = "duckduckgo_search"
48
  description = "Use DuckDuckGo to search the web."