Skip to content

Commit

Permalink
Merge pull request #1094 from MichaelDecent/cleanup
Browse files Browse the repository at this point in the history
Refactor tool registration in community packages
  • Loading branch information
cobycloud authored Jan 15, 2025
2 parents fa21fb1 + 73f05ac commit 5feda25
Show file tree
Hide file tree
Showing 63 changed files with 203 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
asyncio_default_fixture_loop_scope = "function"

[tool.poetry.plugins."swarmauri.llms"]
LeptonAIModel = "swarmauri_llm_communityleptonai.LeptonAIImgGenModel:LeptonAIModel"

[tool.poetry.plugins."swarmauri.image_gens"]
LeptonAIImgGenModel = "swarmauri_llm_communityleptonai.LeptonAIImgGenModel:LeptonAIImgGenModel"
LeptonAIModel = "swarmauri_llm_communityleptonai.LeptonAIImgGenModel:LeptonAIModel"
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from io import BytesIO
from PIL import Image
from typing import List, Literal
from swarmauri_base.image_gens.ImageGenBase import ImageGenBase
from pydantic import Field, ConfigDict
from swarmauri_base.llms.LLMBase import LLMBase
from swarmauri_core.ComponentBase import ComponentBase


class LeptonAIImgGenModel(LLMBase):
@ComponentBase.register_type(ImageGenBase, "LeptonAIImgGenModel")
class LeptonAIImgGenModel(ImageGenBase):
"""
A model for generating images from text using Lepton AI's SDXL image generation model.
It returns the image as bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

from swarmauri_standard.messages.AgentMessage import AgentMessage, UsageData
from swarmauri.utils.duration_manager import DurationManager
from swarmauri_core.ComponentBase import ComponentBase


@ComponentBase.register_type(LLMBase, "LeptonAIModel")
class LeptonAIModel(LLMBase):
"""
Provider resources: https://www.lepton.ai/playground
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os
import asyncio
from typing import List, Literal, Union
from swarmauri_core.ComponentBase import ComponentBase
from pydantic import Field, ConfigDict
from PIL import Image
import pytesseract
from io import BytesIO
from swarmauri_base.llms.LLMBase import LLMBase


@ComponentBase.register_type(LLMBase, "PytesseractImg2TextModel")
class PytesseractImg2TextModel(LLMBase):
"""
A model for performing OCR (Optical Character Recognition) using Pytesseract.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Literal
import pandas as pd
from sklearn.feature_selection import mutual_info_classif
from swarmauri_core.ComponentBase import ComponentBase
from swarmauri_base.measurements.MeasurementBase import MeasurementBase
from swarmauri_base.measurements.MeasurementCalculateMixin import (
MeasurementCalculateMixin,
)


@ComponentBase.register_type(MeasurementBase, "MutualInformationMeasurement")
class MutualInformationMeasurement(MeasurementBase, MeasurementCalculateMixin):
"""
A Measurement class to calculate mutual information between features and a target column in a given dataset.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Literal
from swarmauri_core.ComponentBase import ComponentBase
import tiktoken
from swarmauri_base.measurements.MeasurementBase import MeasurementBase
from swarmauri_base.measurements.MeasurementCalculateMixin import (
MeasurementCalculateMixin,
)


@ComponentBase.register_type(MeasurementBase, "TokenCountEstimatorMeasurement")
class TokenCountEstimatorMeasurement(MeasurementBase, MeasurementCalculateMixin):
"""
A measurement class to estimate the number of tokens in a given text.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import List, Union, Any, Literal
from swarmauri_core.ComponentBase import ComponentBase
from transformers import BertTokenizer, BertModel
import torch
from pydantic import PrivateAttr
from swarmauri_core.documents.IDocument import IDocument
from swarmauri_standard.documents.Document import Document
from swarmauri_base.parsers.ParserBase import ParserBase


@ComponentBase.register_type(ParserBase, "BERTEmbeddingParser")
class BERTEmbeddingParser(ParserBase):
"""
A parser that transforms input text into document embeddings using BERT.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from swarmauri_core.ComponentBase import ComponentBase
import spacy
from typing import List, Union, Any, Literal
from pydantic import PrivateAttr
Expand All @@ -6,6 +7,7 @@
from swarmauri_base.parsers.ParserBase import ParserBase


@ComponentBase.register_type(ParserBase, "EntityRecognitionParser")
class EntityRecognitionParser(ParserBase):
"""
EntityRecognitionParser leverages NER capabilities to parse text and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from swarmauri_core.ComponentBase import ComponentBase
import pymupdf # PyMuPDF
from typing import List, Union, Any, Literal
from swarmauri.parsers.base.ParserBase import ParserBase
from swarmauri_core.documents.IDocument import IDocument
from swarmauri.documents.concrete.Document import Document


@ComponentBase.register_type(ParserBase, "FitzPdfParser")
class PDFtoTextParser(ParserBase):
"""
A parser to extract text from PDF files.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import List, Literal, Union

