From 8b2fa676a11d128968b05ff64c32fd79a6a250d5 Mon Sep 17 00:00:00 2001 From: Kye Date: Sun, 19 Nov 2023 20:03:26 -0800 Subject: [PATCH] ai researh team swarm --- .../demos/accountant_team/account_team2.py | 74 ++++++++++++++ .../demos/accountant_team/accountant_team.py | 47 ++++----- playground/demos/ai_research_team/main.py | 50 ++++++++++ .../__pycache__/PosMedPrompts.cpython-310.pyc | Bin 3831 -> 0 bytes swarms/prompts/accountant_swarm_prompts.py | 90 +++++++++++++++++ swarms/prompts/ai_research_team.py | 91 ++++++++++++++++++ swarms/structs/flow.py | 6 +- swarms/utils/pdf_to_text.py | 6 +- 8 files changed, 336 insertions(+), 28 deletions(-) create mode 100644 playground/demos/accountant_team/account_team2.py create mode 100644 playground/demos/ai_research_team/main.py delete mode 100644 playground/posmed/__pycache__/PosMedPrompts.cpython-310.pyc create mode 100644 swarms/prompts/accountant_swarm_prompts.py create mode 100644 swarms/prompts/ai_research_team.py diff --git a/playground/demos/accountant_team/account_team2.py b/playground/demos/accountant_team/account_team2.py new file mode 100644 index 00000000..db3e6ed6 --- /dev/null +++ b/playground/demos/accountant_team/account_team2.py @@ -0,0 +1,74 @@ +import os +from dotenv import load_dotenv +from swarms.models import Anthropic, OpenAIChat +from swarms.prompts.accountant_swarm_prompts import ( + DECISION_MAKING_PROMPT, + DOC_ANALYZER_AGENT_PROMPT, + FRAUD_DETECTION_AGENT_PROMPT, + SUMMARY_GENERATOR_AGENT_PROMPT, +) +from swarms.structs import Flow +from swarms.utils.pdf_to_text import pdf_to_text + +# Environment variables +load_dotenv() +anthropic_api_key = os.getenv("ANTHROPIC_API_KEY") +openai_api_key = os.getenv("OPENAI_API_KEY") + + +# Base llms +llm1 = OpenAIChat( + openai_api_key=openai_api_key, +) + +llm2 = Anthropic( + anthropic_api_key=anthropic_api_key, +) + + +# Agents +doc_analyzer_agent = Flow( + llm=llm2, + sop=DOC_ANALYZER_AGENT_PROMPT, + max_loops="auto", +) +summary_generator_agent = Flow( + llm=llm2, + sop=SUMMARY_GENERATOR_AGENT_PROMPT, + max_loops="auto", +) +decision_making_support_agent = Flow( + llm=llm2, + sop=DECISION_MAKING_PROMPT, + max_loops="auto", +) + + +pdf_path="swarmdeck_a1.pdf" +fraud_detection_instructions="Detect fraud in the document" +summary_agent_instructions="Generate an actionable summary of the document" +decision_making_support_agent_instructions="Provide decision making support to the business owner:" + + +# Transform the pdf to text +pdf_text = pdf_to_text(pdf_path) +print(pdf_text) + + +# Detect fraud in the document +fraud_detection_agent_output = doc_analyzer_agent.run( + f"{fraud_detection_instructions}: {pdf_text}" +) +print(fraud_detection_agent_output) + +# Generate an actionable summary of the document +summary_agent_output = summary_generator_agent.run( + f"{summary_agent_instructions}: {fraud_detection_agent_output}" +) +print(summary_agent_output) + +# Provide decision making support to the accountant +decision_making_support_agent_output = decision_making_support_agent.run( + f"{decision_making_support_agent_instructions}: {summary_agent_output}" +) +print(decision_making_support_agent_output) \ No newline at end of file diff --git a/playground/demos/accountant_team/accountant_team.py b/playground/demos/accountant_team/accountant_team.py index 1401ef32..61cc2f7a 100644 --- a/playground/demos/accountant_team/accountant_team.py +++ b/playground/demos/accountant_team/accountant_team.py @@ -4,10 +4,15 @@ from typing import List from dotenv import load_dotenv from swarms.models import Anthropic, OpenAIChat +from swarms.prompts.accountant_swarm_prompts import ( + DECISION_MAKING_PROMPT, + DOC_ANALYZER_AGENT_PROMPT, + FRAUD_DETECTION_AGENT_PROMPT, + SUMMARY_GENERATOR_AGENT_PROMPT, +) from swarms.structs import Flow from swarms.utils.pdf_to_text import pdf_to_text - # Environment variables load_dotenv() anthropic_api_key = os.getenv("ANTHROPIC_API_KEY") @@ -24,27 +29,18 @@ llm2 = Anthropic( ) -# Prompts for each agent -SUMMARY_AGENT_PROMPT = """ - Generate an actionable summary of this financial document be very specific and precise, provide bulletpoints be very specific provide methods of lowering expenses: {answer}" -""" - - # Agents -user_consultant_agent = Flow( - llm=llm1, -) doc_analyzer_agent = Flow( llm=llm1, + sop=DOC_ANALYZER_AGENT_PROMPT, ) summary_generator_agent = Flow( llm=llm2, -) -fraud_detection_agent = Flow( - llm=llm2, + sop=SUMMARY_GENERATOR_AGENT_PROMPT, ) decision_making_support_agent = Flow( llm=llm2, + sop=DECISION_MAKING_PROMPT, ) @@ -71,11 +67,6 @@ class AccountantSwarms: 2. The Fraud Detection agent detects fraud in the document. 3. The Summary Agent generates an actionable summary of the document. 4. The Decision Making Support agent provides decision making support - to the accountant. - - Example: - >>> accountant_swarms = AccountantSwarms( - """ @@ -101,14 +92,26 @@ class AccountantSwarms: pdf_text = pdf_to_text(self.pdf_path) # Detect fraud in the document - fraud_detection_agent_output = self.fraud_detection_agent(pdf_text) + fraud_detection_agent_output = doc_analyzer_agent.run( + f"{self.fraud_detection_instructions}: {pdf_text}" + ) # Generate an actionable summary of the document - summary_agent_output = self.summary_agent(fraud_detection_agent_output) + summary_agent_output = summary_generator_agent.run( + f"{self.summary_agent_instructions}: {fraud_detection_agent_output}" + ) # Provide decision making support to the accountant - decision_making_support_agent_output = self.decision_making_support_agent( - summary_agent_output + decision_making_support_agent_output = decision_making_support_agent.run( + f"{self.decision_making_support_agent_instructions}: {summary_agent_output}" ) return decision_making_support_agent_output + + +swarm = AccountantSwarms( + pdf_path="tesla.pdf", + fraud_detection_instructions="Detect fraud in the document", + summary_agent_instructions="Generate an actionable summary of the document", + decision_making_support_agent_instructions="Provide decision making support to the business owner:", +) diff --git a/playground/demos/ai_research_team/main.py b/playground/demos/ai_research_team/main.py new file mode 100644 index 00000000..c986e123 --- /dev/null +++ b/playground/demos/ai_research_team/main.py @@ -0,0 +1,50 @@ +import os + +from dotenv import load_dotenv + +from swarms.models import Anthropic, OpenAIChat +from swarms.prompts.ai_research_team import ( + PAPER_IMPLEMENTOR_AGENT_PROMPT, + PAPER_SUMMARY_ANALYZER, +) +from swarms.structs import Flow +from swarms.utils.pdf_to_text import pdf_to_text + +# Base llms +# Environment variables +load_dotenv() +anthropic_api_key = os.getenv("ANTHROPIC_API_KEY") +openai_api_key = os.getenv("OPENAI_API_KEY") + +PDF_PATH = "shallowfeedforward.pdf" + + +# Base llms +llm1 = OpenAIChat( + openai_api_key=openai_api_key, +) + +llm2 = Anthropic( + anthropic_api_key=anthropic_api_key, +) + +# Agents +paper_summarizer_agent = Flow( + llm=llm2, + sop=PAPER_SUMMARY_ANALYZER, + max_loops=1, + autosave=True, + saved_state_path='paper_summarizer.json' +) + +paper_implementor_agent = Flow( + llm=llm1, + sop=PAPER_IMPLEMENTOR_AGENT_PROMPT, + max_loops=1, + autosave=True, + saved_state_path='paper_implementor.json' +) + +paper = pdf_to_text(PDF_PATH) +algorithmic_psuedocode_agent = paper_summarizer_agent.run(paper) +pytorch_code = paper_implementor_agent.run(algorithmic_psuedocode_agent) \ No newline at end of file diff --git a/playground/posmed/__pycache__/PosMedPrompts.cpython-310.pyc b/playground/posmed/__pycache__/PosMedPrompts.cpython-310.pyc deleted file mode 100644 index 4bcfbb742219abb8adcc40120ef2f5505e351060..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3831 zcmZXX&u$yZ5ymN5UfZ;HlS2aJu!qJvL1IAU%HGXISZtzb30r{vMUvN8M>#ZSn!^rf zrpMhgq-k3~4ta^(vd272-ayCXEpp1QdWMvY5a0}_r@Ol9tFOLlx=%mt_xODN^*83( zXT9Ek8L+mn_0%=BGH(+xN<5|* zn>@E+TCjH5?_W#}dsjAL^Ii4+{l&@Y!T!}%zyDZ0A03a*_72tamj~aC4iAn;G8umZ zCi7H{%{uOmB_)MR?Zg_-6v;^9^4z^?tOj~97PB;WHdWqK zrp7F}>5RsgO=j)FhK|@_*dRl#;fzu3C3|rL)-008l{6O8W8uEi+G!wT0_B9y|_3!l-HOGcAQfz zF+Fc}QON@V))RM6nXOD}^>D=~9cJuhLd;$C8{(D97KKc!4X|XftX1Zm6pEy# zOe|R^y9?uS$dT$uPZ(znc@geT&;y`PRVZym#uTOY+_@|_?9Ka?9(2WF%Or176QM0Y zZjh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