I have the two files below. Im getting this error:
> Entering new CrewAgentExecutor chain...
The first step in my research process will be to find the Case Identification, Case Name and Citation, Plaintiff and Defendant. To do this, I'll need to conduct an internet search with the provided parameters: state, topic, and person. This will help me locate the specific case law I'm looking for.
Action:
Search the internet
Action Input:
{"query": "Case law in state 't' about topic 't' related to person 't'"}
I encountered an error while trying to use the tool. This was the error: SearchTools.search_internet() missing 1 required positional argument: 'self'. Tool Search the internet accepts these inputs: Search the internet(self, query) - Useful to search the internet about a given topic and return relevant results
Thought:
The tool error encountered was likely due to a technical problem. To find the specific case law, I need to retry the search on the internet using the provided parameters: state, topic, and person.
from dotenv import load_dotenv
load_dotenv() # Ensure environment variables are loaded first
import os
from crewai import Crew
from textwrap import dedent
from agents import LawAgents
from tasks import LawTasks
from tools.search_tools import SearchTools # Make sure to import SearchTools class LawCrew:
def __init__(self, person, topic, state):
self.person = person
self.topic = topic
self.state = state
self.search_tools = SearchTools() # Create an instance of SearchTools self.tasks = LawTasks(self.search_tools) # Pass the instance to LawTasks def run(self):
try:
agents = LawAgents()
law_researcher_agent = agents.law_researcher_agent() law_report_writer_agent = agents.law_report_writer_agent() search_case_law = tasks.search_case_law(law_researcher_agent, self.person, self.topic, self.state) analyse_case_law = tasks.analyse_case_law(law_analyst_agent, self.person, self.topic, self.state)
write_report = tasks.write_report(law_report_writer_agent, self.person, self.topic, self.state)
crew = Crew(agents=[law_researcher_agent, law_analyst_agent, law_report_writer_agent], tasks=[search_case_law, analyse_case_law, write_report], verbose=True)
return crew.kickoff()
except Exception as e:
print(f"An error occurred: {e}")
return None
if __name__ == "__main__":
print("Welcome to Law Assistant")
person = input("What is the name of a person involved in this case law?\n")
topic = input("What was this case about? Evidence Suppression, Bail Bonds, Stolen Vehicle, etc.\n")
state = input("In what state did the case originate?\n")
law_crew = LawCrew(person, topic, state)
print("\n\n########################")
print("## Here is your detailed case law report:")
print("########################\n")
print(result)
________________________________________________________________________________________________
import requests
import json
import os
class SearchTools:
@tool("Search the internet")
def search_internet(self, query):
"""Useful to search the internet about a given topic and return relevant results"""
top_results_to_return = 5
api_key = os.getenv('SERPER_API_KEY')
if not api_key:
raise ValueError("SERPER API key is not set. Please set the SERPER_API_KEY environment variable.")
payload = json.dumps({"q": query})
headers = {
'X-API-KEY': api_key,
'Content-Type': 'application/json'
}
if response.status_code != 200:
return f"Failed to fetch data: HTTP Status {response.status_code}"
response_data = response.json()
if 'organic' not in response_data:
return "Sorry, I couldn't find anything about that, could be an error with the SERPER API key."
else:
results = response_data['organic']
strings = []
for result in results[:top_results_to_return]:
try:
strings.append('\n'.join([
f"Title: {result['title']}",
f"Link: {result['link']}",
f"Snippet: {result['snippet']}",
"\n----------------"
]))
except KeyError as e:
strings.append(f"Error processing result: {str(e)}")
return '\n'.join(strings)