-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1129 from MichaelDecent/v0.6.0_release
feat: add new components in swarmauri
- Loading branch information
Showing
43 changed files
with
8,398 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.