import PyPDF2
import PyPDF2
from swarmauri_core.ComponentBase import ComponentBase
from swarmauri_standard.documents.Document import Document
from swarmauri_base.parsers.ParserBase import ParserBase
from swarmauri_core.documents.IDocument import IDocument


@ComponentBase.register_type(ParserBase, "PyPDF2Parser")
class PyPDF2Parser(ParserBase):
"""
Parser for reading and extracting text from PDF files using PyPDF2.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import List, Literal

import pypdftk # PyPDFTK
from swarmauri_core.ComponentBase import ComponentBase
import pypdftk
from swarmauri_standard.documents.Document import Document
from swarmauri_base.parsers.ParserBase import ParserBase
from swarmauri_core.documents.IDocument import IDocument


@ComponentBase.register_type(ParserBase, "PyPDFTKParser")
class PyPDFTKParser(ParserBase):
"""
Parser for reading and extracting data fields from PDF files using PyPDFTK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
asyncio_default_fixture_loop_scope = "function"

[tool.poetry.plugins."swarmauri.parsers"]
TextBlobNounParser = "swarmauri_parser_communitytextblob:TextBlobNounParser"
TextBlobSentenceParser = "swarmauri_parser_communitytextblob:TextBlobSentenceParser"
TextBlobNounParser = "swarmauri_parser_communitytextblob.TextBlobNounParser:TextBlobNounParser"
TextBlobSentenceParser = "swarmauri_parser_communitytextblob.TextBlobSentenceParser:TextBlobSentenceParser"
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from swarmauri_core.ComponentBase import ComponentBase
from textblob import TextBlob
from typing import List, Union, Any, Literal
from swarmauri_standard.documents.Document import Document
from swarmauri_base.parsers.ParserBase import ParserBase


@ComponentBase.register_type(ParserBase, "TextBlobNounParser")
class TextBlobNounParser(ParserBase):
"""
A concrete implementation of IParser using TextBlob for Natural Language Processing tasks.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from swarmauri_core.ComponentBase import ComponentBase
from textblob import TextBlob
from typing import List, Union, Any, Literal
from swarmauri_standard.documents.Document import Document
from swarmauri_base.parsers.ParserBase import ParserBase


@ComponentBase.register_type(ParserBase, "TextBlobSentenceParser")
class TextBlobSentenceParser(ParserBase):
"""
A parser that leverages TextBlob to break text into sentences.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from swarmauri_core.ComponentBase import ComponentBase
import pyperclip
from typing import Dict, Any
from swarmauri_base.state.StateBase import StateBase


@ComponentBase.register_type(StateBase, "ClipboardState")
class ClipboardState(StateBase):
"""
A concrete implementation of StateBase that uses the system clipboard to store and retrieve state data.
Expand Down Expand Up @@ -56,7 +58,8 @@ def reset(self) -> None:

def deep_copy(self) -> "ClipboardState":
"""
Creates a deep copy of the current state. In this context, simply returns a new ClipboardState with the same clipboard data.
Creates a deep copy of the current state. In this context, simply returns a new
ClipboardState with the same clipboard data.
"""
try:
current_state = self.read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import base64
from typing import List, Literal, Dict
from captcha.image import ImageCaptcha
from swarmauri_core.ComponentBase import ComponentBase
from pydantic import Field
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tools.Parameter import Parameter


@ComponentBase.register_type(ToolBase, "CaptchaGeneratorTool")
class CaptchaGeneratorTool(ToolBase):
type: Literal["CaptchaGeneratorTool"] = "CaptchaGeneratorTool"
name: str = Field(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from swarmauri_core.ComponentBase import ComponentBase
import textstat
from typing import Any, Dict, List, Literal
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tools.Parameter import Parameter


@ComponentBase.register_type(ToolBase, "DaleChallReadabilityTool")
class DaleChallReadabilityTool(ToolBase):
"""
A tool for calculating the Dale-Chall Readability Score using the textstat library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from io import BytesIO
import requests
from typing import Dict, Literal, List
from swarmauri_core.ComponentBase import ComponentBase
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tools.Parameter import Parameter


@ComponentBase.register_type(ToolBase, "DownloadPDFTool")
class DownloadPDFTool(ToolBase):
"""
A tool to download a PDF from a specified URL and save it to a specified path.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import List, Literal, Dict, Optional, Callable
from swarmauri_core.ComponentBase import ComponentBase
from transformers import pipeline, logging as hf_logging
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tools.Parameter import Parameter
Expand All @@ -8,6 +9,7 @@
hf_logging.set_verbosity_error()


@ComponentBase.register_type(ToolBase, "EntityRecognitionTool")
class EntityRecognitionTool(ToolBase):
"""
A tool that extracts named entities from text using a pre-trained NLP model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
asyncio_default_fixture_loop_scope = "function"

