跳至主要內容
Open on GitHub

遷移至 astream_events(..., version="v2")

我們在 0.2.x 版本中新增了 v2 版本的 astream_events API。您可以查看此 PR 以瞭解更多詳細資訊。

v2 版本是 v1 版本的重寫,應更有效率,並為事件提供更一致的輸出。v1 版本的 API 將被棄用,改用 v2 版本,並將在 0.4.0 中移除。

以下是 v1v2 版本 API 之間的變更列表。

on_chat_model_end 的輸出

v1 中,與 on_chat_model_end 關聯的輸出會根據聊天模型是以根層級 Runnable 還是作為鏈的一部分執行而有所不同。

作為根層級 Runnable,輸出為

"data": {"output": AIMessageChunk(content="hello world!", id='some id')}

作為鏈的一部分,輸出為

            "data": {
"output": {
"generations": [
[
{
"generation_info": None,
"message": AIMessageChunk(
content="hello world!", id=AnyStr()
),
"text": "hello world!",
"type": "ChatGenerationChunk",
}
]
],
"llm_output": None,
}
},

v2 開始,輸出將始終是更簡單的表示形式

"data": {"output": AIMessageChunk(content="hello world!", id='some id')}
注意

非聊天模型(即,常規 LLM)目前將始終與更詳細的格式關聯。

on_retriever_end 的輸出

on_retriever_end 輸出將始終返回 Documents 列表。

之前

{
"data": {
"output": [
Document(...),
Document(...),
...
]
}
}

已移除 on_retriever_stream

on_retriever_stream 事件是實作的產物,已被移除。

與事件關聯的完整資訊已在 on_retriever_end 事件中提供。

請改用 on_retriever_end

已移除 on_tool_stream

on_tool_stream 事件是實作的產物,已被移除。

與事件關聯的完整資訊已在 on_tool_end 事件中提供。

請改用 on_tool_end

傳播名稱

Runnable 的名稱已更新為更一致。

model = GenericFakeChatModel(messages=infinite_cycle).configurable_fields(
messages=ConfigurableField(
id="messages",
name="Messages",
description="Messages return by the LLM",
)
)

v1 中,事件名稱為 RunnableConfigurableFields

v2 中,事件名稱為 GenericFakeChatModel

如果您正在按事件名稱篩選,請檢查是否需要更新您的篩選器。

RunnableRetry

在串流的 LCEL 鏈中使用 RunnableRetry 會在 v1 中產生不正確的 on_chain_end 事件,該事件對應於正在重試的失敗 Runnable 調用。此事件已在 v2 中移除。

此變更不需要任何操作。


此頁面是否對您有幫助?