langchain.Utils
Utility functions and helpers for Langchain integration.
parse_langchain_provider
Parses langchain provider from serialized data
Arguments:
Name | Description |
---|---|
serialized | Dict[str, Any]: Serialized data to parse provider from |
Returns:
Name | Description |
---|---|
str | Parsed provider |
parse_langchain_llm_error
Parses langchain LLM error into a format that is accepted by Maxim logger
Arguments:
Name | Description |
---|---|
error | Union[Exception, KeyboardInterrupt]: Error to be parsed |
Returns:
Name | Description |
---|---|
[GenerationError](/sdk/python/references/logger/components/types) | Parsed LLM error |
parse_langchain_model_parameters
Parses langchain kwargs into model and model parameters. You can use this function with any langchain _start callback function
Arguments:
Name | Description |
---|---|
kwargs | Dict[str, Any]: Kwargs to be parsed |
Returns:
Tuple[str, Dict[str, Any]]: Model and model parameters
Raises:
Exception
- If model_name is not found in kwargs
parse_base_message_to_maxim_generation
Parses langchain BaseMessage into a format that is accepted by Maxim logger
Arguments:
Name | Description |
---|---|
message | BaseMessage |
Returns:
Dict[str, Any]: Parsed message
parse_langchain_message
Parses langchain BaseMessage into a choice of openai message
Arguments:
Name | Description |
---|---|
message | BaseMessage |
Returns:
Dict[str, Any]: Parsed message
parse_langchain_generation
Parses langchain generation into a format that is accepted by Maxim logger
Arguments:
Name | Description |
---|---|
generation | [Generation](/sdk/python/references/logger/components/generation): Generation to be parsed |
Returns:
Dict[str, Any]: Parsed generation
parse_token_usage_for_result
Parses token usage for a given LLM result
parse_langchain_chat_result
Parses langchain Chat result into a format that is accepted by Maxim logger
Arguments:
Name | Description |
---|---|
result | ChatResult: Chat result to be parsed |
Returns:
Dict[str, Any]: Parsed Chat result
Raises:
Exception
- If error parsing Chat result
parse_langchain_llm_result
Parses langchain LLM result into a format that is accepted by Maxim logger
Arguments:
Name | Description |
---|---|
result | LLMResult: LLM result to be parsed |
Returns:
Dict[str, Any]: Parsed LLM result
Raises:
Exception
- If error parsing LLM result
parse_langchain_messages
Parses langchain messages into messages that are accepted by Maxim logger
Arguments:
Name | Description |
---|---|
input | List[str] or List[List[Any]]: List of messages to be parsed |
default_role | str: Default role to assign to messages without a role |
Returns:
List[Dict[str, str]]: List of messages with role and content
Raises:
Exception
- If input is not List[str] or List[List[Any]]Exception
- If message type is not str or listException
- If message type is not recognized