MCPcopy
hub / github.com/langchain-ai/langchain / bind

Method bind

libs/core/langchain_core/runnables/base.py:1218–1253  ·  view source on GitHub ↗

Bind arguments to a Runnable, returning a new Runnable. Useful when a runnable in a chain requires an argument that is not in the output of the previous runnable or included in the user input. Example: .. code-block:: python from langchain_com

(self, **kwargs: Any)

Source from the content-addressed store, hash-verified

1216 yield output
1217
1218 def bind(self, **kwargs: Any) -> Runnable[Input, Output]:
1219 """
1220 Bind arguments to a Runnable, returning a new Runnable.
1221
1222 Useful when a runnable in a chain requires an argument that is not
1223 in the output of the previous runnable or included in the user input.
1224
1225 Example:
1226
1227 .. code-block:: python
1228
1229 from langchain_community.chat_models import ChatOllama
1230 from langchain_core.output_parsers import StrOutputParser
1231
1232 llm = ChatOllama(model='llama2')
1233
1234 # Without bind.
1235 chain = (
1236 llm
1237 | StrOutputParser()
1238 )
1239
1240 chain.invoke("Repeat quoted words exactly: 'One two three four five.'")
1241 # Output is 'One two three four five.'
1242
1243 # With bind.
1244 chain = (
1245 llm.bind(stop=["three"])
1246 | StrOutputParser()
1247 )
1248
1249 chain.invoke("Repeat quoted words exactly: 'One two three four five.'")
1250 # Output is 'One two'
1251
1252 """
1253 return RunnableBinding(bound=self, kwargs=kwargs, config={})
1254
1255 def with_config(
1256 self,

Callers 15

llm_with_toolsFunction · 0.45
chain.pyFile · 0.45
chain.pyFile · 0.45
chain.pyFile · 0.45
agent.pyFile · 0.45
sql.pyFile · 0.45
chain.pyFile · 0.45
agent.pyFile · 0.45
agent.pyFile · 0.45
agent.pyFile · 0.45
chain.pyFile · 0.45
chain.pyFile · 0.45

Calls 1

RunnableBindingClass · 0.85

Tested by 15

bind_toolsMethod · 0.36
bind_toolsMethod · 0.36
test_schemasFunction · 0.36
test_seq_prompt_mapFunction · 0.36
test_map_streamFunction · 0.36