Martin Bär
commited on
Commit
·
c89b357
1
Parent(s):
2640254
Add read_file tool
Browse files- basic_agent.py +2 -2
- multimodality_tools.py +15 -0
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, _get_file
|
22 |
|
23 |
class BasicAgent:
|
24 |
def __init__(self, ollama=False, langfuse=False):
|
@@ -53,7 +53,7 @@ class BasicAgent:
|
|
53 |
"whether the element to be put in the list is a number or a string."
|
54 |
),
|
55 |
llm=llm,
|
56 |
-
tools=[],
|
57 |
can_handoff_to=["WikiAgent", "WebAgent", "StatsAgent", "AudioAgent", "ImageAgent"],
|
58 |
)
|
59 |
|
|
|
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, get_read_file_tool
|
22 |
|
23 |
class BasicAgent:
|
24 |
def __init__(self, ollama=False, langfuse=False):
|
|
|
53 |
"whether the element to be put in the list is a number or a string."
|
54 |
),
|
55 |
llm=llm,
|
56 |
+
tools=[get_read_file_tool()],
|
57 |
can_handoff_to=["WikiAgent", "WebAgent", "StatsAgent", "AudioAgent", "ImageAgent"],
|
58 |
)
|
59 |
|
multimodality_tools.py
CHANGED
@@ -163,3 +163,18 @@ def remove_think(output: str) -> str:
|
|
163 |
if output:
|
164 |
return re.sub("<think>.*</think>", "", output).strip()
|
165 |
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
if output:
|
164 |
return re.sub("<think>.*</think>", "", output).strip()
|
165 |
return output
|
166 |
+
|
167 |
+
def read_txt_or_py_file(file_id: str) -> str:
|
168 |
+
"""Read a python or txt file as plain text and return its content."""
|
169 |
+
try:
|
170 |
+
bytes_io = _get_file(file_id)
|
171 |
+
except:
|
172 |
+
return "Error: Invalid file. This file is either not a .py/.txt file or the id does not exist."
|
173 |
+
bytes_io.seek(0)
|
174 |
+
return bytes_io.read().decode()
|
175 |
+
|
176 |
+
def get_read_file_tool():
|
177 |
+
return FunctionTool.from_defaults(
|
178 |
+
fn=read_txt_or_py_file,
|
179 |
+
description="Read a python or txt file as plain text and return its content."
|
180 |
+
)
|