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

add restaurant example #108

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 33 additions & 0 deletions examples/restaurant_recs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from controlflow import Task, flow
from pydantic import BaseModel


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


@flow
def restaurant_recs(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.
"""

# 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)

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


if __name__ == "__main__":
restaurant_recs(5)
4 changes: 2 additions & 2 deletions src/controlflow/llm/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _completion_generator(
invalid_tool_message = handle_invalid_tool_call(tool_call)
response_messages.append(invalid_tool_message)
yield CompletionEvent(
type="tool_result_done", payload=dict(message=tool_result_message)
type="tool_result_done", payload=dict(message=invalid_tool_message)
)

counter += 1
Expand Down Expand Up @@ -272,7 +272,7 @@ async def _completion_async_generator(
invalid_tool_message = handle_invalid_tool_call(tool_call)
response_messages.append(invalid_tool_message)
yield CompletionEvent(
type="tool_result_done", payload=dict(message=tool_result_message)
type="tool_result_done", payload=dict(message=invalid_tool_message)
)

counter += 1
Expand Down
Loading