[go: up one dir, main page]

Skip to content

daft.functions.jev_prob#

jev_prob #

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

Probability that each row satisfies a plain-English condition.

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 customer is angry".

required
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 Float64 probability in [0, 1], or null where row is null.

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import jev_prob
>>> df = daft.from_pydict({"ticket": ["I was charged twice!!", "Thanks, all sorted."]})
>>> df = df.with_column("p_angry", jev_prob(df["ticket"], "the customer is angry"))
>>> df.sort("p_angry", desc=True).show()
Source code in daft/functions/jev_.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def jev_prob(
    row: Expression,
    condition: str,
    *,
    model: str | None = None,
    api_key: str | None = None,
    base_url: str | None = None,
    timeout: float = 60.0,
) -> Expression:
    """Probability that each row satisfies a plain-English condition.

    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 customer is angry".
        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 Float64 probability in [0, 1], or null where `row` is null.

    Examples:
        >>> import daft
        >>> from daft.functions import jev_prob
        >>> df = daft.from_pydict({"ticket": ["I was charged twice!!", "Thanks, all sorted."]})
        >>> df = df.with_column("p_angry", jev_prob(df["ticket"], "the customer is angry"))  # doctest: +SKIP
        >>> df.sort("p_angry", desc=True).show()  # doctest: +SKIP
    """
    return _client(api_key, model, base_url, timeout).noul(serialize(row, format="json"), condition)