Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm - added dataconnector #840

Open
wants to merge 1 commit into
base: mono/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/core/swarmauri_core/ComponentBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ResourceTypes(Enum):
VECTOR_STORE = "VectorStore"
VECTOR = "Vector"
VCM = "VCM"
DATA_CONNECTOR = "DataConnector"


def generate_id() -> str:
Expand Down
70 changes: 70 additions & 0 deletions pkgs/core/swarmauri_core/dataconnectors/IDataConnector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from abc import ABC, abstractmethod


class IDataConnector(ABC):
"""
Abstract base class for data connectors.
Defines the interface for all concrete data connector implementations.
"""

@abstractmethod
def authenticate(self, **kwargs):
"""
Authenticate with the data source.
This method should handle any required authentication process.

:param kwargs: Authentication parameters such as API keys, tokens, etc.
"""
pass

@abstractmethod
def fetch_data(self, query: str, **kwargs):
"""
Fetch data from the data source based on a query.

:param query: Query string or parameters to fetch specific data.
:param kwargs: Additional parameters for fetching data.
:return: Data fetched from the source.
"""
pass

@abstractmethod
def insert_data(self, data, **kwargs):
"""
Insert data into the data source.

:param data: Data to be inserted.
:param kwargs: Additional parameters for inserting data.
"""
pass

@abstractmethod
def update_data(self, identifier, data, **kwargs):
"""
Update existing data in the data source.

:param identifier: Unique identifier of the data to update.
:param data: Updated data.
:param kwargs: Additional parameters for updating data.
"""
pass

@abstractmethod
def delete_data(self, identifier, **kwargs):
"""
Delete data from the data source.

:param identifier: Unique identifier of the data to delete.
:param kwargs: Additional parameters for deleting data.
"""
pass

@abstractmethod
def test_connection(self, **kwargs):
"""
Test the connection to the data source.

:param kwargs: Connection parameters.
:return: Boolean indicating whether the connection is successful.
"""
pass
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from swarmauri_core.dataconnectors.IDataConnector import IDataConnector


class DataConnectorBase(IDataConnector):
"""
Base implementation of IDataConnector that raises NotImplementedError
for all abstract methods, ensuring explicit implementation in child classes.
"""

def authenticate(self, **kwargs):
"""
Raises NotImplementedError to enforce implementation in child classes.

:param kwargs: Authentication parameters
:raises NotImplementedError: Always raised to require specific implementation
"""
raise NotImplementedError(
"Authenticate method must be implemented by child classes."
)

def fetch_data(self, query: str, **kwargs):
"""
Raises NotImplementedError to enforce implementation in child classes.

:param query: Query string or parameters
:param kwargs: Additional parameters
:raises NotImplementedError: Always raised to require specific implementation
"""
raise NotImplementedError(
"Fetch data method must be implemented by child classes."
)

def insert_data(self, data, **kwargs):
"""
Raises NotImplementedError to enforce implementation in child classes.

:param data: Data to be inserted
:param kwargs: Additional parameters
:raises NotImplementedError: Always raised to require specific implementation
"""
raise NotImplementedError(
"Insert data method must be implemented by child classes."
)

def update_data(self, identifier, data, **kwargs):
"""
Raises NotImplementedError to enforce implementation in child classes.

:param identifier: Unique identifier of the data to update
:param data: Updated data
:param kwargs: Additional parameters
:raises NotImplementedError: Always raised to require specific implementation
"""
raise NotImplementedError(
"Update data method must be implemented by child classes."
)

def delete_data(self, identifier, **kwargs):
"""
Raises NotImplementedError to enforce implementation in child classes.

:param identifier: Unique identifier of the data to delete
:param kwargs: Additional parameters
:raises NotImplementedError: Always raised to require specific implementation
"""
raise NotImplementedError(
"Delete data method must be implemented by child classes."
)

def test_connection(self, **kwargs):
"""
Raises NotImplementedError to enforce implementation in child classes.

:param kwargs: Connection parameters
:raises NotImplementedError: Always raised to require specific implementation
"""
raise NotImplementedError(
"Test connection method must be implemented by child classes."
)
Empty file.