Tesvia commited on
Commit
ac3e234
·
verified ·
1 Parent(s): 893911f

Upload tools.py

Browse files
Files changed (1) hide show
  1. tools.py +13 -3
tools.py CHANGED
@@ -9,10 +9,20 @@ import io
9
  import os
10
  import time
11
  import datetime
12
- from typing import List, Dict
13
 
14
  from agents import function_tool
15
 
 
 
 
 
 
 
 
 
 
 
16
  def log(msg):
17
  print(f"[{datetime.datetime.now():%Y-%m-%d %H:%M:%S}] {msg}")
18
 
@@ -56,7 +66,7 @@ def python_run(code: str) -> str:
56
  # 2. --------------------------------------------------------------------
57
  @function_tool
58
  @log_tool_call
59
- def load_spreadsheet(path: str, sheet: str | int | None = None) -> list[dict]:
60
  """Read .csv, .xls or .xlsx from disk and return rows as list of dictionaries.
61
 
62
  Args:
@@ -144,7 +154,7 @@ def image_ocr(path: str) -> str:
144
  # 6. --------------------------------------------------------------------
145
  @function_tool
146
  @log_tool_call
147
- def duckduckgo_search(query: str, max_results: int = 5) -> list[dict]:
148
  """Search DuckDuckGo and return a list of result dicts with title, href and body.
149
 
150
  Args:
 
9
  import os
10
  import time
11
  import datetime
12
+ from typing import TypedDict, List, Union
13
 
14
  from agents import function_tool
15
 
16
+ class DuckDuckGoResult(TypedDict):
17
+ title: str
18
+ href: str
19
+ body: str
20
+
21
+ class SpreadsheetRow(TypedDict):
22
+ # If you don't know the columns, leave this empty,
23
+ # but ideally, define them.
24
+ pass
25
+
26
  def log(msg):
27
  print(f"[{datetime.datetime.now():%Y-%m-%d %H:%M:%S}] {msg}")
28
 
 
66
  # 2. --------------------------------------------------------------------
67
  @function_tool
68
  @log_tool_call
69
+ def load_spreadsheet(path: str, sheet: Union[str, int, None] = None) -> List[SpreadsheetRow]:
70
  """Read .csv, .xls or .xlsx from disk and return rows as list of dictionaries.
71
 
72
  Args:
 
154
  # 6. --------------------------------------------------------------------
155
  @function_tool
156
  @log_tool_call
157
+ def duckduckgo_search(query: str, max_results: int = 5) -> List[DuckDuckGoResult]:
158
  """Search DuckDuckGo and return a list of result dicts with title, href and body.
159
 
160
  Args: