From 45f19a6a50175e7cfbc4aa4313798ce5ee996352 Mon Sep 17 00:00:00 2001 From: Kye Date: Fri, 6 Oct 2023 00:47:13 -0400 Subject: [PATCH] code quality --- README.md | 13 +++++++++++-- apps/discord.py | 1 - docs/old-docs/design/abstraction.py | 2 +- example.py | 8 ++++++-- playground/debate.py | 5 +---- playground/godmode.py | 2 +- swarms/__init__.py | 2 +- swarms/agents/__init__.py | 3 ++- swarms/agents/aot.py | 4 ++-- swarms/agents/multi_modal_visual_agent.py | 5 ----- swarms/agents/profitpilot.py | 2 -- swarms/boss/boss_node.py | 1 - swarms/models/__init__.py | 3 +++ swarms/models/huggingface.py | 1 - swarms/models/prompts/agent_prompt_auto.py | 2 +- swarms/models/prompts/debate.py | 8 +------- swarms/structs/__init__.py | 3 ++- swarms/swarms/__init__.py | 1 + swarms/swarms/god_mode.py | 5 ++++- swarms/swarms/multi_agent_debate.py | 3 ++- swarms/swarms/orchestrate.py | 4 ++-- swarms/tools/autogpt.py | 4 ---- swarms/tools/code_intepretor.py | 2 +- swarms/tools/stt.py | 4 ++-- swarms/workers/worker.py | 10 ---------- tests/agents/omni_modal.py | 10 ---------- 26 files changed, 44 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index d54424e3..5fe897e2 100644 --- a/README.md +++ b/README.md @@ -75,13 +75,22 @@ for result in results: - The `Worker` is an fully feature complete agent with an llm, tools, and a vectorstore for long term memory! ```python - +from langchain.models import ChatOpenAI from swarms import Worker +llm = ChatOpenAI( + model_name='gpt-4', + openai_api_key="api-key", + temperature=0.5 +) node = Worker( - openai_api_key="", + llm=llm, ai_name="Optimus Prime", + ai_role="Worker in a swarm", + external_tools = None, + human_in_the_loop = False, + temperature = 0.5, ) task = "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times." diff --git a/apps/discord.py b/apps/discord.py index b0b55860..e2c5ece5 100644 --- a/apps/discord.py +++ b/apps/discord.py @@ -1,4 +1,3 @@ -import discord from discord.ext import commands from langchain.llms import OpenAIChat from swarms.agents import OmniModalAgent diff --git a/docs/old-docs/design/abstraction.py b/docs/old-docs/design/abstraction.py index 34da37a9..c1d86c4d 100644 --- a/docs/old-docs/design/abstraction.py +++ b/docs/old-docs/design/abstraction.py @@ -1,4 +1,4 @@ -from swarms import Model, Agent, WorkerNode, vectorstore, tools, orchestrator +from swarms import Model, Agent, vectorstore, tools, orchestrator #1 model Model(openai) diff --git a/example.py b/example.py index d1e6fc05..cef271c6 100644 --- a/example.py +++ b/example.py @@ -1,7 +1,11 @@ -from langchain.models import OpenAIChat +from langchain.models import ChatOpenAI from swarms import Worker -llm = OpenAIChat() +llm = ChatOpenAI( + model_name='gpt-4', + openai_api_key="api-key", + temperature=0.5 +) node = Worker( llm=llm, diff --git a/playground/debate.py b/playground/debate.py index 43898ee4..60c799b4 100644 --- a/playground/debate.py +++ b/playground/debate.py @@ -1,5 +1,4 @@ -import re -from typing import Callable, Dict, List +from typing import Callable, List import numpy as np import tenacity @@ -7,8 +6,6 @@ from langchain.chat_models import ChatOpenAI from langchain.output_parsers import RegexParser from langchain.prompts import PromptTemplate from langchain.schema import ( - AIMessage, - BaseMessage, HumanMessage, SystemMessage, ) diff --git a/playground/godmode.py b/playground/godmode.py index e3f8d3f8..c6b987ad 100644 --- a/playground/godmode.py +++ b/playground/godmode.py @@ -15,6 +15,6 @@ llms = [ god_mode = GodMode(llms) -task = f"What are the biggest risks facing humanity?" +task = "What are the biggest risks facing humanity?" god_mode.print_responses(task) \ No newline at end of file diff --git a/swarms/__init__.py b/swarms/__init__.py index 935111db..f610356d 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -20,4 +20,4 @@ from swarms import swarms from swarms.swarms.orchestrate import Orchestrator #agents -from swarms import agents +from swarms import agents \ No newline at end of file diff --git a/swarms/agents/__init__.py b/swarms/agents/__init__.py index 19df6e15..06a5104d 100644 --- a/swarms/agents/__init__.py +++ b/swarms/agents/__init__.py @@ -1,3 +1,4 @@ + """Agent Infrastructure, models, memory, utils, tools""" #agents @@ -10,4 +11,4 @@ from swarms.agents.omni_modal_agent import OmniModalAgent #utils from swarms.agents.message import Message -from swarms.agents.stream_response import stream +from swarms.agents.stream_response import stream \ No newline at end of file diff --git a/swarms/agents/aot.py b/swarms/agents/aot.py index a9657cf0..daf31481 100644 --- a/swarms/agents/aot.py +++ b/swarms/agents/aot.py @@ -112,9 +112,9 @@ class OpenAI: rejected_solutions=None ): if (type(state) == str): - state_text = state + pass else: - state_text = '\n'.join(state) + '\n'.join(state) print("New state generating thought:", state, "\n\n") prompt = f""" Accomplish the task below by decomposing it as many very explicit subtasks as possible, be very explicit and thorough denoted by diff --git a/swarms/agents/multi_modal_visual_agent.py b/swarms/agents/multi_modal_visual_agent.py index 94d4f161..eeb88ad9 100644 --- a/swarms/agents/multi_modal_visual_agent.py +++ b/swarms/agents/multi_modal_visual_agent.py @@ -7,12 +7,8 @@ import uuid from PIL import Image, ImageDraw, ImageOps, ImageFont import math import numpy as np -import argparse import inspect -import tempfile -from transformers import CLIPSegProcessor, CLIPSegForImageSegmentation from transformers import pipeline, BlipProcessor, BlipForConditionalGeneration, BlipForQuestionAnswering -from transformers import AutoImageProcessor, UperNetForSemanticSegmentation from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline, StableDiffusionInstructPix2PixPipeline from diffusers import EulerAncestralDiscreteScheduler @@ -29,7 +25,6 @@ from langchain.llms.openai import OpenAI # Grounding DINO import groundingdino.datasets.transforms as T from groundingdino.models import build_model -from groundingdino.util import box_ops from groundingdino.util.slconfig import SLConfig from groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap diff --git a/swarms/agents/profitpilot.py b/swarms/agents/profitpilot.py index fd961b3a..243bd7aa 100644 --- a/swarms/agents/profitpilot.py +++ b/swarms/agents/profitpilot.py @@ -1,4 +1,3 @@ -import os import re from typing import Any, Callable, Dict, List, Union @@ -18,7 +17,6 @@ from langchain.vectorstores import Chroma from pydantic import BaseModel, Field from swarms.models.prompts.sales import SALES_AGENT_TOOLS_PROMPT, conversation_stages from swarms.tools.interpreter_tool import compile -from swarms.agents.omni_modal_agent import OmniModalAgent # classes diff --git a/swarms/boss/boss_node.py b/swarms/boss/boss_node.py index 4ee483b8..b1c48758 100644 --- a/swarms/boss/boss_node.py +++ b/swarms/boss/boss_node.py @@ -1,6 +1,5 @@ import logging import os -from typing import Optional import faiss from langchain import LLMChain, OpenAI, PromptTemplate diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index fe3d1aad..a943844d 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -1,3 +1,6 @@ +# from swarms.models.palm import GooglePalm +# from swarms.models.openai import OpenAIChat +#prompts from swarms.models.anthropic import Anthropic # from swarms.models.palm import GooglePalm from swarms.models.petals import Petals diff --git a/swarms/models/huggingface.py b/swarms/models/huggingface.py index 6192201f..e69de29b 100644 --- a/swarms/models/huggingface.py +++ b/swarms/models/huggingface.py @@ -1 +0,0 @@ -from exa import Inference, GPTQInference, MultiModalInference \ No newline at end of file diff --git a/swarms/models/prompts/agent_prompt_auto.py b/swarms/models/prompts/agent_prompt_auto.py index 3a901e6b..a2e860af 100644 --- a/swarms/models/prompts/agent_prompt_auto.py +++ b/swarms/models/prompts/agent_prompt_auto.py @@ -1,5 +1,5 @@ import time -from typing import Any, Callable, List +from typing import Any, List from swarms.models.prompts.agent_prompt_generator import get_prompt class TokenUtils: diff --git a/swarms/models/prompts/debate.py b/swarms/models/prompts/debate.py index a1c6b224..85bdfd00 100644 --- a/swarms/models/prompts/debate.py +++ b/swarms/models/prompts/debate.py @@ -38,10 +38,4 @@ def debate_monitor(game_description, word_limit, character_names): def generate_character_header(game_description, topic, character_name, character_description): - prompt = f"""{game_description} - Your name is {character_name}. - You are a presidential candidate. - Your description is as follows: {character_description} - You are debating the topic: {topic}. - Your goal is to be as creative as possible and make the voters think you are the best candidate. - """ + pass diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index 9344c3a0..4da656ff 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -1,3 +1,4 @@ #structs +#structs from swarms.structs.workflow import Workflow -from swarms.structs.task import Task \ No newline at end of file +from swarms.structs.task import Task diff --git a/swarms/swarms/__init__.py b/swarms/swarms/__init__.py index 0d4f85e9..524cd652 100644 --- a/swarms/swarms/__init__.py +++ b/swarms/swarms/__init__.py @@ -1,4 +1,5 @@ # swarms +# swarms from swarms.swarms.dialogue_simulator import DialogueSimulator from swarms.swarms.autoscaler import AutoScaler from swarms.swarms.orchestrate import Orchestrator diff --git a/swarms/swarms/god_mode.py b/swarms/swarms/god_mode.py index 5fa34845..7b69a839 100644 --- a/swarms/swarms/god_mode.py +++ b/swarms/swarms/god_mode.py @@ -29,7 +29,10 @@ class GodMode: """ - def __init__(self, llms): + def __init__( + self, + llms + ): self.llms = llms def run(self, task): diff --git a/swarms/swarms/multi_agent_debate.py b/swarms/swarms/multi_agent_debate.py index 3ce257df..d9cb5e73 100644 --- a/swarms/swarms/multi_agent_debate.py +++ b/swarms/swarms/multi_agent_debate.py @@ -7,11 +7,12 @@ def select_speaker(step: int, agents: List[Worker]) -> int: # This function selects the speaker in a round-robin fashion return step % len(agents) - class MultiAgentDebate: """ MultiAgentDebate + Args: + """ def __init__( diff --git a/swarms/swarms/orchestrate.py b/swarms/swarms/orchestrate.py index 083a8f7b..a00f8dbd 100644 --- a/swarms/swarms/orchestrate.py +++ b/swarms/swarms/orchestrate.py @@ -281,13 +281,13 @@ class Orchestrator: ) #store the mesage in the vector database - added = self.collection.add( + self.collection.add( embeddings=[message_vector], documents=[message], ids=[f"{sender_id}_to_{receiver_id}"] ) - result = self.run( + self.run( objective=f"chat with agent {receiver_id} about {message}" ) diff --git a/swarms/tools/autogpt.py b/swarms/tools/autogpt.py index 33582a06..735b4e0b 100644 --- a/swarms/tools/autogpt.py +++ b/swarms/tools/autogpt.py @@ -8,17 +8,13 @@ from typing import Optional import pandas as pd from langchain.agents import tool from langchain.agents.agent_toolkits.pandas.base import create_pandas_dataframe_agent -from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain from langchain.docstore.document import Document ROOT_DIR = "./data/" from langchain.chains.qa_with_sources.loading import BaseCombineDocumentsChain -from langchain.chat_models import ChatOpenAI from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.tools import BaseTool -from langchain.tools.file_management.read import ReadFileTool -from langchain.tools.file_management.write import WriteFileTool from pydantic import Field from swarms.utils.logger import logger diff --git a/swarms/tools/code_intepretor.py b/swarms/tools/code_intepretor.py index 5af3e46a..62887bab 100644 --- a/swarms/tools/code_intepretor.py +++ b/swarms/tools/code_intepretor.py @@ -1,6 +1,6 @@ #props to shroominic from swarms.tools.base import Tool, ToolException -from typing import Callable, Any, List +from typing import Any, List from codeinterpreterapi import CodeInterpreterSession, File, ToolException class CodeInterpreter(Tool): diff --git a/swarms/tools/stt.py b/swarms/tools/stt.py index 65b12306..399bb516 100644 --- a/swarms/tools/stt.py +++ b/swarms/tools/stt.py @@ -75,7 +75,7 @@ class SpeechToText: use_auth_token=self.hf_api_key, device=device ) - diarize_segments = diarize_model(audio_file) + diarize_model(audio_file) try: segments = result["segments"] @@ -113,7 +113,7 @@ class SpeechToText: device=self.device ) - diarize_segments = diarize_model(audio_file) + diarize_model(audio_file) try: segments = result["segments"] diff --git a/swarms/workers/worker.py b/swarms/workers/worker.py index fd97e5de..e01866e1 100644 --- a/swarms/workers/worker.py +++ b/swarms/workers/worker.py @@ -17,16 +17,9 @@ from swarms.tools.autogpt import ( ) from swarms.utils.decorators import error_decorator, log_decorator, timing_decorator -# self.llm = ChatOpenAI( -# model_name=model_name, -# openai_api_key=self.openai_api_key, -# temperature=self.temperature -# ) - #cache ROOT_DIR = "./data/" - #main class Worker: """ @@ -79,9 +72,6 @@ class Worker: self.setup_tools(external_tools) self.setup_memory() self.setup_agent() - - # self.task_queue = [] - # self.executor = concurrent.futures.ThreadPoolExecutor() def reset(self): """ diff --git a/tests/agents/omni_modal.py b/tests/agents/omni_modal.py index 3c3c79df..1407f261 100644 --- a/tests/agents/omni_modal.py +++ b/tests/agents/omni_modal.py @@ -1,15 +1,5 @@ import pytest from langchain.base_language import BaseLanguageModel -from langchain_experimental.autonomous_agents.hugginggpt.repsonse_generator import ( - load_response_generator, -) -from langchain_experimental.autonomous_agents.hugginggpt.task_executor import ( - TaskExecutor, -) -from langchain_experimental.autonomous_agents.hugginggpt.task_planner import ( - load_chat_planner, -) -from transformers import load_tool from swarms.agents import ( OmniModalAgent, # Replace `your_module_name` with the appropriate module name