Hi
I am trying to replicate the operation of this tool used in the CrewAI examples (crewAI-examples/instagram_post/tools/browser_tools.py at 660c7dbdabb36fcd1ec95ee0cca4412e00f0d4c6 · crewAIInc/crewAI-examples · GitHub). I would like to use this approach for text files. My code so far is as follows:
import os
from crewai import Agent, Task
from crewai.llm import LLM
from crewai_tools import tool
from dotenv import load_dotenv
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
llm = LLM(
model="gpt-3.5-turbo-16k",
temperature=0.7
)
@tool("Summarize text file content")
def summarize_text_file():
"""
Summarizes the content of a local text file.
"""
file_path = 'information.txt'
# Read the content of the .txt file
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Split the content into 8000-character segments
content_chunks = [content[i:i + 8000] for i in range(0, len(content), 8000)]
summaries = []
for chunk in content_chunks:
agent = Agent(
role='Principal Researcher',
goal='Conduct detailed research and summaries based on the provided content.',
backstory="You are a Principal Researcher and need to analyze and summarize large text files.",
llm=llm,
allow_delegation=False
)
task = Task(
agent=agent,
description=f'Analyze and create a detailed summary of the content below. Make sure to include the most relevant information in the summary and return only the summary.\n\nCONTENT\n----------\n{chunk}',
expected_output='A clear and concise summary of the content with the most important points highlighted.'
)
summary = task.execute()
summaries.append(summary)
final_summary = "\n\n".join(summaries)
return f'\nFile Summary:\n{final_summary}\n'
When I run it I get the following error reported by the agent:
I encountered an error while trying to use the tool. This was the error: ‘Task’ object has no attribute ‘execute’.
I don’t understand what exactly is going on. Can someone help me? Sorry. I am new to crewai