eq
Signature:
eq(a, b)
Compare two values for exact equality.
| Parameter | Type | Default | Description |
|---|---|---|---|
| a | None | None | First value to compare |
| b | None | None | Second value to compare |
| :Returns: | float | - | Returns 0 if values are equal, infinity if they differ |
safe_eval
Signature:
safe_eval(out, expression)
Safely evaluate a Python expression with a provided value.
This function takes a value and a Python expression template, formats the expression with the value, and evaluates it safely. It handles various error cases and type conversions.
| Parameter | Type | Default | Description |
|---|---|---|---|
| out | None | None | Value to insert into the expression template |
| expression | str | None | Python expression template with {} placeholder for the value |
| :Returns: | float | - | - For boolean results: 0 if True, infinity if False - For float results: the float value directly - For errors or invalid types: infinity |
chat_eval
Signature:
chat_eval(out: Any, expected: Any, model: str = 'gpt-4o-mini', system_prompt: str = None) -> float
Evaluate similarity between two values using a language model.
This function uses a language model to compare two values and return a similarity score. It can use either a default system prompt or a custom one to guide the evaluation.
| Parameter | Type | Default | Description |
|---|---|---|---|
| out | typing.Any | None | First value to compare |
| expected | typing.Any | None | Second value to compare |
| model | <class ‘str’> | gpt-4o-mini | Language model to use. Defaults to “gpt-4o-mini” |
| system_prompt | <class ‘str’> | None | Custom system prompt for evaluation. Must contain{{out}} and {{expected}} jinja variables. If None, uses default prompt. |
| :Returns: | <class ‘float’> | - | Similarity score between 0 and 1, where: - 0 indicates lowest similarity - 1 indicates highest similarity |
cosine_dist
Signature:
cosine_dist(out: str, expected: str, model: str = 'text-embedding-3-small') -> float
Compute cosine distance between two strings using OpenAI embeddings.
This function converts two strings into embeddings using OpenAI’s embedding model and computes the cosine distance between them. The distance is normalized by the norm of the expected embedding.
| Parameter | Type | Default | Description |
|---|---|---|---|
| out | <class ‘str’> | None | First string to compare |
| expected | <class ‘str’> | None | Second string to compare |
| model | <class ‘str’> | text-embedding-3-small | OpenAI embedding model to use. Defaults to ‘text-embedding-3-small’ |
| :Returns: | <class ‘float’> | - | Cosine distance between the strings If out is not a string, returns inf |
eval_any
Signature:
eval_any(out: Any, expected: Any) -> float
Accept any value by always returning 0 distance.
This function is used to verify the existence of a key or value without caring about its actual content. It always returns 0, indicating a perfect match regardless of the input values.
| Parameter | Type | Default | Description |
|---|---|---|---|
| out | typing.Any | None | First value (ignored) |
| expected | typing.Any | None | Second value (ignored) |
| :Returns: | <class ‘float’> | - | Always returns 0, indicating a perfect match |