From ec4dcfca7f7081545c87b0c7c9649065124b8b00 Mon Sep 17 00:00:00 2001 From: aditya thomas Date: Fri, 29 Mar 2024 02:30:08 +0530 Subject: [PATCH] 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 --- libs/core/langchain_core/runnables/base.py | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.py index 78188f2e6ed..dbb09cf106d 100644 --- a/libs/core/langchain_core/runnables/base.py +++ b/libs/core/langchain_core/runnables/base.py @@ -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, )