From 9ebb51aa947da1b98d47781c865ac8d05f0f4ce0 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 27 Jul 2023 21:02:38 -0400 Subject: [PATCH] clean up Former-commit-id: ec8b8be28d02efe68e334a7a28b2cbad9c42f69f --- README.md | 2 +- swarms/agents/prompts/chains/llm.py | 2 +- .../agents/tools/core/code_interpreter/main.py | 7 ++----- swarms/agents/utils/Agent.py | 5 ++--- swarms/agents/utils/Calback.py | 5 +++-- swarms/agents/utils/ChatOpenAI.py | 8 +++----- swarms/agents/utils/ConversationalChatAgent.py | 16 +++++----------- swarms/agents/utils/agent_setup.py | 14 ++++++-------- swarms/workers/generative_worker.py | 8 +++----- 9 files changed, 26 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 66a4d56c..8c90ea49 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Swarming AI Agents (Swarms) +## Swarms of Autonomous AI Agents ![Swarming banner](images/swarms.png) diff --git a/swarms/agents/prompts/chains/llm.py b/swarms/agents/prompts/chains/llm.py index a6eba984..b9a5fea3 100644 --- a/swarms/agents/prompts/chains/llm.py +++ b/swarms/agents/prompts/chains/llm.py @@ -24,7 +24,7 @@ from langchain.schema import ( NoOpOutputParser, PromptValue, ) -from langchain.schema.language_model import BaseLanguageModel +from langchain.base_language import BaseLanguageModel class LLMChain(Chain): diff --git a/swarms/agents/tools/core/code_interpreter/main.py b/swarms/agents/tools/core/code_interpreter/main.py index 6fc0fd09..efaa29a5 100644 --- a/swarms/agents/tools/core/code_interpreter/main.py +++ b/swarms/agents/tools/core/code_interpreter/main.py @@ -7,8 +7,6 @@ from dataclasses import dataclass from io import BytesIO from typing import Any, List, Optional, Sequence, Tuple, Union -from pydantic import BaseModel, BaseSettings, root_validator - from langchain.agents import AgentExecutor, BaseSingleActionAgent from langchain.base_language import BaseLanguageModel from langchain.callbacks import AsyncIteratorCallbackHandler @@ -36,8 +34,7 @@ from langchain.schema import ( ) from langchain.tools import BaseTool, StructuredTool from langchain.tools.convert_to_openai import format_tool_to_openai_function - - +from pydantic import BaseModel, BaseSettings, root_validator remove_dl_link_prompt = ChatPromptTemplate( input_variables=["input_response"], @@ -295,7 +292,7 @@ class File(BaseModel): return f"File(name={self.name})" -from langchain.schema import HumanMessage, AIMessage # type: ignore +from langchain.schema import AIMessage, HumanMessage # type: ignore class UserRequest(HumanMessage): diff --git a/swarms/agents/utils/Agent.py b/swarms/agents/utils/Agent.py index 6bb035b9..18eefb64 100644 --- a/swarms/agents/utils/Agent.py +++ b/swarms/agents/utils/Agent.py @@ -8,9 +8,8 @@ from pathlib import Path from typing import Any, Dict, List, Optional, Sequence, Tuple, Union import yaml -from pydantic import BaseModel, root_validator - from langchain.agents.agent_types import AgentType +from langchain.base_language import BaseLanguageModel from langchain.callbacks.base import BaseCallbackManager from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, @@ -26,9 +25,9 @@ from langchain.schema import ( BaseOutputParser, BasePromptTemplate, ) -from langchain.schema.language_model import BaseLanguageModel from langchain.schema.messages import BaseMessage from langchain.tools.base import BaseTool +from pydantic import BaseModel, root_validator logger = logging.getLogger(__name__) diff --git a/swarms/agents/utils/Calback.py b/swarms/agents/utils/Calback.py index 174ac5a9..f840b6be 100644 --- a/swarms/agents/utils/Calback.py +++ b/swarms/agents/utils/Calback.py @@ -1,12 +1,13 @@ from typing import Any, Dict, List, Optional, Union +from celery import Task from langchain.callbacks.base import BaseCallbackHandler from langchain.schema import AgentAction, AgentFinish, LLMResult -from celery import Task + +from swarms.utils.logger import logger # from ansi import ANSI, Color, Style, dim_multiline from swarms.utils.main import ANSI, Color, Style, dim_multiline -from swarms.utils.logger import logger class EVALCallbackHandler(BaseCallbackHandler): diff --git a/swarms/agents/utils/ChatOpenAI.py b/swarms/agents/utils/ChatOpenAI.py index a6775c38..97b6fd3a 100644 --- a/swarms/agents/utils/ChatOpenAI.py +++ b/swarms/agents/utils/ChatOpenAI.py @@ -1,13 +1,12 @@ """OpenAI chat wrapper.""" from __future__ import annotations -import os import logging +import os import sys from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple import openai - from langchain.chat_models.base import BaseChatModel from langchain.schema import ( AIMessage, @@ -18,9 +17,7 @@ from langchain.schema import ( HumanMessage, SystemMessage, ) - from langchain.utils import get_from_dict_or_env -from swarms.utils.logger import logger from pydantic import BaseModel, Extra, Field, root_validator from tenacity import ( before_sleep_log, @@ -30,10 +27,11 @@ from tenacity import ( wait_exponential, ) +from swarms.utils.logger import logger # from ansi import ANSI, Color, Style from swarms.utils.main import ANSI, Color, Style -import os + def _create_retry_decorator(llm: ChatOpenAI) -> Callable[[Any], Any]: import openai diff --git a/swarms/agents/utils/ConversationalChatAgent.py b/swarms/agents/utils/ConversationalChatAgent.py index fe0bac15..981c3815 100644 --- a/swarms/agents/utils/ConversationalChatAgent.py +++ b/swarms/agents/utils/ConversationalChatAgent.py @@ -1,10 +1,10 @@ -from typing import Any, List, Optional, Sequence, Tuple import logging +from typing import Any, List, Optional, Sequence, Tuple -from swarms.agents.utils.Agent import Agent +from langchain.agents.agent import AgentOutputParser +from langchain.base_language import BaseLanguageModel from langchain.callbacks.base import BaseCallbackManager from langchain.chains import LLMChain -from langchain.schema import BaseOutputParser from langchain.prompts.base import BasePromptTemplate from langchain.prompts.chat import ( ChatPromptTemplate, @@ -15,20 +15,14 @@ from langchain.prompts.chat import ( from langchain.schema import ( AgentAction, AIMessage, - BaseLanguageModel, BaseMessage, + BaseOutputParser, HumanMessage, ) from langchain.tools.base import BaseTool - -from langchain.agents.agent import AgentOutputParser -from langchain.schema import AgentAction - - from swarms.agents.prompts.prompts import EVAL_TOOL_RESPONSE - - +from swarms.agents.utils.Agent import Agent logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') diff --git a/swarms/agents/utils/agent_setup.py b/swarms/agents/utils/agent_setup.py index 7fc9d318..2e71cf27 100644 --- a/swarms/agents/utils/agent_setup.py +++ b/swarms/agents/utils/agent_setup.py @@ -1,21 +1,19 @@ import os -from swarms.agents.prompts.prompts import EVAL_PREFIX, EVAL_SUFFIX -from swarms.agents.tools.main import BaseToolSet -from swarms.agents.tools.main import ToolsFactory - +from langchain.callbacks.base import BaseCallbackManager +# from .ChatOpenAI import ChatOpenAI +from langchain.chat_models import ChatOpenAI from langchain.chat_models.base import BaseChatModel from langchain.schema import BaseOutputParser -from langchain.callbacks.base import BaseCallbackManager + +from swarms.agents.prompts.prompts import EVAL_PREFIX, EVAL_SUFFIX +from swarms.agents.tools.main import BaseToolSet, ToolsFactory from .ConversationalChatAgent import ConversationalChatAgent -# from .ChatOpenAI import ChatOpenAI -from langchain.chat_models import ChatOpenAI from .output_parser import EvalOutputParser - class AgentSetup: def __init__(self, toolsets: list[BaseToolSet] = [], openai_api_key: str = None, serpapi_api_key: str = None, bing_search_url: str = None, bing_subscription_key: str = None): self.llm: BaseChatModel = None diff --git a/swarms/workers/generative_worker.py b/swarms/workers/generative_worker.py index 917b424b..1ccb5dae 100644 --- a/swarms/workers/generative_worker.py +++ b/swarms/workers/generative_worker.py @@ -3,16 +3,14 @@ import re from datetime import datetime from typing import Any, Dict, List, Optional +from langchain import LLMChain +from langchain.base_language import BaseLanguageModel + ############ from langchain.prompts import PromptTemplate from langchain.retrievers import TimeWeightedVectorStoreRetriever from langchain.schema import BaseMemory, Document - -from langchain.schema.language_model import BaseLanguageModel from langchain.utils import mock_now -from langchain import LLMChain -from langchain.schema.language_model import BaseLanguageModel - logger = logging.getLogger(__name__)