langchain.callbacks.streaming_aiter_final_only
.AsyncFinalIteratorCallbackHandler¶
- class langchain.callbacks.streaming_aiter_final_only.AsyncFinalIteratorCallbackHandler(*, answer_prefix_tokens: Optional[List[str]] = None, strip_tokens: bool = True, stream_prefix: bool = False)[source]¶
回调处理程序,返回一个异步迭代器。 仅迭代代理的最终输出。
实例化AsyncFinalIteratorCallbackHandler。
- 参数:
- answer_prefix_tokens:前缀答案的令牌序列。
默认值为[“Final”, “Answer”, “:”]
- strip_tokens:在比较answer_prefix_tokens和最后的令牌时是否忽略空格和换行符?
(以确定是否已到达答案)
stream_prefix:答案前缀本身是否也应该被流式传输?
Attributes
always_verbose
ignore_agent
是否忽略代理回调。
ignore_chain
是否忽略链式回调。
ignore_chat_model
是否忽略聊天模型的回调。
ignore_llm
是否忽略LLM回调。
ignore_retriever
是否忽略检索器回调函数。
ignore_retry
是否忽略重试回调。
raise_error
run_inline
Methods
__init__
(*[, answer_prefix_tokens, ...])实例化AsyncFinalIteratorCallbackHandler。
aiter
()append_to_last_tokens
(token)on_agent_action
(action, *, run_id[, ...])在代理程序上运行的动作。
on_agent_finish
(finish, *, run_id[, ...])在代理端运行。
on_chain_end
(outputs, *, run_id[, ...])当链结束运行时运行。
on_chain_error
(error, *, run_id[, ...])当链式错误时运行。
on_chain_start
(serialized, inputs, *, run_id)当链开始运行时运行。
on_chat_model_start
(serialized, messages, *, ...)当聊天模型开始运行时运行。
on_llm_end
(response, **kwargs)当LLM运行结束时运行。
on_llm_error
(error, **kwargs)当LLM出现错误时运行。
on_llm_new_token
(token, **kwargs)在新的LLM令牌上运行。仅在流式传输启用时可用。
on_llm_start
(serialized, prompts, **kwargs)LLM 启动时运行。
on_retriever_end
(documents, *, run_id[, ...])在检索器端运行。
on_retriever_error
(error, *, run_id[, ...])在检索器错误时运行。
on_retriever_start
(serialized, query, *, run_id)在检索器启动时运行。
on_retry
(retry_state, *, run_id[, parent_run_id])在重试事件上运行。
on_text
(text, *, run_id[, parent_run_id, tags])在任意文本上运行。
on_tool_end
(output, *, run_id[, ...])当工具运行结束时运行。
on_tool_error
(error, *, run_id[, ...])当工具发生错误时运行。
on_tool_start
(serialized, input_str, *, run_id)当工具开始运行时运行。
- Parameters
answer_prefix_tokens (Optional[List[str]]) –
strip_tokens (bool) –
stream_prefix (bool) –
- Return type
None
- __init__(*, answer_prefix_tokens: Optional[List[str]] = None, strip_tokens: bool = True, stream_prefix: bool = False) None [source]¶
实例化AsyncFinalIteratorCallbackHandler。
- 参数:
- answer_prefix_tokens:前缀答案的令牌序列。
默认值为[“Final”, “Answer”, “:”]
- strip_tokens:在比较answer_prefix_tokens和最后的令牌时是否忽略空格和换行符?
(以确定是否已到达答案)
stream_prefix:答案前缀本身是否也应该被流式传输?
- Parameters
answer_prefix_tokens (Optional[List[str]]) –
strip_tokens (bool) –
stream_prefix (bool) –
- Return type
None
- async aiter() AsyncIterator[str] ¶
- Return type
AsyncIterator[str]
- async on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
在代理程序上运行的动作。
- Parameters
action (AgentAction) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
在代理端运行。
- Parameters
finish (AgentFinish) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
当链结束运行时运行。
- Parameters
outputs (Dict[str, Any]) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
当链式错误时运行。
- Parameters
error (BaseException) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) None ¶
当链开始运行时运行。
- Parameters
serialized (Dict[str, Any]) –
inputs (Dict[str, Any]) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
metadata (Optional[Dict[str, Any]]) –
kwargs (Any) –
- Return type
None
- async on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) Any ¶
当聊天模型开始运行时运行。
注意 : 此方法用于聊天模型。如果您正在为非聊天模型实现处理程序,则应改用on_llm_start。
- Parameters
serialized (Dict[str, Any]) –
messages (List[List[BaseMessage]]) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
metadata (Optional[Dict[str, Any]]) –
kwargs (Any) –
- Return type
Any
- async on_llm_end(response: LLMResult, **kwargs: Any) None [source]¶
当LLM运行结束时运行。
- Parameters
response (LLMResult) –
kwargs (Any) –
- Return type
None
- async on_llm_error(error: BaseException, **kwargs: Any) None ¶
当LLM出现错误时运行。
- 参数:
error: 发生的错误。 kwargs (Any): 附加的关键字参数。
response (LLMResult): 在错误发生之前生成的响应。
- Parameters
error (BaseException) –
kwargs (Any) –
- Return type
None
- async on_llm_new_token(token: str, **kwargs: Any) None [source]¶
在新的LLM令牌上运行。仅在流式传输启用时可用。
- Parameters
token (str) –
kwargs (Any) –
- Return type
None
- async on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) None [source]¶
LLM 启动时运行。
注意 : 当前方法用于非聊天模型(常规 LLM)。如果您正在为聊天模型实现处理程序,则应该使用 on_chat_model_start。
- Parameters
serialized (Dict[str, Any]) –
prompts (List[str]) –
kwargs (Any) –
- Return type
None
- async on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
在检索器端运行。
- Parameters
documents (Sequence[Document]) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
在检索器错误时运行。
- Parameters
error (BaseException) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) None ¶
在检索器启动时运行。
- Parameters
serialized (Dict[str, Any]) –
query (str) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
metadata (Optional[Dict[str, Any]]) –
kwargs (Any) –
- Return type
None
- async on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) Any ¶
在重试事件上运行。
- Parameters
retry_state (RetryCallState) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
kwargs (Any) –
- Return type
Any
- async on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
在任意文本上运行。
- Parameters
text (str) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_tool_end(output: Any, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
当工具运行结束时运行。
- Parameters
output (Any) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) None ¶
当工具发生错误时运行。
- Parameters
error (BaseException) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
kwargs (Any) –
- Return type
None
- async on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) None ¶
当工具开始运行时运行。
- Parameters
serialized (Dict[str, Any]) –
input_str (str) –
run_id (UUID) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
metadata (Optional[Dict[str, Any]]) –
inputs (Optional[Dict[str, Any]]) –
kwargs (Any) –
- Return type
None