RCaz commited on
Commit
22985f3
·
verified ·
1 Parent(s): 6e08ce0

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +29 -0
agent.py CHANGED
@@ -160,6 +160,34 @@ def parse_python_file(path: str) -> str:
160
  with open(path, "r") as py_file:
161
  return py_file.read()
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  class TestAgent:
165
  def __init__(self):
@@ -196,6 +224,7 @@ class TestAgent:
196
  parse_python_file, # V4
197
  describe_image, # V4
198
  extract_text_from_audio, # V4
 
199
  FinalAnswerTool()],
200
  additional_authorized_imports=["pandas","markdownify","requests","chess","os"], # V2 add markdownify & requests V5 add chess and os
201
  model=model,
 
160
  with open(path, "r") as py_file:
161
  return py_file.read()
162
 
163
+ @tool
164
+ def parse_pdf_file(path: str) -> str:
165
+ """
166
+ Read and return the contents of a pdf file from its path.
167
+
168
+ Args:
169
+ path (str): The file path to the pdf file to be read.
170
+
171
+ Returns:
172
+ str: The complete contents of the pdf file as a string.
173
+
174
+ """
175
+ from pypdf import PdfReader
176
+
177
+ if not path.endswith(".pdf"):
178
+ return "file does not end with .pdf"
179
+
180
+ reader = PdfReader(path)
181
+ len_pages = len(reader.pages)
182
+
183
+ out = ""
184
+ for p in range(len_pages):
185
+ page = reader.pages[0]
186
+ text = page.extract_text()
187
+ out+=text+"\n"
188
+ return out
189
+
190
+
191
 
192
  class TestAgent:
193
  def __init__(self):
 
224
  parse_python_file, # V4
225
  describe_image, # V4
226
  extract_text_from_audio, # V4
227
+ parse_pdf_file, # V5
228
  FinalAnswerTool()],
229
  additional_authorized_imports=["pandas","markdownify","requests","chess","os"], # V2 add markdownify & requests V5 add chess and os
230
  model=model,