Skip to content

langchain.ChatCohereDataset

kedro_datasets_experimental.langchain.ChatCohereDataset

ChatCohereDataset(credentials, kwargs=None)

Bases: AbstractDataset[None, ChatCohere]

ChatCohereDataset loads a ChatCohere langchain model.

Example usage for the YAML API

catalog.yml

command:
    type: langchain.ChatCohereDataset
    kwargs:
        model: "command"
        temperature: 0.0
    credentials: cohere

credentials.yml

cohere:
    cohere_api_url: <cohere-api-base>
    cohere_api_key: <cohere-api-key>
Example usage for the Python API
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!")

Parameters:

  • credentials (dict[str, str]) –

    must contain cohere_api_url and cohere_api_key.

  • kwargs (dict[str, Any], default: None ) –

    keyword arguments passed to the underlying constructor.

Source code in kedro-datasets/kedro_datasets_experimental/langchain/_cohere.py
58
59
60
61
62
63
64
65
66
67
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 {}

cohere_api_key instance-attribute

cohere_api_key = credentials['cohere_api_key']

cohere_api_url instance-attribute

cohere_api_url = credentials['cohere_api_url']

kwargs instance-attribute

kwargs = kwargs or {}

_describe

_describe()
Source code in kedro-datasets/kedro_datasets_experimental/langchain/_cohere.py
69
70
def _describe(self) -> dict[str, Any]:
    return {**self.kwargs}

load

load()
Source code in kedro-datasets/kedro_datasets_experimental/langchain/_cohere.py
75
76
def load(self) -> ChatCohere:
    return ChatCohere(cohere_api_key=self.cohere_api_key, base_url=self.cohere_api_url, **self.kwargs)

save

save(data)
Source code in kedro-datasets/kedro_datasets_experimental/langchain/_cohere.py
72
73
def save(self, data: None) -> NoReturn:
    raise DatasetError(f"{self.__class__.__name__} is a read only dataset type")