迁移到 astream_events(..., version=“v2”)
我们添加了一个v2的 astream_events API 中发布了0.2.x.你可以查看此 PR 了解更多详情。
这v2version 是v1版中,并且应该更高效,事件的输出更一致。这v1版本将被弃用,取而代之的是v2版本,并将在0.4.0.
以下是v1和v2API 的版本。
output 的on_chat_model_end
在v1,则与on_chat_model_end更改取决于
chat 模型作为根级别可运行或作为链的一部分运行。
作为根级别可运行对象,输出为:
"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)目前将始终与更详细的格式相关联。
output 的on_retriever_end
on_retriever_endoutput 将始终返回Documents.
以前:
{
"data": {
"output": [
Document(...),
Document(...),
...
]
}
}
删除on_retriever_stream
这on_retriever_streamevent 是实现的产物,已被删除。
与事件关联的完整信息已在on_retriever_end事件。
请使用on_retriever_end相反。
删除on_tool_stream
这on_tool_streamevent 是实现的产物,已被删除。
与事件关联的完整信息已在on_tool_end事件。
请使用on_tool_end相反。
传播名称
Runnables 的名称已更新,更加一致。
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 会生成不正确的on_chain_end事件中v1相应
添加到正在重试的失败的 Runnable 调用。此事件已在v2.
此更改无需执行任何作。