diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index aa11856d..00000000 --- a/Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ - -# ================================== -# Use an official Python runtime as a parent image -FROM python:3.9-slim - -# Set environment variables -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -# Set the working directory in the container -WORKDIR /usr/src/swarm_cloud - - -# Install Python dependencies -# COPY requirements.txt and pyproject.toml if you're using poetry for dependency management -COPY requirements.txt . -RUN pip install --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt - -# Install the 'swarms' package, assuming it's available on PyPI -RUN pip install swarms - -# Copy the rest of the application -COPY . . - -# Add entrypoint script if needed -# COPY ./entrypoint.sh . -# RUN chmod +x /usr/src/swarm_cloud/entrypoint.sh - -# Expose port if your application has a web interface -# EXPOSE 5000 - -# # Define environment variable for the swarm to work -# ENV SWARM_API_KEY=your_swarm_api_key_here - -# # Add Docker CMD or ENTRYPOINT script to run the application -# CMD python your_swarm_startup_script.py -# Or use the entrypoint script if you have one -# ENTRYPOINT ["/usr/src/swarm_cloud/entrypoint.sh"] - -# If you're using `CMD` to execute a Python script, make sure it's executable -# RUN chmod +x your_swarm_startup_script.py diff --git a/example.py b/example.py index 6ed2cbab..4ee4e7c4 100644 --- a/example.py +++ b/example.py @@ -17,6 +17,7 @@ llm = OpenAIChat( temperature=0.5, model_name="gpt-4", openai_api_key=api_key, + max_tokens=1000, ) diff --git a/playground/demos/accountant_team/accountant_team.py b/playground/demos/accountant_team/accountant_team.py deleted file mode 100644 index fccd628b..00000000 --- a/playground/demos/accountant_team/accountant_team.py +++ /dev/null @@ -1,125 +0,0 @@ -import os -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 Agent -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 = Agent( - llm=llm1, - sop=DOC_ANALYZER_AGENT_PROMPT, -) -summary_generator_agent = Agent( - llm=llm2, - sop=SUMMARY_GENERATOR_AGENT_PROMPT, -) -decision_making_support_agent = Agent( - llm=llm2, - sop=DECISION_MAKING_PROMPT, -) - - -class AccountantSwarms: - """ - Accountant Swarms is a collection of agents that work together to help - accountants with their work. - - Agent: analyze doc -> detect fraud -> generate summary -> decision making support - - The agents are: - - User Consultant: Asks the user many questions - - Document Analyzer: Extracts text from the image of the financial document - - Fraud Detection: Detects fraud in the document - - Summary Agent: Generates an actionable summary of the document - - Decision Making Support: Provides decision making support to the accountant - - The agents are connected together in a workflow that is defined in the - run method. - - The workflow is as follows: - 1. The Document Analyzer agent extracts text from the image of the - financial document. - 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 - - """ - - def __init__( - self, - pdf_path: str, - list_pdfs: List[str] = None, - fraud_detection_instructions: str = None, - summary_agent_instructions: str = None, - decision_making_support_agent_instructions: str = None, - ): - super().__init__() - self.pdf_path = pdf_path - self.list_pdfs = list_pdfs - self.fraud_detection_instructions = ( - fraud_detection_instructions - ) - self.summary_agent_instructions = summary_agent_instructions - self.decision_making_support_agent_instructions = ( - decision_making_support_agent_instructions - ) - - def run(self): - # Transform the pdf to text - pdf_text = pdf_to_text(self.pdf_path) - - # Detect fraud in the document - 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 = summary_generator_agent.run( - f"{self.summary_agent_instructions}:" - f" {fraud_detection_agent_output}" - ) - - # Provide decision making support to the accountant - decision_making_support_agent_output = decision_making_support_agent.run( - f"{self.decision_making_support_agent_instructions}:" - f" {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/accountant_team/bank_statement_2.jpg b/playground/demos/accountant_team/bank_statement_2.jpg deleted file mode 100644 index dbc8a4e9..00000000 Binary files a/playground/demos/accountant_team/bank_statement_2.jpg and /dev/null differ diff --git a/playground/demos/logistics/logistics.py b/playground/demos/logistics/logistics.py index 6a05d304..fefe78d3 100644 --- a/playground/demos/logistics/logistics.py +++ b/playground/demos/logistics/logistics.py @@ -11,50 +11,67 @@ from swarms.prompts.logistics import ( Sustainability_Agent_Prompt, Efficiency_Agent_Prompt, ) +# from swarms.utils.phoenix_handler import phoenix_trace_decorator +# from swarms.utils.banana_wrapper import banana load_dotenv() api_key = os.getenv("OPENAI_API_KEY") +# GPT4VisionAPI or llama +# @banana #- deploy to banana llm = GPT4VisionAPI(openai_api_key=api_key) # Image for analysis factory_image = "factory_image1.jpg" # Initialize agents with respective prompts +# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") health_security_agent = Agent( llm=llm, sop=Health_Security_Agent_Prompt, - max_loops=3, + max_loops=1, multi_modal=True, ) + +#@phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") quality_control_agent = Agent( llm=llm, sop=Quality_Control_Agent_Prompt, - max_loops=3, + max_loops=1, multi_modal=True, ) + +#@phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") productivity_agent = Agent( llm=llm, sop=Productivity_Agent_Prompt, - max_loops=3, + max_loops=1, multi_modal=True, ) + +#@phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") safety_agent = Agent( - llm=llm, sop=Safety_Agent_Prompt, max_loops=3, multi_modal=True + llm=llm, sop=Safety_Agent_Prompt, max_loops=1, multi_modal=True ) + +#@phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") security_agent = Agent( - llm=llm, sop=Security_Agent_Prompt, max_loops=3, multi_modal=True + llm=llm, sop=Security_Agent_Prompt, max_loops=1, multi_modal=True ) + +#@phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") sustainability_agent = Agent( llm=llm, sop=Sustainability_Agent_Prompt, - max_loops=3, + max_loops=1, multi_modal=True, ) + +#@phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") efficiency_agent = Agent( llm=llm, sop=Efficiency_Agent_Prompt, - max_loops=3, + max_loops=1, multi_modal=True, ) diff --git a/playground/demos/optimize_llm_stack/vortex.py b/playground/demos/optimize_llm_stack/vortex.py index 25756a81..5f48b2b6 100644 --- a/playground/demos/optimize_llm_stack/vortex.py +++ b/playground/demos/optimize_llm_stack/vortex.py @@ -5,9 +5,8 @@ from dotenv import load_dotenv from swarms.models import OpenAIChat from swarms.structs import Agent -from swarms.utils.phoenix_handler import phoenix_trace_decorator - -import modal +# from swarms.utils.phoenix_handler import phoenix_trace_decorator +# import modal load_dotenv() @@ -15,22 +14,23 @@ load_dotenv() llm = OpenAIChat( openai_api_key=os.getenv("OPENAI_API_KEY"), model_name="gpt-4", - max_tokens=4000, + max_tokens=1000, ) # Modal -stub = modal.Stub(name="swarms") +# stub = modal.Stub(name="swarms") # Agent -@phoenix_trace_decorator( - "This function is an agent and is traced by Phoenix." +# @phoenix_trace_decorator( +# "This function is an agent and is traced by Phoenix." +# ) +# @stub.function(gpu="any") +agent = Agent( + llm=llm, + max_loops=2, + autosave=True, + dashboard=True, ) -@stub.function(gpu="any") -def agent(task: str): - agent = Agent( - llm=llm, - max_loops=1, - ) - out = agent.run(task=task) - return out +out = agent.run("Generate a 5,000 word blog on how swarms of autonomous agents can be used to solve the world's problems.") +print(out) \ No newline at end of file diff --git a/playground/demos/swarm_of_mma_manufacturing/main.py b/playground/demos/swarm_of_mma_manufacturing/main.py index 05b0e8e5..37938608 100644 --- a/playground/demos/swarm_of_mma_manufacturing/main.py +++ b/playground/demos/swarm_of_mma_manufacturing/main.py @@ -20,6 +20,7 @@ from termcolor import colored from swarms.models import GPT4VisionAPI from swarms.structs import Agent +from swarms.utils.phoenix_handler import phoenix_trace_decorator load_dotenv() api_key = os.getenv("OPENAI_API_KEY") diff --git a/pyproject.toml b/pyproject.toml index 26cf54ac..09c00e12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "2.6.7" +version = "2.7.0" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] @@ -33,6 +33,7 @@ einops = "*" google-generativeai = "*" langchain-experimental = "*" playwright = "*" +weaviate-client = "*" duckduckgo-search = "*" opencv-python-headless = "*" faiss-cpu = "*" @@ -42,9 +43,11 @@ datasets = "*" optimum = "*" diffusers = "*" PyPDF2 = "*" +vllm = "*" accelerate = "*" sentencepiece = "*" wget = "*" +arize-phoenix = "*" tensorflow = "*" httpx = "*" tiktoken = "*" @@ -94,8 +97,3 @@ target-version = ['py38'] preview = true -[tool.poetry.scripts] -swarms = "swarms.cli.run_file:run_file" - - - diff --git a/requirements.txt b/requirements.txt index d256291e..e33a7438 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,11 +19,14 @@ attrs datasets pydantic==1.10.12 soundfile +arize-phoenix +weaviate-client huggingface-hub google-generativeai sentencepiece PyPDF2 accelerate +vllm chromadb tensorflow optimum diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index 539d849b..caccc7ab 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -8,11 +8,7 @@ from swarms.models.openai_models import ( AzureOpenAI, OpenAIChat, ) # noqa: E402 - -# try: -# from swarms.models.vllm import vLLM # noqa: E402 -# except ImportError: -# pass +from swarms.models.vllm import vLLM # noqa: E402 # from swarms.models.zephyr import Zephyr # noqa: E402 from swarms.models.biogpt import BioGPT # noqa: E402 @@ -64,5 +60,5 @@ __all__ = [ # "Dalle3", # "DistilWhisperModel", "GPT4VisionAPI", - # "vLLM", + "vLLM", ] diff --git a/swarms/structs/agent.py b/swarms/structs/agent.py index 2ce86479..ac5f2413 100644 --- a/swarms/structs/agent.py +++ b/swarms/structs/agent.py @@ -583,7 +583,10 @@ class Agent: return agent_system_prompt_2(self.agent_name) def run( - self, task: Optional[str], img: Optional[str] = None, **kwargs + self, + task: Optional[str] = None, + img: Optional[str] = None, + **kwargs ): """ Run the autonomous agent loop @@ -639,9 +642,9 @@ class Agent: AGENT_SYSTEM_PROMPT_3, response ) - # Retreiving long term memory - if self.memory: - task = self.agent_memory_prompt(response, task) + # # Retreiving long term memory + # if self.memory: + # task = self.agent_memory_prompt(response, task) attempt = 0 while attempt < self.retry_attempts: @@ -652,11 +655,13 @@ class Agent: img, **kwargs, ) + print(response) else: response = self.llm( task, **kwargs, ) + print(response) # If code interpreter is enabled then run the code if self.code_interpreter: diff --git a/swarms/utils/__init__.py b/swarms/utils/__init__.py index 7dadd2f7..b858d291 100644 --- a/swarms/utils/__init__.py +++ b/swarms/utils/__init__.py @@ -1,14 +1,10 @@ -from swarms.utils.markdown_message import display_markdown_message from swarms.utils.code_interpreter import SubprocessCodeInterpreter +from swarms.utils.markdown_message import display_markdown_message from swarms.utils.parse_code import ( extract_code_in_backticks_in_string, ) from swarms.utils.pdf_to_text import pdf_to_text - -try: - from swarms.utils.phoenix_handler import phoenix_trace_decorator -except ImportError: - pass +from swarms.utils.phoenix_handler import phoenix_trace_decorator __all__ = [ "display_markdown_message", diff --git a/swarms/utils/phoenix_handler.py b/swarms/utils/phoenix_handler.py index 641e01cf..329d3f2a 100644 --- a/swarms/utils/phoenix_handler.py +++ b/swarms/utils/phoenix_handler.py @@ -1,8 +1,5 @@ -import subprocess -import sys -import traceback import functools - +import traceback import phoenix as px