crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

How to read large text file (having tokens more than context limit of LLM)?

Open azaylamba opened this issue 1 year ago • 9 comments

I have a requirement to read a text file having around 500k tokens. How can I efficiently read the file content using FileReaderTool or some other tool. The agents need to consider the content of entire file while performing tasks, so the techniques like summarization might not be sufficient.

Any ideas please?

azaylamba avatar Jun 17 '24 12:06 azaylamba

Try google Gemini flash 1.5 with 1M context

theCyberTech avatar Jun 17 '24 12:06 theCyberTech

@theCyberTech Thanks for the suggestion. Is there any way to read the file in chunks so that LLMs with smaller context size can be used?

azaylamba avatar Jun 18 '24 05:06 azaylamba

There is a plan to integrate memgpt into the framework. however, the attempt was mentioned back in January and there hasn't been any update on that.

@joaomdmoura can you please confirm if that is still part of the plan or the status of it?

rezzie-rich avatar Jun 19 '24 17:06 rezzie-rich

@rezzie-rich Integrating memgpt would be very helpful. It would make CrewAI more useful for production level applications where context size is usually large.

azaylamba avatar Jun 21 '24 07:06 azaylamba

@azaylamba I know, I'm asking the same question, lol

rezzie-rich avatar Jun 21 '24 14:06 rezzie-rich

@joaomdmoura, currently, autogen is integrated to work with memgpt. I assume the process will be similar for crewai as well.

https://memgpt.readme.io/docs/autogen

rezzie-rich avatar Jun 21 '24 17:06 rezzie-rich

@rezzie-rich @azaylamba can you try using our tools?: https://docs.crewai.com/core-concepts/Tools/?h=tools

If its a PDF, we have a PDF search tool:

from crewai import Agent, Crew
from langchain_openai import ChatOpenAI
from crewai.process import Process

from crewai_tools import PDFSearchTool

from crewai.task import Task


llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo")


# Define the agents
researcher = Agent(
    role="Researcher",
    goal="Load 'https://arxiv.org/pdf/2406.04151' and understand it",
    backstory="Backstory 1",
    verbose=True,
    llm=llm,
    tools=[PDFSearchTool()],
)
analyzer = Agent(
    role="Analyzer",
    goal="Understand the paper from https://arxiv.org/pdf/2406.04151 and tell me about Evolving Large Language Model-based Agents across Diverse Environments",
    backstory="Backstory 2",
    verbose=True,
    llm=llm,
    tools=[PDFSearchTool()],
)


task1 = Task(
    name="Paper Ingestor",
    description="Search 'https://arxiv.org/pdf/2406.04151' and understand the paper",
    expected_output="give me a summary about the project",
    agent=researcher,
)
task2 = Task(
    name="Paper Analyzer",
    description="analyze the paper and tell me about Evolving Large Language Model-based Agents across Diverse Environments.  Ensure all information is accurate and comes from the searches. ",
    expected_output="give 3 paragaraph summary about the project",
    agent=analyzer,
)


# Create a crew with the tasks
crew = Crew(
    agents=[researcher, analyzer],
    tasks=[task1, task2],
    verbose=True,
    process=Process.sequential,
    # memory=True,
)


result = crew.kickoff()
print("results", result)

lorenzejay avatar Jul 31 '24 18:07 lorenzejay

alternatively you can load the pdf by instantiating the tool like this:

from crewai import Agent, Crew
from langchain_openai import ChatOpenAI
from crewai.process import Process

from crewai_tools import PDFSearchTool

from crewai.task import Task


llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo")

pdf_rag_tool = PDFSearchTool(pdf="https://arxiv.org/pdf/2406.04151")

# Define the agents
researcher = Agent(
    role="Researcher",
    goal="Load 'https://arxiv.org/pdf/2406.04151' and understand it",
    backstory="Backstory 1",
    verbose=True,
    llm=llm,
    tools=[pdf_rag_tool],
)


task1 = Task(
    name="Paper Ingestor",
    description="Search 'https://arxiv.org/pdf/2406.04151' and understand the paper then generate a 3 paragraph summary",
    expected_output="give me a 3 paragraph summary about the project",
    agent=researcher,
)

# Create a crew with the tasks
crew = Crew(
    agents=[researcher],
    tasks=[task1],
    verbose=True,
    process=Process.sequential,
    # memory=True,
)


result = crew.kickoff()
print("results", result)

lorenzejay avatar Jul 31 '24 18:07 lorenzejay

Thanks for the suggestion @lorenzejay, will try this.

azaylamba avatar Aug 03 '24 13:08 azaylamba

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 03 '24 12:09 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Sep 09 '24 12:09 github-actions[bot]