From 1dd3964561f220de64f694514aa067bcef7df00d Mon Sep 17 00:00:00 2001 From: ysolanky Date: Tue, 24 Dec 2024 19:53:41 -0500 Subject: [PATCH 1/2] gather agents example --- cookbook/async/gather_agents.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cookbook/async/gather_agents.py diff --git a/cookbook/async/gather_agents.py b/cookbook/async/gather_agents.py new file mode 100644 index 000000000..0fd7e5420 --- /dev/null +++ b/cookbook/async/gather_agents.py @@ -0,0 +1,38 @@ +import asyncio +from rich.pretty import pprint +from phi.agent import Agent +from phi.model.openai import OpenAIChat +from phi.tools.duckduckgo import DuckDuckGo + +providers = ["openai", "anthropic", "ollama", "cohere", "google"] +instructions = [ + "Your task is to write a well researched report on AI providers.", + "The report should be unbiased and factual." +] + + +async def get_reports(): + tasks = [] + for provider in providers: + agent = Agent( + model=OpenAIChat(id="gpt-4"), + instructions=instructions, + tools=[DuckDuckGo()], + ) + tasks.append(agent.arun(f"Write a report on the following AI provider: {provider}")) + + results = await asyncio.gather(*tasks) + return results + + +async def main(): + results = await get_reports() + for result in results: + print("************") + pprint(result.content) + print("************") + print("\n") + + +if __name__ == "__main__": + asyncio.run(main()) From 15d238e9af401cf59b0dbcc5b3300123708c5e47 Mon Sep 17 00:00:00 2001 From: ysolanky Date: Tue, 24 Dec 2024 19:54:10 -0500 Subject: [PATCH 2/2] update --- cookbook/async/gather_agents.py | 2 +- cookbook/workflows/startup_idea_validator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cookbook/async/gather_agents.py b/cookbook/async/gather_agents.py index 0fd7e5420..cec1a2c35 100644 --- a/cookbook/async/gather_agents.py +++ b/cookbook/async/gather_agents.py @@ -7,7 +7,7 @@ providers = ["openai", "anthropic", "ollama", "cohere", "google"] instructions = [ "Your task is to write a well researched report on AI providers.", - "The report should be unbiased and factual." + "The report should be unbiased and factual.", ] diff --git a/cookbook/workflows/startup_idea_validator.py b/cookbook/workflows/startup_idea_validator.py index c4070f622..99bc89dfc 100644 --- a/cookbook/workflows/startup_idea_validator.py +++ b/cookbook/workflows/startup_idea_validator.py @@ -205,7 +205,7 @@ def run(self, startup_idea: str) -> Iterator[RunResponse]: table_name="validate_startup_ideas_workflow", db_file="tmp/workflows.db", ), - debug_mode=True + debug_mode=True, ) final_report: Iterator[RunResponse] = startup_idea_validator.run(startup_idea=idea)