From 958d7a66d70d52109f801ffd4b776be857cd7d4e Mon Sep 17 00:00:00 2001 From: evelynmitchell Date: Sun, 4 Feb 2024 17:49:28 -0700 Subject: [PATCH] pylint simple_agent --- swarms/agents/simple_agent.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/swarms/agents/simple_agent.py b/swarms/agents/simple_agent.py index 757715dd..4224d08f 100644 --- a/swarms/agents/simple_agent.py +++ b/swarms/agents/simple_agent.py @@ -1,8 +1,10 @@ -from swarms.structs.conversation import Conversation -from swarms.models.base_llm import AbstractLLM from typing import Any import importlib import pkgutil + +from swarms.structs.conversation import Conversation +from swarms.models.base_llm import AbstractLLM + import swarms.models @@ -16,7 +18,7 @@ def get_llm_by_name(name: str): Returns: type: The class with the given name, or None if no such class is found. """ - for importer, modname, ispkg in pkgutil.iter_modules( + for importer, modname, ispkg in pkgutil.iter_modules( # noqa: W0612 swarms.models.__path__ ): module = importlib.import_module(f"swarms.models.{modname}") @@ -26,7 +28,7 @@ def get_llm_by_name(name: str): # Run the language model in a loop for n iterations -def SimpleAgent( +def SimpleAgent( #noqa: C0103 llm: AbstractLLM = None, iters: Any = "automatic", *args, **kwargs ): """ @@ -39,21 +41,21 @@ def SimpleAgent( **kwargs: Additional keyword arguments to pass to the language model. Raises: - Exception: If the language model is not defined or cannot be found. + AttributeError: If the language model is not defined or cannot be found. Returns: None """ try: if llm is None: - raise Exception("Language model not defined") + raise AttributeError("Language model not defined") if isinstance(llm, str): llm = get_llm_by_name(llm) if llm is None: - raise Exception(f"Language model {llm} not found") + raise AttributeError(f"Language model {llm} not found") llm = llm(*args, **kwargs) - except Exception as error: + except AttributeError as error: print(f"[ERROR][SimpleAgent] {error}") raise error @@ -98,7 +100,7 @@ def SimpleAgent( print(f"[ERROR][SimpleAgentConversation] {error}") raise error - except KeyboardInterrupt: + except KeyboardInterrupt as exc: print("[INFO][SimpleAgentConversation] Keyboard interrupt") conv.export_conversation("conversation.txt") - raise KeyboardInterrupt + raise KeyboardInterrupt from exc