Skip to content

Commit

Permalink
Merge pull request #1129 from MichaelDecent/v0.6.0_release
Browse files Browse the repository at this point in the history
feat: add new components in swarmauri
  • Loading branch information
cobycloud authored Feb 10, 2025
2 parents 03be0d4 + 036acf1 commit ec9075e
Show file tree
Hide file tree
Showing 43 changed files with 8,398 additions and 2 deletions.
71 changes: 71 additions & 0 deletions pkgs/base/swarmauri_base/ocrs/OCRBase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from abc import abstractmethod
from typing import Optional, List, Literal
from pydantic import ConfigDict, model_validator, Field

from swarmauri_core.llms.IPredict import IPredict
from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes


@ComponentBase.register_model()
class OCRBase(IPredict, ComponentBase):
allowed_models: List[str] = []
resource: Optional[str] = Field(default=ResourceTypes.OCR.value, frozen=True)
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
type: Literal["OCRBase"] = "OCRBase"

@model_validator(mode="after")
@classmethod
def _validate_name_in_allowed_models(cls, values):
name = values.name
allowed_models = values.allowed_models
if name and name not in allowed_models:
raise ValueError(
f"Model name {name} is not allowed. Choose from {allowed_models}"
)
return values

def add_allowed_model(self, model: str) -> None:
"""
Add a new model to the list of allowed models.
Raises:
ValueError: If the model is already in the allowed models list.
"""
if model in self.allowed_models:
raise ValueError(f"Model '{model}' is already allowed.")
self.allowed_models.append(model)

def remove_allowed_model(self, model: str) -> None:
"""
Remove a model from the list of allowed models.
Raises:
ValueError: If the model is not in the allowed models list.
"""
if model not in self.allowed_models:
raise ValueError(f"Model '{model}' is not in the allowed models list.")
self.allowed_models.remove(model)

@abstractmethod
def predict(self, *args, **kwargs):
raise NotImplementedError("predict() not implemented in subclass yet.")

@abstractmethod
async def apredict(self, *args, **kwargs):
raise NotImplementedError("apredict() not implemented in subclass yet.")

@abstractmethod
def stream(self, *args, **kwargs):
raise NotImplementedError("stream() not implemented in subclass yet.")

@abstractmethod
async def astream(self, *args, **kwargs):
raise NotImplementedError("astream() not implemented in subclass yet.")

@abstractmethod
def batch(self, *args, **kwargs):
raise NotImplementedError("batch() not implemented in subclass yet.")

@abstractmethod
async def abatch(self, *args, **kwargs):
raise NotImplementedError("abatch() not implemented in subclass yet.")
71 changes: 71 additions & 0 deletions pkgs/base/swarmauri_base/stt/STTBase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from abc import abstractmethod
from typing import Optional, List, Literal
from pydantic import ConfigDict, model_validator, Field

from swarmauri_core.llms.IPredict import IPredict
from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes


@ComponentBase.register_model()
class STTBase(IPredict, ComponentBase):
allowed_models: List[str] = []
resource: Optional[str] = Field(default=ResourceTypes.STT.value, frozen=True)
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
type: Literal["STTBase"] = "STTBase"

@model_validator(mode="after")
@classmethod
def _validate_name_in_allowed_models(cls, values):
name = values.name
allowed_models = values.allowed_models
if name and name not in allowed_models:
raise ValueError(
f"Model name {name} is not allowed. Choose from {allowed_models}"
)
return values

def add_allowed_model(self, model: str) -> None:
"""
Add a new model to the list of allowed models.
Raises:
ValueError: If the model is already in the allowed models list.
"""
if model in self.allowed_models:
raise ValueError(f"Model '{model}' is already allowed.")
self.allowed_models.append(model)

def remove_allowed_model(self, model: str) -> None:
"""
Remove a model from the list of allowed models.
Raises:
ValueError: If the model is not in the allowed models list.
"""
if model not in self.allowed_models:
raise ValueError(f"Model '{model}' is not in the allowed models list.")
self.allowed_models.remove(model)

@abstractmethod
def predict(self, *args, **kwargs):
raise NotImplementedError("predict() not implemented in subclass yet.")

@abstractmethod
async def apredict(self, *args, **kwargs):
raise NotImplementedError("apredict() not implemented in subclass yet.")

@abstractmethod
def stream(self, *args, **kwargs):
raise NotImplementedError("stream() not implemented in subclass yet.")

@abstractmethod
async def astream(self, *args, **kwargs):
raise NotImplementedError("astream() not implemented in subclass yet.")

@abstractmethod
def batch(self, *args, **kwargs):
raise NotImplementedError("batch() not implemented in subclass yet.")

