langchain.ChatAnthropicDataset
kedro_datasets.langchain.ChatAnthropicDataset ¶
ChatAnthropicDataset(credentials={}, kwargs={})
Bases: AbstractDataset[None, ChatAnthropic]
ChatAnthropicDataset loads a ChatAnthropic langchain model.
Example usage for the YAML API¶
catalog.yml
claude_instant_1:
type: langchain.ChatAnthropicDataset
kwargs:
model: "claude-instant-1"
temperature: 0.0
credentials: anthropic # Optional, can use environment variables instead
credentials.yml (optional if using environment variables)
If credentials are passed through credentials.yml, they take precedence over environment variables.
anthropic:
base_url: <anthropic-api-base> # Optional, defaults to Anthropic default
api_key: <anthropic-api-key> # Optional if ANTHROPIC_API_KEY is set
Or use environment variables:
export ANTHROPIC_API_KEY=<your-api-key>
export ANTHROPIC_API_URL=<anthropic-api-base> # Optional
Example usage for the Python API¶
from kedro_datasets.langchain import ChatAnthropicDataset
# With explicit credentials
llm = ChatAnthropicDataset(
credentials={
"base_url": "xxx",
"api_key": "xxx", # pragma: allowlist secret
},
kwargs={
"model": "claude-instant-1",
"temperature": 0.0,
},
).load()
# Or without credentials (using environment variables)
llm = ChatAnthropicDataset(
kwargs={
"model": "claude-instant-1",
"temperature": 0.0,
},
).load()
# See: https://python.langchain.com/docs/integrations/chat/anthropic
llm.invoke("Hello world!")
Parameters:
-
credentials(Optional, default:{}) –contains
api_keyandbase_url. If not provided, will use environment variables ANTHROPIC_API_KEY and ANTHROPIC_API_URL. -
kwargs(dict[str, Any], default:{}) –keyword arguments passed to the ChatAnthropic constructor.
Source code in kedro_datasets/langchain/chat_anthropic_dataset.py
72 73 74 75 76 77 78 79 80 81 | |
_describe ¶
_describe()
Returns a description of the dataset.
Returns:
-
dict[str, Any]–Dictionary containing the kwargs passed to ChatAnthropic.
Source code in kedro_datasets/langchain/chat_anthropic_dataset.py
83 84 85 86 87 88 89 90 91 92 | |
load ¶
load()
Load and return a ChatAnthropic model instance.
Constructs a ChatAnthropic instance using the provided kwargs and optional credentials. If credentials are not provided, the ChatAnthropic instance will automatically use environment variables ANTHROPIC_API_KEY and ANTHROPIC_API_URL for authentication.
Returns:
-
ChatAnthropic–A configured ChatAnthropic model instance.
Source code in kedro_datasets/langchain/chat_anthropic_dataset.py
102 103 104 105 106 107 108 109 110 111 112 113 | |
save ¶
save(data)
Save operation is not supported for ChatAnthropicDataset.
Raises:
-
DatasetError–Always raised as this dataset is read-only.
Source code in kedro_datasets/langchain/chat_anthropic_dataset.py
94 95 96 97 98 99 100 | |