Martin Bär commited on
Commit
20816f3
·
1 Parent(s): f31b7de

Add check if file exists

Browse files
Files changed (1) hide show
  1. basic_agent.py +10 -2
basic_agent.py CHANGED
@@ -18,7 +18,7 @@ from llama_index.core.agent.workflow import (
18
  )
19
 
20
  from multimodality_tools import get_image_qa_tool, get_transcription_tool, \
21
- get_excel_analysis_tool, get_excel_tool, get_csv_analysis_tool, get_csv_tool
22
 
23
  class BasicAgent:
24
  def __init__(self, ollama=False, langfuse=False):
@@ -145,7 +145,7 @@ class BasicAgent:
145
 
146
  async def __call__(self, question: str, task_id: str = None) -> str:
147
  file_str = ""
148
- if task_id:
149
  file_str = f'\nIf you need to load a file, do so by providing the id "{task_id}".'
150
 
151
  msg = f"{question}{file_str}"
@@ -193,3 +193,11 @@ class BasicAgent:
193
  return res
194
  except:
195
  return "Error occured. No valid agent response could be determined."
 
 
 
 
 
 
 
 
 
18
  )
19
 
20
  from multimodality_tools import get_image_qa_tool, get_transcription_tool, \
21
+ get_excel_analysis_tool, get_excel_tool, get_csv_analysis_tool, get_csv_tool, _get_file
22
 
23
  class BasicAgent:
24
  def __init__(self, ollama=False, langfuse=False):
 
145
 
146
  async def __call__(self, question: str, task_id: str = None) -> str:
147
  file_str = ""
148
+ if file_exists(task_id):
149
  file_str = f'\nIf you need to load a file, do so by providing the id "{task_id}".'
150
 
151
  msg = f"{question}{file_str}"
 
193
  return res
194
  except:
195
  return "Error occured. No valid agent response could be determined."
196
+
197
+ def file_exists(task_id: str) -> bool:
198
+ try:
199
+ file = _get_file(task_id)
200
+ except:
201
+ return False
202
+ del file
203
+ return True