From 14dd89a1ee2876525dcccc74524e39184405b843 Mon Sep 17 00:00:00 2001 From: jongwony Date: Thu, 11 Jul 2024 02:17:51 +0900 Subject: [PATCH] docs: add itemgetter in how_to/dynamic_chain (#23951) Hello! I am honored to be able to contribute to the LangChain project for the first time. - **Description:** Using `RunnablePassthrough` logic without providing `chat_history` key will result in nested keys in `question`, so I submit a pull request to resolve this issue. I am attaching a LangSmith screenshot below. This is the result of the current version of the document. image without `chat_history`: image - **Lint and test**: image --- docs/docs/how_to/dynamic_chain.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/docs/how_to/dynamic_chain.ipynb b/docs/docs/how_to/dynamic_chain.ipynb index 2f8c26efd2a..53790472a4a 100644 --- a/docs/docs/how_to/dynamic_chain.ipynb +++ b/docs/docs/how_to/dynamic_chain.ipynb @@ -58,6 +58,8 @@ } ], "source": [ + "from operator import itemgetter\n", + "\n", "from langchain_core.output_parsers import StrOutputParser\n", "from langchain_core.prompts import ChatPromptTemplate\n", "from langchain_core.runnables import Runnable, RunnablePassthrough, chain\n", @@ -86,7 +88,7 @@ " # NOTE: This is returning another Runnable, not an actual output.\n", " return contextualize_question\n", " else:\n", - " return RunnablePassthrough()\n", + " return RunnablePassthrough() | itemgetter(\"question\")\n", "\n", "\n", "@chain\n",