From 4cde6b563c5f2dd2196e0fc3ef159c29f2786d9a Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 17 Aug 2023 01:22:13 -0400 Subject: [PATCH] clean up swarms Former-commit-id: 3aeb7b96ae2d83328e4bd6891005fdd157bac686 --- pyproject.toml | 2 +- setup.py | 2 +- swarms/__init__.py | 4 ++-- swarms/agents/base.py | 6 +++--- swarms/agents/memory.py | 2 +- swarms/agents/models/huggingface.py | 3 +++ swarms/workers/worker_node.py | 16 ++++++++-------- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5b8609c4..563e47cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "1.4.0" +version = "1.4.3" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/setup.py b/setup.py index dfa36d1a..454438a1 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup( name = 'swarms', packages = find_packages(exclude=[]), - version = '1.3.3', + version = '1.4.1', license='MIT', description = 'Swarms - Pytorch', author = 'Kye Gomez', diff --git a/swarms/__init__.py b/swarms/__init__.py index 07500191..6fcb0b7f 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -1,10 +1,10 @@ #swarms # worker -from swarms.workers.worker_node import WorkerNode +# from swarms.workers.worker_node import WorkerNode #boss -from swarms.boss.boss_node import BossNode +# from swarms.boss.boss_node import BossNode #models from swarms.agents.models.anthropic import Anthropic diff --git a/swarms/agents/base.py b/swarms/agents/base.py index 056254f0..0e85f024 100644 --- a/swarms/agents/base.py +++ b/swarms/agents/base.py @@ -4,7 +4,7 @@ from typing import List, Optional from langchain.chains.llm import LLMChain -from pydantic import ValidationError +# from pydantic import ValidationError from swarms.agents.memory.base import VectorStoreRetriever from swarms.agents.memory.base_memory import BaseChatMessageHistory, ChatMessageHistory @@ -106,9 +106,9 @@ class Agent: tool = tools[action.name] try: observation = tool.run(action.args) - except ValidationError as e: + except Exception as error: observation = ( - f"Validation Error in args: {str(e)}, args: {action.args}" + f"Validation Error in args: {str(error)}, args: {action.args}" ) except Exception as e: observation = ( diff --git a/swarms/agents/memory.py b/swarms/agents/memory.py index 493e151c..4511a1fb 100644 --- a/swarms/agents/memory.py +++ b/swarms/agents/memory.py @@ -1,5 +1,5 @@ from typing import Any, Dict, List -from pydantic import Field +# from pydantic import Field from swarms.agents.memory.base_memory import BaseChatMemory, get_prompt_input_key from swarms.agents.memory.base import VectorStoreRetriever diff --git a/swarms/agents/models/huggingface.py b/swarms/agents/models/huggingface.py index 8f1cf5cc..f43c76e5 100644 --- a/swarms/agents/models/huggingface.py +++ b/swarms/agents/models/huggingface.py @@ -50,3 +50,6 @@ class HuggingFaceLLM: except Exception as e: self.logger.error(f"Failed to generate the text: {e}") raise + + + diff --git a/swarms/workers/worker_node.py b/swarms/workers/worker_node.py index 98991fe7..1c02d193 100644 --- a/swarms/workers/worker_node.py +++ b/swarms/workers/worker_node.py @@ -1,8 +1,8 @@ import logging -from typing import List, Optional, Union +from typing import List, Optional, Union, Any import faiss -# from langchain.agents import Tool +from langchain.agents import Tool from langchain.chat_models import ChatOpenAI from langchain.docstore import InMemoryDocstore from langchain.embeddings import OpenAIEmbeddings @@ -39,7 +39,7 @@ class WorkerNodeInitializer: def __init__(self, openai_api_key: str, llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None, - tools: Optional[List[Tool]] = None, + tools: Optional[List[Any]] = None, embedding_size: Optional[int] = 8192, worker_name: Optional[str] = "Swarm Worker AI Assistant", worker_role: Optional[str] = "Assistant", @@ -119,14 +119,13 @@ class WorkerNodeInitializer: raise e -##################### class WorkerNode: def __init__(self, openai_api_key: str, temperature: Optional[int] = None, llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None, - tools: Optional[List[Tool]] = None, + tools: Optional[List[Any]] = None, embedding_size: Optional[int] = 8192, worker_name: Optional[str] = "Swarm Worker AI Assistant", worker_role: Optional[str] = "Assistant", @@ -170,7 +169,7 @@ class WorkerNode: logging.error(f"Error while creating agent: {str(e)}") raise e - def add_tool(self, tool: Optional[Tool] = None): + def add_tool(self, tool: Optional[Any] = None): if tool is None: tool = DuckDuckGoSearchRun() @@ -270,14 +269,15 @@ class WorkerNode: logging.error(f"Failed to create worker node: {e}") raise -def worker_node(openai_api_key): +def worker_node(openai_api_key, objective): if not openai_api_key: logging.error("OpenAI API key is not provided") raise ValueError("OpenAI API key is required") try: worker_node = WorkerNode(openai_api_key) - return worker_node.create_worker_node() + worker_node.create_worker_node() + return worker_node.run(objective) except Exception as e: logging.error(f"An error occured in worker_node: {e}") raise \ No newline at end of file