forked from kedro-org/kedro-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
467 additions
and
44 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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Kedro plugin for running a project with Airflow.""" | ||
|
||
__version__ = "0.8.0" | ||
__version__ = "0.9.0" |
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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
kedro-datasets/kedro_datasets_experimental/langchain/__init__.py
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,19 @@ | ||
"""Provides interface to langchain model API objects.""" | ||
from typing import Any | ||
|
||
import lazy_loader as lazy | ||
|
||
# https://github.com/pylint-dev/pylint/issues/4300#issuecomment-1043601901 | ||
ChatOpenAIDataset: Any | ||
OpenAIEmbeddingsDataset: Any | ||
ChatAnthropicDataset: Any | ||
ChatCohereDataset: Any | ||
|
||
__getattr__, __dir__, __all__ = lazy.attach( | ||
__name__, | ||
submod_attrs={ | ||
"_openai": ["ChatOpenAIDataset", "OpenAIEmbeddingsDataset"], | ||
"_anthropic": ["ChatAnthropicDataset"], | ||
"_cohere": ["ChatCohereDataset"], | ||
}, | ||
) |
78 changes: 78 additions & 0 deletions
78
kedro-datasets/kedro_datasets_experimental/langchain/_anthropic.py
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,78 @@ | ||
"""Defines an interface to common Anthropic models.""" | ||
|
||
from typing import Any, NoReturn | ||
|
||
from kedro.io import AbstractDataset, DatasetError | ||
from langchain_anthropic import ChatAnthropic | ||
|
||
|
||
class ChatAnthropicDataset(AbstractDataset[None, ChatAnthropic]): | ||
"""``ChatAnthropicDataset`` loads a ChatAnthropic `langchain <https://python.langchain.com/>`_ model. | ||
Example usage for the :doc:`YAML API <kedro:data/data_catalog_yaml_examples>`: | ||
catalog.yml: | ||
.. code-block:: yaml | ||
claude_instant_1: | ||
type: langchain.ChatAnthropicDataset | ||
kwargs: | ||
model: "claude-instant-1" | ||
temperature: 0.0 | ||
credentials: anthropic | ||
credentials.yml: | ||
.. code-block:: yaml | ||
anthropic: | ||
anthropic_api_url: <anthropic-api-base> | ||
anthropic_api_key: <anthropic-api-key> | ||
Example usage for the | ||
`Python API <https://kedro.readthedocs.io/en/stable/data/\ | ||
advanced_data_catalog_usage.html>`_: | ||
.. code-block:: pycon | ||
>>> from kedro_datasets_experimental.langchain import ChatAnthropicDataset | ||
>>> llm = ChatAnthropicDataset( | ||
... credentials={ | ||
... "anthropic_api_url": "xxx" | ||
... "anthropic_api_key": "xxx", | ||
... }, | ||
... kwargs={ | ||
... "model": "claude-instant-1", | ||
... "temperature": 0.0, | ||
... } | ||
... ).load() | ||
>>> | ||
>>> # See: https://python.langchain.com/docs/integrations/chat/anthropic | ||
>>> llm.invoke("Hello world!") | ||
""" | ||
|
||
def __init__(self, credentials: dict[str, str], kwargs: dict[str, Any] = None): | ||
"""Constructor. | ||
Args: | ||
credentials: must contain `anthropic_api_url` and `anthropic_api_key`. | ||
kwargs: keyword arguments passed to the ChatAnthropic constructor. | ||
""" | ||
self.anthropic_api_url = credentials["anthropic_api_url"] | ||
self.anthropic_api_key = credentials["anthropic_api_key"] | ||
self.kwargs = kwargs or {} | ||
|
||
def _describe(self) -> dict[str, Any]: | ||
return {**self.kwargs} | ||
|
||
def _save(self, data: None) -> NoReturn: | ||
raise DatasetError(f"{self.__class__.__name__} is a read only data set type") | ||
|
||
def _load(self) -> ChatAnthropic: | ||
return ChatAnthropic( | ||
anthropic_api_url=self.anthropic_api_url, | ||
anthropic_api_key=self.anthropic_api_key, | ||
**self.kwargs, | ||
) |
76 changes: 76 additions & 0 deletions
76
kedro-datasets/kedro_datasets_experimental/langchain/_cohere.py
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,76 @@ | ||
""" | ||
Cohere dataset definition. | ||
""" | ||
|
||
from typing import Any, NoReturn | ||
|
||
from kedro.io import AbstractDataset, DatasetError | ||
from langchain_cohere import ChatCohere | ||
|
||
|
||
class ChatCohereDataset(AbstractDataset[None, ChatCohere]): | ||
"""``ChatCohereDataset`` loads a ChatCohere `langchain <https://python.langchain.com/>`_ model. | ||
Example usage for the :doc:`YAML API <kedro:data/data_catalog_yaml_examples>`: | ||
catalog.yml: | ||
.. code-block:: yaml | ||
command: | ||
type: langchain.ChatCohereDataset | ||
kwargs: | ||
model: "command" | ||
temperature: 0.0 | ||
credentials: cohere | ||
credentials.yml: | ||
.. code-block:: yaml | ||
cohere: | ||
cohere_api_url: <cohere-api-base> | ||
cohere_api_key: <cohere-api-key> | ||
Example usage for the | ||
`Python API <https://kedro.readthedocs.io/en/stable/data/\ | ||
advanced_data_catalog_usage.html>`_: | ||
.. code-block:: pycon | ||
>>> from kedro_datasets_experimental.langchain import ChatCohereDataset | ||
>>> llm = ChatCohereDataset( | ||
... credentials={ | ||
... "cohere_api_key": "xxx", | ||
... "cohere_api_url": "xxx", | ||
... }, | ||
... kwargs={ | ||
... "model": "command", | ||
... "temperature": 0.0, | ||
... } | ||
... ).load() | ||
>>> | ||
>>> # See: https://python.langchain.com/v0.1/docs/integrations/chat/cohere/ | ||
>>> llm.invoke("Hello world!") | ||
""" | ||
|
||
def __init__(self, credentials: dict[str, str], kwargs: dict[str, Any] = None): | ||
"""Constructor. | ||
Args: | ||
credentials: must contain `cohere_api_url` and `cohere_api_key`. | ||
kwargs: keyword arguments passed to the underlying constructor. | ||
""" | ||
self.cohere_api_url = credentials["cohere_api_url"] | ||
self.cohere_api_key = credentials["cohere_api_key"] | ||
self.kwargs = kwargs or {} | ||
|
||
def _describe(self) -> dict[str, Any]: | ||
return {**self.kwargs} | ||
|
||
def _save(self, data: None) -> NoReturn: | ||
raise DatasetError(f"{self.__class__.__name__} is a read only data set type") | ||
|
||
def _load(self) -> ChatCohere: | ||
return ChatCohere(cohere_api_key=self.cohere_api_key, base_url=self.cohere_api_url, **self.kwargs) |
Oops, something went wrong.