From 801980bacca7963c7d0e16d5eb531a64d3dcf0f1 Mon Sep 17 00:00:00 2001 From: Kye Date: Sun, 16 Jul 2023 13:19:04 -0400 Subject: [PATCH] boss node fix Former-commit-id: c25424d919a589f2dee9ccbf76fa73e117279681 --- README.md | 2 +- swarms/agents/boss/BossNode.py | 37 +++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6d0b2731..ca6d6918 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ At Swarms, we're transforming the landscape of AI from siloed AI agents to a uni --- ## Installation -There are 2 methods, one is through `git clone` and the other is by `pip install swarms`. Check out the [document](DOCS/DOCUMENTATION.md) for more information on the classes. +There are 2 methods, one is through `git clone` and the other is by `pip install swarms`. Check out the [DOCUMENTATION](DOCS/DOCUMENTATION.md) for more information on the classes. --- # Method1 diff --git a/swarms/agents/boss/BossNode.py b/swarms/agents/boss/BossNode.py index 3ec040f0..92c877fc 100644 --- a/swarms/agents/boss/BossNode.py +++ b/swarms/agents/boss/BossNode.py @@ -33,6 +33,20 @@ class BossNode: logging.error(f"Unexpected Error while initializing BabyAGI: {e}") raise + def initialize_vectorstore(self): + """ + Init vector store + """ + try: + embeddings_model = OpenAIEmbeddings(openai_api_key=self.openai_api_key) + embedding_size = 1536 + index = faiss.IndexFlatL2(embedding_size) + return FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {}) + except Exception as e: + logging.error(f"Failed to initialize vector store: {e}") + return None + + def create_task(self, objective): """ Creates a task with the given objective. @@ -53,4 +67,25 @@ class BossNode: self.baby_agi(task) except Exception as e: logging.error(f"Error while executing task: {e}") - raise \ No newline at end of file + raise + + + +def boss_node(objective, api_key=None, llm=None, vectorstore=None, agent_executor=None, max_iterations=10): +#wrapper function to initialize and use Bossnode with given parameters + #api keys can be passed as an argument or set as an env + api_key = api_key or os.getenv("API_KEY") + + if not api_key: + raise ValueError("API key must be providef either as argument as an env named 'api_key'") + + if not llm: + raise ValueError("Language model must be provided") + if not vectorstore: + raise ValueError("Vectorstore must be provided") + if not agent_executor: + raise ValueError('Agent Executor must be provided') + + boss = BossNode(llm, vectorstore, agent_executor, max_iterations) + task = boss.create_task(objective) + boss.execute_task(task)