diff --git a/docs/extras/modules/model_io/output_parsers/xml.ipynb b/docs/extras/modules/model_io/output_parsers/xml.ipynb index d0ca341d42..62d14dba7d 100644 --- a/docs/extras/modules/model_io/output_parsers/xml.ipynb +++ b/docs/extras/modules/model_io/output_parsers/xml.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "3b10fc55", "metadata": {}, "outputs": [], @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "909161d1", "metadata": {}, "outputs": [ @@ -35,7 +35,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/home/mateusz/Documents/Projects/langchain/libs/langchain/langchain/llms/anthropic.py:170: UserWarning: This Anthropic LLM is deprecated. Please use `from langchain.chat_models import ChatAnthropic` instead\n", + "/Users/harrisonchase/workplace/langchain/libs/langchain/langchain/llms/anthropic.py:171: UserWarning: This Anthropic LLM is deprecated. Please use `from langchain.chat_models import ChatAnthropic` instead\n", " warnings.warn(\n" ] } @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "id": "b03785af-69fc-40a1-a1be-c04ed6fade70", "metadata": {}, "outputs": [ @@ -105,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "id": "87ba8d11", "metadata": {}, "outputs": [ @@ -113,93 +113,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", - "\n", - " \n", - " Splash\n", - " 1984\n", - " \n", - " \n", - " \n", - " Big \n", - " 1988\n", - " \n", - "\n", - " \n", - " A League of Their Own\n", - " 1992\n", - " \n", - "\n", - " \n", - " Sleepless in Seattle\n", - " 1993\n", - " \n", - "\n", - " \n", - " Forrest Gump\n", - " 1994\n", - " \n", - "\n", - " \n", - " Toy Story\n", - " 1995\n", - " \n", - "\n", - " \n", - " Apollo 13\n", - " 1995\n", - " \n", - "\n", - " \n", - " Saving Private Ryan\n", - " 1998\n", - " \n", - "\n", - " \n", - " Cast Away\n", - " 2000\n", - " \n", - "\n", - " \n", - " Catch Me If You Can\n", - " 2002\n", - " \n", - "\n", - " \n", - " The Polar Express\n", - " 2004\n", - " \n", - "\n", - " \n", - " Charlie Wilson's War\n", - " 2007\n", - " \n", - "\n", - " \n", - " Toy Story 3\n", - " 2010\n", - " \n", - "\n", - " \n", - " Captain Phillips\n", - " 2013\n", - " \n", - "\n", - " \n", - " Bridge of Spies\n", - " 2015\n", - " \n", - "\n", - " \n", - " The Post\n", - " 2017\n", - " \n", - "\n", - " \n", - " A Beautiful Day in the Neighborhood \n", - " 2019\n", - " \n", - "\n" + "{'filmography': [{'movie': [{'title': 'Splash'}, {'year': '1984'}]}, {'movie': [{'title': 'Big'}, {'year': '1988'}]}, {'movie': [{'title': 'A League of Their Own'}, {'year': '1992'}]}, {'movie': [{'title': 'Sleepless in Seattle'}, {'year': '1993'}]}, {'movie': [{'title': 'Forrest Gump'}, {'year': '1994'}]}, {'movie': [{'title': 'Toy Story'}, {'year': '1995'}]}, {'movie': [{'title': 'Apollo 13'}, {'year': '1995'}]}, {'movie': [{'title': 'Saving Private Ryan'}, {'year': '1998'}]}, {'movie': [{'title': 'Cast Away'}, {'year': '2000'}]}, {'movie': [{'title': 'Catch Me If You Can'}, {'year': '2002'}]}, {'movie': [{'title': 'The Polar Express'}, {'year': '2004'}]}, {'movie': [{'title': 'Bridge of Spies'}, {'year': '2015'}]}]}\n" ] } ], @@ -217,58 +131,12 @@ " partial_variables={\"format_instructions\": parser.get_format_instructions()},\n", ")\n", "\n", - "_input = prompt.format_prompt(query=actor_query)\n", + "chain = prompt | model | parser\n", "\n", - "output = model(_input.to_string())\n", + "output = chain.invoke({\"query\": actor_query})\n", "print(output)" ] }, - { - "cell_type": "markdown", - "id": "1c4c47ee", - "metadata": {}, - "source": [ - "And here parsed output is shown:" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "4c864dc9", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'filmography': [{'movie': [{'title': 'Splash'}, {'year': '1984'}]},\n", - " {'movie': [{'title': 'Big'}, {'year': '1988'}]},\n", - " {'movie': [{'title': 'A League of Their Own'}, {'year': '1992'}]},\n", - " {'movie': [{'title': 'Sleepless in Seattle'}, {'year': '1993'}]},\n", - " {'movie': [{'title': 'Forrest Gump'}, {'year': '1994'}]},\n", - " {'movie': [{'title': 'Toy Story'}, {'year': '1995'}]},\n", - " {'movie': [{'title': 'Apollo 13'}, {'year': '1995'}]},\n", - " {'movie': [{'title': 'Saving Private Ryan'}, {'year': '1998'}]},\n", - " {'movie': [{'title': 'Cast Away'}, {'year': '2000'}]},\n", - " {'movie': [{'title': 'Catch Me If You Can'}, {'year': '2002'}]},\n", - " {'movie': [{'title': 'The Polar Express'}, {'year': '2004'}]},\n", - " {'movie': [{'title': \"Charlie Wilson's War\"}, {'year': '2007'}]},\n", - " {'movie': [{'title': 'Toy Story 3'}, {'year': '2010'}]},\n", - " {'movie': [{'title': 'Captain Phillips'}, {'year': '2013'}]},\n", - " {'movie': [{'title': 'Bridge of Spies'}, {'year': '2015'}]},\n", - " {'movie': [{'title': 'The Post'}, {'year': '2017'}]},\n", - " {'movie': [{'title': 'A Beautiful Day in the Neighborhood'},\n", - " {'year': '2019'}]}]}" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "parser.parse(output)" - ] - }, { "cell_type": "markdown", "id": "327f5479-77e0-4549-8393-2cd7a286d491", @@ -279,29 +147,16 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "id": "b722a235", "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{'movies': [{'actor': [{'name': 'Tom Hanks'},\n", - " {'film': [{'name': 'Splash'}, {'genre': 'Comedy'}]},\n", - " {'film': [{'name': 'Big'}, {'genre': 'Comedy'}]},\n", - " {'film': [{'name': 'A League of Their Own'}, {'genre': 'Drama'}]},\n", - " {'film': [{'name': 'Sleepless in Seattle'}, {'genre': 'Romance'}]},\n", - " {'film': [{'name': 'Forrest Gump'}, {'genre': 'Drama'}]},\n", - " {'film': [{'name': 'Toy Story'}, {'genre': 'Animation'}]},\n", - " {'film': [{'name': 'Apollo 13'}, {'genre': 'Drama'}]},\n", - " {'film': [{'name': 'Saving Private Ryan'}, {'genre': 'War'}]},\n", - " {'film': [{'name': 'Cast Away'}, {'genre': 'Adventure'}]},\n", - " {'film': [{'name': 'The Green Mile'}, {'genre': 'Drama'}]}]}]}" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "{'movies': [{'actor': [{'name': 'Tom Hanks'}, {'film': [{'name': 'Splash'}, {'genre': 'Comedy'}]}, {'film': [{'name': 'Big'}, {'genre': 'Comedy'}]}, {'film': [{'name': 'A League of Their Own'}, {'genre': 'Comedy'}]}, {'film': [{'name': 'Sleepless in Seattle'}, {'genre': 'Romance'}]}, {'film': [{'name': 'Forrest Gump'}, {'genre': 'Drama'}]}, {'film': [{'name': 'Toy Story'}, {'genre': 'Animation'}]}, {'film': [{'name': 'Apollo 13'}, {'genre': 'Drama'}]}, {'film': [{'name': 'Saving Private Ryan'}, {'genre': 'War'}]}, {'film': [{'name': 'Cast Away'}, {'genre': 'Adventure'}]}, {'film': [{'name': 'The Green Mile'}, {'genre': 'Drama'}]}]}]}\n" + ] } ], "source": [ @@ -318,11 +173,11 @@ ")\n", "\n", "\n", - "_input = prompt.format_prompt(query=actor_query)\n", + "chain = prompt | model | parser\n", "\n", - "output = model(_input.to_string())\n", + "output = chain.invoke({\"query\": actor_query})\n", "\n", - "parser.parse(output)" + "print(output)" ] }, { @@ -350,7 +205,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.1" } }, "nbformat": 4,