pylint simple_agent

pull/377/head
evelynmitchell 1 year ago
parent e70acbaea5
commit 958d7a66d7

@ -1,8 +1,10 @@
from swarms.structs.conversation import Conversation
from swarms.models.base_llm import AbstractLLM
from typing import Any from typing import Any
import importlib import importlib
import pkgutil import pkgutil
from swarms.structs.conversation import Conversation
from swarms.models.base_llm import AbstractLLM
import swarms.models import swarms.models
@ -16,7 +18,7 @@ def get_llm_by_name(name: str):
Returns: Returns:
type: The class with the given name, or None if no such class is found. 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__ swarms.models.__path__
): ):
module = importlib.import_module(f"swarms.models.{modname}") 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 # Run the language model in a loop for n iterations
def SimpleAgent( def SimpleAgent( #noqa: C0103
llm: AbstractLLM = None, iters: Any = "automatic", *args, **kwargs llm: AbstractLLM = None, iters: Any = "automatic", *args, **kwargs
): ):
""" """
@ -39,21 +41,21 @@ def SimpleAgent(
**kwargs: Additional keyword arguments to pass to the language model. **kwargs: Additional keyword arguments to pass to the language model.
Raises: 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: Returns:
None None
""" """
try: try:
if llm is None: if llm is None:
raise Exception("Language model not defined") raise AttributeError("Language model not defined")
if isinstance(llm, str): if isinstance(llm, str):
llm = get_llm_by_name(llm) llm = get_llm_by_name(llm)
if llm is None: if llm is None:
raise Exception(f"Language model {llm} not found") raise AttributeError(f"Language model {llm} not found")
llm = llm(*args, **kwargs) llm = llm(*args, **kwargs)
except Exception as error: except AttributeError as error:
print(f"[ERROR][SimpleAgent] {error}") print(f"[ERROR][SimpleAgent] {error}")
raise error raise error
@ -98,7 +100,7 @@ def SimpleAgent(
print(f"[ERROR][SimpleAgentConversation] {error}") print(f"[ERROR][SimpleAgentConversation] {error}")
raise error raise error
except KeyboardInterrupt: except KeyboardInterrupt as exc:
print("[INFO][SimpleAgentConversation] Keyboard interrupt") print("[INFO][SimpleAgentConversation] Keyboard interrupt")
conv.export_conversation("conversation.txt") conv.export_conversation("conversation.txt")
raise KeyboardInterrupt raise KeyboardInterrupt from exc

Loading…
Cancel
Save