mohantest commited on
Commit
60e36fc
·
verified ·
1 Parent(s): c34464d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -25,7 +25,12 @@ def save_cache():
25
  def calculator(expression: str) -> str:
26
  """
27
  Safely evaluate a mathematical expression.
28
- Input should be a simple arithmetic expression (e.g., '2 + 2').
 
 
 
 
 
29
  """
30
  # Allow only numbers, basic operators, parentheses, and spaces
31
  allowed_chars = set("0123456789+-*/(). ")
@@ -42,7 +47,13 @@ def calculator(expression: str) -> str:
42
  def web_search(query: str) -> str:
43
  """
44
  Search the web for up-to-date information.
45
- Uses DuckDuckGo (free, no API key). Requires duckduckgo-search package.
 
 
 
 
 
 
46
  """
47
  try:
48
  from duckduckgo_search import DDGS
@@ -61,10 +72,7 @@ def web_search(query: str) -> str:
61
 
62
  # ---------- Agent ----------
63
  # Use ApiModel (the correct class name in current smolagents)
64
- # You can specify a model explicitly, e.g.:
65
- # model = ApiModel("meta-llama/Llama-2-7b-chat-hf")
66
- # The default uses Hugging Face's free inference API.
67
- model = ApiModel()
68
 
69
  # Only include web_search if the package is installed
70
  tools = [calculator]
 
25
  def calculator(expression: str) -> str:
26
  """
27
  Safely evaluate a mathematical expression.
28
+
29
+ Args:
30
+ expression: A string containing a simple arithmetic expression (e.g., '2 + 2').
31
+
32
+ Returns:
33
+ The result as a string, or an error message if the expression is invalid.
34
  """
35
  # Allow only numbers, basic operators, parentheses, and spaces
36
  allowed_chars = set("0123456789+-*/(). ")
 
47
  def web_search(query: str) -> str:
48
  """
49
  Search the web for up-to-date information.
50
+
51
+ Args:
52
+ query: The search query string.
53
+
54
+ Returns:
55
+ A string containing up to three search result snippets with titles and URLs,
56
+ or an error message if the search fails.
57
  """
58
  try:
59
  from duckduckgo_search import DDGS
 
72
 
73
  # ---------- Agent ----------
74
  # Use ApiModel (the correct class name in current smolagents)
75
+ model = ApiModel() # Uses Hugging Face's free inference API
 
 
 
76
 
77
  # Only include web_search if the package is installed
78
  tools = [calculator]