mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +00:00
3749af79ae
This pull request addresses an issue found in the example code within the docstring of `libs/core/langchain_core/runnables/passthrough.py` The original code snippet caused a `NameError` due to the missing import of `RunnableLambda`. The error was as follows: ``` 12 return "completion" 13 ---> 14 chain = RunnableLambda(fake_llm) | { 15 'original': RunnablePassthrough(), # Original LLM output 16 'parsed': lambda text: text[::-1] # Parsing logic NameError: name 'RunnableLambda' is not defined ``` To resolve this, I have modified the example code to include the necessary import statement for `RunnableLambda`. Additionally, I have adjusted the indentation in the code snippet to ensure consistency and readability. The modified code now successfully defines and utilizes `RunnableLambda`, ensuring that users referencing the docstring will have a functional and clear example to follow. There are no related GitHub issues for this particular change. Modified Code: ```python from langchain_core.runnables import RunnablePassthrough, RunnableParallel from langchain_core.runnables import RunnableLambda runnable = RunnableParallel( origin=RunnablePassthrough(), modified=lambda x: x+1 ) runnable.invoke(1) # {'origin': 1, 'modified': 2} def fake_llm(prompt: str) -> str: # Fake LLM for the example return "completion" chain = RunnableLambda(fake_llm) | { 'original': RunnablePassthrough(), # Original LLM output 'parsed': lambda text: text[::-1] # Parsing logic } chain.invoke('hello') # {'original': 'completion', 'parsed': 'noitelpmoc'} ``` --------- Co-authored-by: Bagatur <baskaryan@gmail.com> |
||
---|---|---|
.. | ||
langchain_core | ||
scripts | ||
tests | ||
Makefile | ||
poetry.lock | ||
pyproject.toml | ||
README.md |