Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable naming consistency + remove options with default values #1

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions flight_search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=
export BROWSERBASE_PROJECT_ID=
charlypoly marked this conversation as resolved.
Show resolved Hide resolved
charlypoly marked this conversation as resolved.
Show resolved Hide resolved
```

Optional, but recommended. Set a different model type in CrewAI to avoid token size limits:
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -110,7 +111,6 @@ search_task = Task(
),
expected_output=output_search_example,
agent=flights,
human_input=False, # Optional
)
```

Expand All @@ -132,23 +132,19 @@ 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,
)
```

5. Initialize new crew with agents and tasks:

```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,
)
```
Expand Down
File renamed without changes.
28 changes: 14 additions & 14 deletions flight_search/main.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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.",
Expand All @@ -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,
}
)
Expand Down