From 21c842baf6237c0aa35fb73f9e3d7606c340f151 Mon Sep 17 00:00:00 2001 From: Vadym Barda Date: Mon, 12 Aug 2024 17:11:07 -0400 Subject: [PATCH 1/2] docs: update streaming example (#1321) * docs: update streaming example --- examples/streaming-content.ipynb | 36 ++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/examples/streaming-content.ipynb b/examples/streaming-content.ipynb index aabd6fc97..ff182ca21 100644 --- a/examples/streaming-content.ipynb +++ b/examples/streaming-content.ipynb @@ -14,9 +14,24 @@ "Below is a simple toy example." ] }, + { + "cell_type": "markdown", + "id": "95301021-1db9-426f-807c-ec5b37bd5a9d", + "metadata": {}, + "source": [ + "
\n", + "

ASYNC IN PYTHON<=3.10

\n", + "

\n", + "Any Langchain RunnableLambda, a RunnableGenerator, or Tool that invokes other runnables and is running async in python<=3.10, will have to propagate callbacks to child objects manually. This is because LangChain cannot automatically propagate callbacks to child objects in this case.\n", + " \n", + "This is a common reason why you may fail to see events being emitted from custom runnables or tools.\n", + "

\n", + "
" + ] + }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "id": "486a01a0", "metadata": {}, "outputs": [], @@ -51,7 +66,10 @@ " messages = []\n", " # Tagging a node makes it easy to filter out which events to include in your stream\n", " # It's completely optional, but useful if you have many functions with similar names\n", - " gen = RunnableGenerator(my_generator).with_config(tags=[\"should_stream\"])\n", + " gen = RunnableGenerator(my_generator).with_config(\n", + " tags=[\"should_stream\"],\n", + " callbacks=config.get(\"callbacks\", []) # <-- Propagate callbacks (Python <= 3.10)\n", + " )\n", " async for message in gen.astream(state):\n", " messages.append(message)\n", " return {\"messages\": [AIMessage(content=\" \".join(messages))]}\n", @@ -65,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "id": "ce773a40", "metadata": {}, "outputs": [ @@ -80,7 +98,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/Users/harrisonchase/.pyenv/versions/3.11.1/envs/permchain/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.\n", + "/Users/vadymbarda/.virtualenvs/langgraph/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.\n", " warn_beta(\n" ] } @@ -89,7 +107,7 @@ "from langchain_core.messages import HumanMessage\n", "\n", "inputs = [HumanMessage(content=\"What are you thinking about?\")]\n", - "async for event in app.astream_events({\"messages\": inputs}, version=\"v1\"):\n", + "async for event in app.astream_events({\"messages\": inputs}, version=\"v2\"):\n", " kind = event[\"event\"]\n", " tags = event.get(\"tags\", [])\n", " if kind == \"on_chain_stream\" and \"should_stream\" in tags:\n", @@ -104,7 +122,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2c7b7902-2d80-4bf9-91c1-737b749e58a3", + "id": "615cb9d2-bfa2-4f83-90b0-c6c2d1e6df95", "metadata": {}, "outputs": [], "source": [] @@ -112,9 +130,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "langgraph", "language": "python", - "name": "python3" + "name": "langgraph" }, "language_info": { "codemirror_mode": { @@ -126,7 +144,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.1" + "version": "3.11.9" } }, "nbformat": 4, From 408676913c27fed6db85c3f8b08b5c06f4003d94 Mon Sep 17 00:00:00 2001 From: Lenni Justen <65619456+lennijusten@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:21:32 -0400 Subject: [PATCH 2/2] Remove extra bullet from index.md (#1149) --- docs/docs/tutorials/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/docs/tutorials/index.md b/docs/docs/tutorials/index.md index 3e414d592..5d17ac234 100644 --- a/docs/docs/tutorials/index.md +++ b/docs/docs/tutorials/index.md @@ -65,4 +65,3 @@ Learn from example implementations of graphs designed for specific scenarios and - [Web Navigation](web-navigation/web_voyager.ipynb): Build an agent that can navigate and interact with websites - [Competitive Programming](usaco/usaco.ipynb): Build an agent with few-shot "episodic memory" and human-in-the-loop collaboration to solve problems from the USA Computing Olympiad; adapted from the ["Can Language Models Solve Olympiad Programming?"](https://arxiv.org/abs/2404.10952v1) paper by Shi, Tang, Narasimhan, and Yao. - [Complex data extraction](extraction/retries.ipynb): Build an agent that can use function calling to do complex extraction tasks -- \ No newline at end of file