From 64ff4e4f186eb7cd6384c8810330b4924c0f7e8d Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Wed, 15 May 2024 13:29:38 -0400 Subject: [PATCH] x --- docs/docs/versions/overview.mdx | 4 + docs/docs/versions/v_02/astream_events.mdx | 124 ++++++++++++++++++ .../versions/{v0_2.mdx => v_02/index.mdx} | 5 +- 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 docs/docs/versions/v_02/astream_events.mdx rename docs/docs/versions/{v0_2.mdx => v_02/index.mdx} (99%) diff --git a/docs/docs/versions/overview.mdx b/docs/docs/versions/overview.mdx index d6786e02514..f4544bbac22 100644 --- a/docs/docs/versions/overview.mdx +++ b/docs/docs/versions/overview.mdx @@ -7,6 +7,10 @@ sidebar_label: Overview ## What’s new in LangChain? +The following features have been added during the development of 0.2.x: + +- Rolled out `v2` of the [Event Streaming API](https://python.langchain.com/docs/expression_language/streaming/#using-stream-events) + The following features have been added during the development of 0.1.x: - Better streaming support via the [Event Streaming API](https://python.langchain.com/docs/expression_language/streaming/#using-stream-events) diff --git a/docs/docs/versions/v_02/astream_events.mdx b/docs/docs/versions/v_02/astream_events.mdx new file mode 100644 index 00000000000..f299c11a4fb --- /dev/null +++ b/docs/docs/versions/v_02/astream_events.mdx @@ -0,0 +1,124 @@ +--- +sidebar_position: 1 +sidebar_label: astream_events +--- + +# astream_events V2 + +We've added a `v2` of the astream_events API with the release of `0.2.0`. + +You can see this [PR](https://github.com/langchain-ai/langchain/pull/21638) for more details. + +The `v2` version is a re-write of the `v1` version, and should be more efficient, with more consistent output for the events. + +The `v1` version of the API will be deprecated in favor of the `v2` version. `v1` is deprecated as of `0.2.0` and removed in `0.4.0`. + +## Changes + +Below is a list of changes between the `v1` and `v2` versions of the API. + +### on_chat_model_end `output` + +In `v1`, the outputs associated with `on_chat_model_end` changed depending on whether the +chat model was run as a root level runnable or as part of a chain. + +As a root level runnable the output was: + +```python +"data": {"output": AIMessageChunk(content="hello world!", id='some id')} +``` + +As part of a chain the output was: + +``` + "data": { + "output": { + "generations": [ + [ + { + "generation_info": None, + "message": AIMessageChunk( + content="hello world!", id=AnyStr() + ), + "text": "hello world!", + "type": "ChatGenerationChunk", + } + ] + ], + "llm_output": None, + } + }, +``` + + +As of `v2`, the output will always be the simpler representation: + +```python +"data": {"output": AIMessageChunk(content="hello world!", id='some id')} +``` + +:::note +Non chat models (i.e., regular LLMs) are will be consistently associated with the more verbose format for now. +::: + +### Removed `on_retriever_stream` + +The `on_retriever_stream` event was an artifact of the implementation and has been removed. + +Full information associated with the event is already available in the `on_retriever_end` event. + +Please use `on_retriever_end` instead. + +### Removed `on_tool_stream` + +The `on_tool_stream` event was an artifact of the implementation and has been removed. + +Full information associated with the event is already available in the `on_tool_end` event. + +Please use `on_tool_end` instead. + +### Update output for `on_retriever_end` + +`on_retriever_end` output will always return a list of `Documents`. + +Before: +```python +{ + "data": { + "output": [ + Document(...), + Document(...), + ... + ] + } +} +``` + + +### Propagating Names + +Names of runnables have been updated to be more consistent. + +```python +model = GenericFakeChatModel(messages=infinite_cycle).configurable_fields( + messages=ConfigurableField( + id="messages", + name="Messages", + description="Messages return by the LLM", + ) +) +``` + +In `v1`, the event name was `RunnableConfigurableFields`. + +In `v2`, the event name is `GenericFakeChatModel`. + +If you're filtering by event names, check if you need to update your filters. + +### RunnableRetry + +Usage of [RunnableRetry](https://api.python.langchain.com/en/latest/runnables/langchain_core.runnables.retry.RunnableRetry.html) +within an LCEL chain being streamed generated an incorrect `on_chain_end` event in `v1` corresponding +to the failed runnable invocation that was being retried. + +This event has been removed in `v2`. \ No newline at end of file diff --git a/docs/docs/versions/v0_2.mdx b/docs/docs/versions/v_02/index.mdx similarity index 99% rename from docs/docs/versions/v0_2.mdx rename to docs/docs/versions/v_02/index.mdx index ef06512cf82..34eacbee606 100644 --- a/docs/docs/versions/v0_2.mdx +++ b/docs/docs/versions/v_02/index.mdx @@ -172,4 +172,7 @@ We have two main types of deprecations: 2. Code that has better alternatives available and will eventually be removed, so there’s only a single way to do things. (e.g., `predict_messages` method in ChatModels has been deprecated in favor of `invoke`). - Many of these were marked for removal in 0.2. We have bumped the removal to 0.3. \ No newline at end of file + Many of these were marked for removal in 0.2. We have bumped the removal to 0.3. + +### Notable Deprecations +