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)
| 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, |