Skip to content

Commit

Permalink
Merge pull request #116 from PrefectHQ/introduction
Browse files Browse the repository at this point in the history
Update introduction.mdx
  • Loading branch information
jlowin authored Jun 14, 2024
2 parents 3316ea9 + d0cd219 commit 30f2503
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions docs/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,47 @@ ControlFlow provides a structured and intuitive way to create sophisticated agen
from controlflow import flow, Task
from pydantic import BaseModel

class Preferences(BaseModel):
location: str
cuisine: str

class Restaurant(BaseModel):
name: str
description: str


@flow
def restaurant_recs(n:int) -> list[Restaurant]:
def restaurant_recommendations(n:int) -> list[Restaurant]:
"""
An agentic workflow that asks the user for their location and
cuisine preference, then recommends n restaurants based on their input.
An agentic workflow that asks the user for preferences,
then recommends restaurants based on their input.
"""

# get the user's location
location = Task("Get a location", user_access=True)

# get the user's preferred cuisine
cuisine = Task("Get a preferred cuisine", user_access=True)
# get preferences from the user
preferences = Task(
"Get the user's preferences",
result_type=Preferences,
user_access=True,
)

# generate the recommendations from the user's input
recs = Task(
# generate the recommendations
recommendations = Task(
f"Recommend {n} restaurants to the user",
context=dict(location=location, cuisine=cuisine),
context=dict(preferences=preferences),
result_type=list[Restaurant],
)
return recs

return recommendations

recs = restaurant_recs(n=3)
print(recs)
```
```python Result
# >> Agent: Hi! Could you please tell me your current location? Also,
# what type of cuisine are you in the mood for?
# >> Agent: Hi there! To help find the best restaurant
# for you, could you please tell me your location and
# the type of cuisine you're interested in?

# >> User: I'm in DC looking for a cafe

# -------------------------------------------------

[
Restaurant(
name="Compass Coffee",
Expand Down

0 comments on commit 30f2503

Please sign in to comment.