mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-15 14:36:54 +00:00
core[runnables]: docstring of class RunnableSerializable, method configurable_alternatives (#19724)
**Description:** Update to the docstring for class RunnableSerializable, method configurable_alternatives **Issue:** [Add in code documentation to core Runnable methods #18804](https://github.com/langchain-ai/langchain/issues/18804) **Dependencies:** None --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
@@ -2053,6 +2053,32 @@ class RunnableSerializable(Serializable, Runnable[Input, Output]):
|
||||
prefix_keys: bool = False,
|
||||
**kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]],
|
||||
) -> RunnableSerializable[Input, Output]:
|
||||
"""Configure alternatives for runnables that can be set at runtime.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
from langchain_core.runnables.utils import ConfigurableField
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
model = ChatAnthropic(
|
||||
model_name="claude-3-sonnet-20240229"
|
||||
).configurable_alternatives(
|
||||
ConfigurableField(id="llm"),
|
||||
default_key="anthropic",
|
||||
openai=ChatOpenAI()
|
||||
)
|
||||
|
||||
# uses the default model ChatAnthropic
|
||||
print(model.invoke("which organization created you?").content)
|
||||
|
||||
# uses ChatOpenaAI
|
||||
print(
|
||||
model.with_config(
|
||||
configurable={"llm": "openai"}
|
||||
).invoke("which organization created you?").content
|
||||
)
|
||||
"""
|
||||
from langchain_core.runnables.configurable import (
|
||||
RunnableConfigurableAlternatives,
|
||||
)
|
||||
|
Reference in New Issue
Block a user