clean up swarms

pull/53/head
Kye 1 year ago
parent e19b78cf60
commit 3aeb7b96ae

@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "1.4.0" version = "1.4.3"
description = "Swarms - Pytorch" description = "Swarms - Pytorch"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"] authors = ["Kye Gomez <kye@apac.ai>"]

@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup( setup(
name = 'swarms', name = 'swarms',
packages = find_packages(exclude=[]), packages = find_packages(exclude=[]),
version = '1.3.3', version = '1.4.1',
license='MIT', license='MIT',
description = 'Swarms - Pytorch', description = 'Swarms - Pytorch',
author = 'Kye Gomez', author = 'Kye Gomez',

@ -1,10 +1,10 @@
#swarms #swarms
# worker # worker
from swarms.workers.worker_node import WorkerNode # from swarms.workers.worker_node import WorkerNode
#boss #boss
from swarms.boss.boss_node import BossNode # from swarms.boss.boss_node import BossNode
#models #models
from swarms.agents.models.anthropic import Anthropic from swarms.agents.models.anthropic import Anthropic

@ -4,7 +4,7 @@ from typing import List, Optional
from langchain.chains.llm import LLMChain 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 import VectorStoreRetriever
from swarms.agents.memory.base_memory import BaseChatMessageHistory, ChatMessageHistory from swarms.agents.memory.base_memory import BaseChatMessageHistory, ChatMessageHistory
@ -106,9 +106,9 @@ class Agent:
tool = tools[action.name] tool = tools[action.name]
try: try:
observation = tool.run(action.args) observation = tool.run(action.args)
except ValidationError as e: except Exception as error:
observation = ( 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: except Exception as e:
observation = ( observation = (

@ -1,5 +1,5 @@
from typing import Any, Dict, List 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_memory import BaseChatMemory, get_prompt_input_key
from swarms.agents.memory.base import VectorStoreRetriever from swarms.agents.memory.base import VectorStoreRetriever

@ -50,3 +50,6 @@ class HuggingFaceLLM:
except Exception as e: except Exception as e:
self.logger.error(f"Failed to generate the text: {e}") self.logger.error(f"Failed to generate the text: {e}")
raise raise

@ -1,8 +1,8 @@
import logging import logging
from typing import List, Optional, Union from typing import List, Optional, Union, Any
import faiss import faiss
# from langchain.agents import Tool from langchain.agents import Tool
from langchain.chat_models import ChatOpenAI from langchain.chat_models import ChatOpenAI
from langchain.docstore import InMemoryDocstore from langchain.docstore import InMemoryDocstore
from langchain.embeddings import OpenAIEmbeddings from langchain.embeddings import OpenAIEmbeddings
@ -39,7 +39,7 @@ class WorkerNodeInitializer:
def __init__(self, def __init__(self,
openai_api_key: str, openai_api_key: str,
llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None, llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None,
tools: Optional[List[Tool]] = None, tools: Optional[List[Any]] = None,
embedding_size: Optional[int] = 8192, embedding_size: Optional[int] = 8192,
worker_name: Optional[str] = "Swarm Worker AI Assistant", worker_name: Optional[str] = "Swarm Worker AI Assistant",
worker_role: Optional[str] = "Assistant", worker_role: Optional[str] = "Assistant",
@ -119,14 +119,13 @@ class WorkerNodeInitializer:
raise e raise e
#####################
class WorkerNode: class WorkerNode:
def __init__(self, def __init__(self,
openai_api_key: str, openai_api_key: str,
temperature: Optional[int] = None, temperature: Optional[int] = None,
llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None, llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None,
tools: Optional[List[Tool]] = None, tools: Optional[List[Any]] = None,
embedding_size: Optional[int] = 8192, embedding_size: Optional[int] = 8192,
worker_name: Optional[str] = "Swarm Worker AI Assistant", worker_name: Optional[str] = "Swarm Worker AI Assistant",
worker_role: Optional[str] = "Assistant", worker_role: Optional[str] = "Assistant",
@ -170,7 +169,7 @@ class WorkerNode:
logging.error(f"Error while creating agent: {str(e)}") logging.error(f"Error while creating agent: {str(e)}")
raise e raise e
def add_tool(self, tool: Optional[Tool] = None): def add_tool(self, tool: Optional[Any] = None):
if tool is None: if tool is None:
tool = DuckDuckGoSearchRun() tool = DuckDuckGoSearchRun()
@ -270,14 +269,15 @@ class WorkerNode:
logging.error(f"Failed to create worker node: {e}") logging.error(f"Failed to create worker node: {e}")
raise raise
def worker_node(openai_api_key): def worker_node(openai_api_key, objective):
if not openai_api_key: if not openai_api_key:
logging.error("OpenAI API key is not provided") logging.error("OpenAI API key is not provided")
raise ValueError("OpenAI API key is required") raise ValueError("OpenAI API key is required")
try: try:
worker_node = WorkerNode(openai_api_key) 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: except Exception as e:
logging.error(f"An error occured in worker_node: {e}") logging.error(f"An error occured in worker_node: {e}")
raise raise
Loading…
Cancel
Save