I am getting the above error while calling the agent.
from crewai.tools import BaseTool
import os
from crewai import Agent, LLM
from tools import Custom_Data_Tool
from dotenv import load_dotenv
load_dotenv()
from langchain_google_genai import ChatGoogleGenerativeAI
my_llm=ChatGoogleGenerativeAI(model=“gemini-1.5-flash”,
verbose=True,
temperature=0.5,
google_api_key=os.getenv(“GOOGLE_API_KEY”))
#pdf_scrapper:
Exploration_Agent=Agent(
llm=my_llm,
role=“Data reader and processor”,
goal=“Read and process the data”,
verbose=True,
memory=True,
backstory= “”“”
You are a data explorer tasked with processing data from custom datasets.
“”" ,
tools=[Custom_Data_Tool]
)
My custom tool file (tools.py) looks like -
from crewai import Agent, Task, Crew, Process
from crewai.tools import BaseTool
import os
from pypdf import PdfReader
from typing import Type
from pydantic import BaseModel, Field
import pandas as pd
class CustomDataTool(BaseTool):
name: str = “CustomDataTool”
description: str = “Tool to process custom data files”
def _run(self, file: str) → str:
reader = PdfReader(‘kyc.pdf’).pages
pages = reader.pages
# print(len(reader))
pageObj = reader.pages[0]# print(pageObj.extract_text())
text =pageObj.extract_text()
# Extracting lines containing “Name:”
Name1=
lines = [line.strip() for line in text.split(‘\n’) if “NAME:” in line]
for line in lines:
name = line.split(“:”)[1].strip()
Name1.append(name)
# Name1.append({“NAME”: name})
# Extracting lines containing “DOB:”
Dob1=
lines = [line.strip() for line in text.split(‘\n’) if “DOB:” in line]
for line in lines:
dob = line.split(“:”)[1].strip()
Dob1.append(dob)
# Extracting lines containing “GEnder:”
gndr=
lines = [line.strip() for line in text.split(‘\n’) if “GENDER:” in line]
for line in lines:
gender = line.split(“:”)[1].strip()
gndr.append(gender)
# Extracting lines containing “Aadhar card:”
res=text.split()
aadhar_number=‘’
for word in res:
if len(word) == 4 and word.isdigit():
aadhar_number=aadhar_number + word + ’ ’
if len(aadhar_number)>=14:
print(“Aadhar number is :”+ aadhar_number)
else:
print(“Aadhar number not read”)
adh=aadhar_number
data={}
data['NAME']=Name1
data['DOB']=Dob1
data['gndr']=gndr
data['adh']=adh
data['CUST_ID']='abc1'
pdf_data=data = pd.DataFrame(data)
# Save the processed data
pdf_data.to_csv('C:/Users/ranit/Documents/gem1', index=False)
return(pdf_data)
#Load custom tool :
Custom_Data_Tool=CustomDataTool()