[tool.poetry.plugins."swarmauri.tools"]
FoliumTool = "swarmauri_tool_communityfolium:FoliumTool"
FoliumTool = "swarmauri_tool_communityfolium.FoliumTool:FoliumTool"
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# standard/tools/concrete/FoliumTool.py
import folium
from typing import List, Tuple, Literal, Dict
from swarmauri_core.ComponentBase import ComponentBase
from pydantic import Field
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tools.Parameter import Parameter
import base64
import io


@ComponentBase.register_type(ToolBase, "FoliumTool")
class FoliumTool(ToolBase):
type: Literal["FoliumTool"] = "FoliumTool"
name: str = Field("FoliumTool", description="Tool to generate maps using Folium.")
Expand Down
14 changes: 7 additions & 7 deletions pkgs/community/swarmauri_tool_communitygithub/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
asyncio_default_fixture_loop_scope = "function"

[tool.poetry.plugins."swarmauri.tools"]
GithubBranchTool = "swarmauri_tool_communitygithub.GithubBranchTool"
GithubCommitTool = "swarmauri_tool_communitygithub.GithubCommitTool"
GithubIssueTool = "swarmauri_tool_communitygithub.GithubIssueTool"
GithubPRTool = "swarmauri_tool_communitygithub.GithubPRTool"
GithubTool = "swarmauri_tool_communitygithub.GithubTool"
GithubRepoTool = "swarmauri_tool_communitygithub.GithubRepoTool"
GithubBranchTool = "swarmauri_tool_communitygithub.GithubBranchTool:GithubBranchTool"
GithubCommitTool = "swarmauri_tool_communitygithub.GithubCommitTool:GithubCommitTool"
GithubIssueTool = "swarmauri_tool_communitygithub.GithubIssueTool:GithubIssueTool"
GithubPRTool = "swarmauri_tool_communitygithub.GithubPRTool:GithubPRTool"
GithubTool = "swarmauri_tool_communitygithub.GithubTool:GithubTool"
GithubRepoTool = "swarmauri_tool_communitygithub.GithubRepoTool:GithubRepoTool"

[tool.poetry.plugins."swarmauri.toolkits"]
GithubToolkit = "swarmauri_tool_communitygithub.GithubToolkit"
GithubToolkit = "swarmauri_tool_communitygithub.GithubToolkit:GithubToolkit"

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from github import Github, GithubException
from typing import List, Dict, Literal, Any
from swarmauri_core.ComponentBase import ComponentBase
from pydantic import Field, ConfigDict
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tool.Parameter import Parameter
from swarmauri_standard.tools.Parameter import Parameter


@ComponentBase.register_type(ToolBase, "GithubBranchTool")
class GithubBranchTool(ToolBase):
version: str = "1.1.0"
parameters: List[Parameter] = Field(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# swarmauri/standard/tools/concrete/GithubTool.py

from github import Github, GithubException
from typing import List, Dict, Literal, Any
from swarmauri_core.ComponentBase import ComponentBase
from pydantic import Field, ConfigDict
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tool.Parameter import Parameter

from swarmauri_standard.tools.Parameter import Parameter

@ComponentBase.register_type(ToolBase, "GithubCommitTool")
class GithubCommitTool(ToolBase):
version: str = "1.1.0"
parameters: List[Parameter] = Field(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# swarmauri/standard/tools/concrete/GithubTool.py

from github import Github, GithubException
from typing import List, Dict, Literal, Any
from swarmauri_core.ComponentBase import ComponentBase
from pydantic import Field, ConfigDict
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tool.Parameter import Parameter
from swarmauri_standard.tools.Parameter import Parameter


@ComponentBase.register_type(ToolBase, "GithubCommitTool")
class GithubIssueTool(ToolBase):
version: str = "1.1.0"
parameters: List[Parameter] = Field(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# swarmauri/community/tools/concrete/GithubPRTool.py

from github import Github, GithubException
from typing import List, Dict, Literal, Any
from pydantic import Field, ConfigDict
from swarmauri_base.tools.base.ToolBase import ToolBase
from swarmauri_standard.tool.Parameter import Parameter
from swarmauri_standard.tools.Parameter import Parameter


class GithubPRTool(ToolBase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# swarmauri/standard/tools/concrete/GithubTool.py

from github import Github, GithubException
from typing import List, Dict, Literal, Any
from swarmauri_core.ComponentBase import ComponentBase
from pydantic import Field, ConfigDict
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tools.Parameter import Parameter


@ComponentBase.register_type(ToolBase, "GithubCommitTool")
class GithubRepoTool(ToolBase):
version: str = "1.1.0"
parameters: List[Parameter] = Field(
Expand Down Expand Up @@ -66,7 +66,7 @@ def __call__(self, action: str, **kwargs) -> Dict[str, Any]:
def create_repo(self, repo_name: str, private: bool = False) -> str:
try:
user = self._github.get_user()
repo = user.create_repo(repo_name, private=private)
user.create_repo(repo_name, private=private)
return f"Repository '{repo_name}' created successfully."
except GithubException as e:
return f"Error creating repository: {e}"
Expand Down
Loading

0 comments on commit 5feda25

Please sign in to comment.