diff --git a/flight_search/README.md b/flight_search/README.md index 411f5959..eeaaeeb8 100644 --- a/flight_search/README.md +++ b/flight_search/README.md @@ -12,14 +12,15 @@ The following is a multi-task, multi-agent, multi-tool example for AI-based flig Install the required dependencies by running the following command: ``` -pip install crewai 'crewai[tools]' html2text playwright +pip install crewai 'crewai[tools]' html2text playwright dotenv ``` -Set the required environment variables: +Set the required environment variables in a `.env` file: ``` -export OPENAI_API_KEY= -export BROWSERBASE_API_KEY= +OPENAI_API_KEY= +BROWSERBASE_API_KEY= +BROWSERBASE_PROJECT_ID= ``` Optional, but recommended. Set a different model type in CrewAI to avoid token size limits: @@ -73,7 +74,7 @@ from typing import Optional 2. Create a flight agent for searching flights: ```python -flights = Agent( +flights_agent = Agent( role="Flights", goal="Search flights", backstory="I am an agent that can search for flights.", @@ -110,7 +111,6 @@ search_task = Task( ), expected_output=output_search_example, agent=flights, - human_input=False, # Optional ) ``` @@ -132,11 +132,10 @@ Here are our top 5 picks from Sofia to Berlin on 24th May 2024: - Booking: [MyTrip](https://www.skyscanner.net/transport_deeplink/4.0/UK/en-GB/GBP/ctuk/1/16440.9828.2024-05-26/air/trava/flights?itinerary=flight|-32474|319|16440|2024-05-26T21:05|9828|2024-05-26T22:15|130|-|-|-&carriers=-32474&operators=-32474&passengers=1&channel=website&cabin_class=economy&fps_session_id=20287887-26ad-45dc-b225-28fb4b9d8357&ticket_price=126.90&is_npt=false&is_multipart=false&client_id=skyscanner_website&request_id=4b423165-9b7b-4281-9596-cfcd6b0bb4e0&q_ids=H4sIAAAAAAAA_-NS52JJLinNFmLh2NHAKMXM8cRHoeH7yU1sRkwKjEWsqXm67k5VzO5OAQASECl8KQAAAA|8257781087420252411|2&q_sources=JACQUARD&commercial_filters=false&q_datetime_utc=2024-05-22T13:45:58&pqid=true&booking_panel_option_guid=dfb1f593-22dc-4565-8540-5f4f70979b9b&index=0&isbp=1&posidx=0&qid=16440-2405262105--32474-0-9828-2405262215&sort=BEST&stops=0&tabs=CombinedDayView&pre_redirect_id=7cdb112a-3842-4a51-b228-1cbcbc4c8094&redirect_id=a8541976-84a8-4161-849c-c7a6343125ae&is_acorn_referral=true) """ -search_providers = Task( +search_booking_providers_task = Task( description="Load every flight individually and find available booking providers", expected_output=output_result_example, agent=flights, - human_input=False, ) ``` @@ -144,11 +143,8 @@ search_providers = Task( ```python crew = Crew( - agents=[flights, summarize_agent], - tasks=[search_task, search_providers], - process=Process.sequential, - memory=False, - cache=True, + agents=[flights_agent, summarize_agent], + tasks=[search_task, search_booking_providers_task], max_rpm=100, ) ``` diff --git a/flight_search/bb.py b/flight_search/browserbase.py similarity index 100% rename from flight_search/bb.py rename to flight_search/browserbase.py diff --git a/flight_search/main.py b/flight_search/main.py index 913542e7..041a3002 100644 --- a/flight_search/main.py +++ b/flight_search/main.py @@ -1,8 +1,11 @@ import sys import datetime -from crewai import Crew, Process, Task, Agent -from bb import browserbase +from crewai import Crew, Task, Agent +from browserbase import browserbase from skyscanner import skyscanner +from dotenv import load_dotenv + +load_dotenv() # take environment variables from .env. output_search_example = """ Here are our top 5 flights from Sofia to Berlin on 24th May 2024: @@ -22,7 +25,7 @@ - Booking: [MyTrip](https://www.skyscanner.net/transport_deeplink/4.0/UK/en-GB/GBP/ctuk/1/16440.9828.2024-05-26/air/trava/flights?itinerary=flight|-32474|319|16440|2024-05-26T21:05|9828|2024-05-26T22:15|130|-|-|-&carriers=-32474&operators=-32474&passengers=1&channel=website&cabin_class=economy&fps_session_id=20287887-26ad-45dc-b225-28fb4b9d8357&ticket_price=126.90&is_npt=false&is_multipart=false&client_id=skyscanner_website&request_id=4b423165-9b7b-4281-9596-cfcd6b0bb4e0&q_ids=H4sIAAAAAAAA_-NS52JJLinNFmLh2NHAKMXM8cRHoeH7yU1sRkwKjEWsqXm67k5VzO5OAQASECl8KQAAAA|8257781087420252411|2&q_sources=JACQUARD&commercial_filters=false&q_datetime_utc=2024-05-22T13:45:58&pqid=true&booking_panel_option_guid=dfb1f593-22dc-4565-8540-5f4f70979b9b&index=0&isbp=1&posidx=0&qid=16440-2405262105--32474-0-9828-2405262215&sort=BEST&stops=0&tabs=CombinedDayView&pre_redirect_id=7cdb112a-3842-4a51-b228-1cbcbc4c8094&redirect_id=a8541976-84a8-4161-849c-c7a6343125ae&is_acorn_referral=true) """ -flights = Agent( +flights_agent = Agent( role="Flights", goal="Search flights", backstory="I am an agent that can search for flights.", @@ -39,34 +42,31 @@ allow_delegation=False, ) -search_task = Task( +search_flights_task = Task( description=( "Search flights according to criteria {request}. Current year: {current_year}" ), expected_output=output_search_example, - agent=flights, - human_input=False, # Optional + agent=flights_agent, ) -search_providers = Task( +search_booking_providers_task = Task( description="Load every flight individually and find available booking providers", expected_output=output_result_example, - agent=flights, + agent=flights_agent, human_input=False, ) crew = Crew( - agents=[flights, summarize_agent], - tasks=[search_task, search_providers], - process=Process.sequential, - memory=False, - cache=True, + agents=[flights_agent, summarize_agent], + tasks=[search_flights_task, search_booking_providers_task], max_rpm=100, + verbose=True ) result = crew.kickoff( inputs={ - "request": sys.argv[1] or "Flights from Sofia to Berlin on 2th July", + "request": sys.argv[1], "current_year": datetime.date.today().year, } )