prefactor_langchain.metadata_extractor module
prefactor_langchain.metadata_extractor module
Section titled “prefactor_langchain.metadata_extractor module”Utilities for extracting metadata from LangChain objects.
prefactor_langchain.metadata_extractor.extract_error_info(error: Exception) → ErrorInfo
Section titled “prefactor_langchain.metadata_extractor.extract_error_info(error: Exception) → ErrorInfo”Extract error information from an exception.
- Parameters: error – The exception to extract information from.
- Returns: ErrorInfo containing error details.
prefactor_langchain.metadata_extractor.extract_token_usage(response: Any) → TokenUsage | None
Section titled “prefactor_langchain.metadata_extractor.extract_token_usage(response: Any) → TokenUsage | None”Extract token usage from a ModelResponse.
Checks each message in response.result for usage_metadata
(the standard LangChain field populated by all providers), accumulating
totals across messages.
- Parameters: response – A ModelResponse object from LangChain.
- Returns: TokenUsage if available, None otherwise.