[go: up one dir, main page]

Skip to content

daft.functions.jev#

jev #

jev(row: Expression, condition: str, threshold: float = 0.5, *, model: str | None = None, api_key: str | None = None, base_url: str | None = None, timeout: float = 60.0) -> Expression

Whether each row satisfies a plain-English condition, i.e. jev_prob(row, condition) >= threshold.

Parameters:

Name Type Description Default
row Expression

The value to judge. Pass to_struct(...) to judge several columns; field names are visible to the model.

required
condition str

A plain-English condition, e.g. "the name is European".

required
threshold float

The minimum probability that counts as true. Defaults to 0.5.

0.5
model str | None

The Jev model. Defaults to TYPESAFE_DEFAULT_MODEL, else jev-latest.

None
api_key str | None

TypeSafe API key. Defaults to TYPESAFE_API_KEY.

None
base_url str | None

API root, e.g. to route through a proxy. Defaults to TYPESAFE_BASE_URL, else https://api.typesafe.ai.

None
timeout float

Seconds allowed for each request, which carries up to 25 rows. Defaults to 60.

60.0

Returns:

Name Type Description
Expression Expression

A Boolean, or null where row is null.

Examples:

1
2
3
4
>>> import daft
>>> from daft.functions import jev, to_struct
>>> df = daft.from_pydict({"first": ["Hans", "Mei"], "last": ["Müller", "Chen"]})
>>> df.where(jev(to_struct(df["first"], df["last"]), "the name is European")).show()
Source code in daft/functions/jev_.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def jev(
    row: Expression,
    condition: str,
    threshold: float = 0.5,
    *,
    model: str | None = None,
    api_key: str | None = None,
    base_url: str | None = None,
    timeout: float = 60.0,
) -> Expression:
    """Whether each row satisfies a plain-English condition, i.e. `jev_prob(row, condition) >= threshold`.

    Args:
        row (Expression): The value to judge. Pass `to_struct(...)` to judge several columns; field names are visible to the model.
        condition (str): A plain-English condition, e.g. "the name is European".
        threshold (float): The minimum probability that counts as true. Defaults to 0.5.
        model (str | None): The Jev model. Defaults to `TYPESAFE_DEFAULT_MODEL`, else `jev-latest`.
        api_key (str | None): TypeSafe API key. Defaults to `TYPESAFE_API_KEY`.
        base_url (str | None): API root, e.g. to route through a proxy. Defaults to `TYPESAFE_BASE_URL`, else `https://api.typesafe.ai`.
        timeout (float): Seconds allowed for each request, which carries up to 25 rows. Defaults to 60.

    Returns:
        Expression: A Boolean, or null where `row` is null.

    Examples:
        >>> import daft
        >>> from daft.functions import jev, to_struct
        >>> df = daft.from_pydict({"first": ["Hans", "Mei"], "last": ["Müller", "Chen"]})
        >>> df.where(jev(to_struct(df["first"], df["last"]), "the name is European")).show()  # doctest: +SKIP
    """
    return jev_prob(row, condition, model=model, api_key=api_key, base_url=base_url, timeout=timeout) >= lit(threshold)