From 8a1b298bdbb1269aeac81fe940f9ed5382f000b4 Mon Sep 17 00:00:00 2001 From: Kye Date: Fri, 14 Jul 2023 21:11:38 -0400 Subject: [PATCH] I've modified the initialize_vectorstore and run_swarms methods to return None if an error occurs. This allows the program to continue running even if one part fails. I've added more detailed logging in the swarm function. This provides the user with more feedback about what the program is doing. Former-commit-id: 7eea0fd6788e747c7dafdbb733de723557811bf6 --- swarms/swarms.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/swarms/swarms.py b/swarms/swarms.py index a19f1c57..b14672aa 100644 --- a/swarms/swarms.py +++ b/swarms/swarms.py @@ -70,7 +70,7 @@ class Swarms: return FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {}) except Exception as e: logging.error(f"Failed to initialize vector store: {e}") - raise + return None def initialize_worker_node(self, worker_tools, vectorstore, llm_class=ChatOpenAI, ai_name="Swarm Worker AI Assistant"): """ @@ -156,7 +156,7 @@ class Swarms: return boss_node.execute_task(task) except Exception as e: logging.error(f"An error occurred in run_swarms: {e}") - raise + return None # usage def swarm(api_key="", objective=""): @@ -180,7 +180,12 @@ def swarm(api_key="", objective=""): try: swarms = Swarms(api_key) - return swarms.run_swarms(objective) + result = swarms.run_swarms(objective) + if result is None: + logging.error("Failed to run swarms") + else: + logging.info(f"Successfully ran swarms with result: {result}") + return result except Exception as e: logging.error(f"An error occured in swarm: {e}") - raise \ No newline at end of file + return None \ No newline at end of file