@abstractmethod
async def abatch(self, *args, **kwargs):
raise NotImplementedError("abatch() not implemented in subclass yet.")
71 changes: 71 additions & 0 deletions pkgs/base/swarmauri_base/tts/TTSBase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from abc import abstractmethod
from typing import Optional, List, Literal
from pydantic import ConfigDict, model_validator, Field

from swarmauri_core.llms.IPredict import IPredict
from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes


@ComponentBase.register_model()
class TTSBase(IPredict, ComponentBase):
allowed_models: List[str] = []
resource: Optional[str] = Field(default=ResourceTypes.TTS.value, frozen=True)
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
type: Literal["TTSBase"] = "TTSBase"

@model_validator(mode="after")
@classmethod
def _validate_name_in_allowed_models(cls, values):
name = values.name
allowed_models = values.allowed_models
if name and name not in allowed_models:
raise ValueError(
f"Model name {name} is not allowed. Choose from {allowed_models}"
)
return values

def add_allowed_model(self, model: str) -> None:
"""
Add a new model to the list of allowed models.
Raises:
ValueError: If the model is already in the allowed models list.
"""
if model in self.allowed_models:
raise ValueError(f"Model '{model}' is already allowed.")
self.allowed_models.append(model)

def remove_allowed_model(self, model: str) -> None:
"""
Remove a model from the list of allowed models.
Raises:
ValueError: If the model is not in the allowed models list.
"""
if model not in self.allowed_models:
raise ValueError(f"Model '{model}' is not in the allowed models list.")
self.allowed_models.remove(model)

@abstractmethod
def predict(self, *args, **kwargs):
raise NotImplementedError("predict() not implemented in subclass yet.")

@abstractmethod
async def apredict(self, *args, **kwargs):
raise NotImplementedError("apredict() not implemented in subclass yet.")

@abstractmethod
def stream(self, *args, **kwargs):
raise NotImplementedError("stream() not implemented in subclass yet.")

@abstractmethod
async def astream(self, *args, **kwargs):
raise NotImplementedError("astream() not implemented in subclass yet.")

@abstractmethod
def batch(self, *args, **kwargs):
raise NotImplementedError("batch() not implemented in subclass yet.")

@abstractmethod
async def abatch(self, *args, **kwargs):
raise NotImplementedError("abatch() not implemented in subclass yet.")
48 changes: 48 additions & 0 deletions pkgs/core/swarmauri_core/ocrs/IPredict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from abc import ABC, abstractmethod

class IPredict(ABC):
"""
Interface focusing on the basic properties and settings essential for defining models.
"""

@abstractmethod
def predict(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def apredict(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
def stream(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def astream(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
def batch(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def abatch(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass
48 changes: 48 additions & 0 deletions pkgs/core/swarmauri_core/sst/IPredict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from abc import ABC, abstractmethod

class IPredict(ABC):
"""
Interface focusing on the basic properties and settings essential for defining models.
"""

@abstractmethod
def predict(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def apredict(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
def stream(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def astream(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
def batch(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def abatch(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass
48 changes: 48 additions & 0 deletions pkgs/core/swarmauri_core/tts/IPredict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from abc import ABC, abstractmethod

class IPredict(ABC):
"""
Interface focusing on the basic properties and settings essential for defining models.
"""

@abstractmethod
def predict(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def apredict(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
def stream(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def astream(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
def batch(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass

@abstractmethod
async def abatch(self, *args, **kwargs) -> any:
"""
Generate predictions based on the input data provided to the model.
"""
pass
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
from pydantic import ConfigDict
from typing import Any, Optional, Union, Dict, Literal

from swarmauri_base.tool_llms.ToolLLMBase import ToolLLMBase
from swarmauri_standard.messages.HumanMessage import HumanMessage
from swarmauri_base.llms.LLMBase import LLMBase
from swarmauri_base.agents.AgentBase import AgentBase
from swarmauri_base.agents.AgentConversationMixin import AgentConversationMixin
from swarmauri_base.agents.AgentToolMixin import AgentToolMixin
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
from swarmauri_base.conversations.ConversationBase import ConversationBase

from swarmauri_core.messages import IMessage
from swarmauri_core.ComponentBase import SubclassUnion, ComponentBase


@ComponentBase.register_type(AgentBase, "ToolAgent")
class ToolAgent(AgentToolMixin, AgentConversationMixin, AgentBase):
llm: SubclassUnion[LLMBase]
llm: SubclassUnion[ToolLLMBase]
toolkit: SubclassUnion[ToolkitBase]
conversation: SubclassUnion[ConversationBase] # 🚧 Placeholder
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
Expand Down
Loading

0 comments on commit ec9075e

Please sign in to comment.