Skip to content

trulens.core.utils.signature

trulens.core.utils.signature

Utilities related to guessing inputs and outputs of functions.

Functions

_extract_content

_extract_content(value, content_keys=['content'])

Extracts the 'content' from various data types commonly used by libraries like OpenAI, Canopy, LiteLLM, etc. This method navigates nested data structures (pydantic models, dictionaries, lists) to retrieve the 'content' field. If 'content' is not directly available, it attempts to extract from known structures like 'choices' in a ChatResponse. This standardizes extracting relevant text or data from complex API responses or internal data representations.

PARAMETER DESCRIPTION
value

The input data to extract content from. Can be a pydantic model, dictionary, list, or basic data type.

RETURNS DESCRIPTION

The extracted content, which may be a single value, a list of values,

or a nested structure with content extracted from all levels.

main_input

main_input(
    func: Callable, sig: Signature, bindings: BoundArguments
) -> str

Determine (guess) the main input string for a main app call.

PARAMETER DESCRIPTION
func

The main function we are targeting in this determination.

TYPE: Callable

sig

The signature of the above.

TYPE: Signature

bindings

The arguments to be passed to the function.

TYPE: BoundArguments

RETURNS DESCRIPTION
str

The main input string.

main_output

main_output(func: Callable, ret: Any) -> str

Determine (guess) the "main output" string for a given main app call.

This is for functions whose output is not a string.

PARAMETER DESCRIPTION
func

The main function whose main output we are guessing.

TYPE: Callable

ret

The return value of the function.

TYPE: Any