GitHub

decision_model

API reference for decision_model.

OpenAI's Decisions API as a DecisionModel (Effect's OpenAiDecisionModel)::

program.pipe(fx.provide(decision_model.model("gpt-6-luna").layer))

A string state is sent as input unchanged, any other state as JSON; with images, input is one user message with the state as text followed by the images (bytes and base64 text as data: URLs; a remote URL fails with InvalidUserInputError, OpenAI takes inline images only). Probability criteria are appended to the question's instructions, each rating level is sent with its label and description, and structured instructions and descriptions (and None) are sent as JSON text. Probabilities are rounded to two decimals, so their drift is accepted.

Types

TypeDefinitionDescription
Modeltype Model = Literal['gpt-6-luna']

Model names (any other string is accepted too).

Functions

make

make(*, model) -> Effect[DM.Service, Never, OpenAiClient]

A DecisionModel asking model through the OpenAiClient.

ParameterTypeDescription
modelModel | str

Returns Effect[DM.Service, Never, OpenAiClient]

def make(*, model: Model | str) -> Effect[DM.Service, Never, OpenAiClient]:
    """A ``DecisionModel`` asking ``model`` through the ``OpenAiClient``."""

    def build(client: ClientService) -> Effect[DM.Service]:
        def decide(
            options: DM.ProviderOptions[D.NonLocateDecision],
        ) -> Effect[DM.ProviderResponse, E.AiError]:
            images = options.images
            if images is not None and any(
                isinstance(i.image.data, Url) and i.image.data.protocol != "data:" for i in images
            ):
                return fx.fail(_remote_url_error())
            text = options.state if isinstance(options.state, str) else P.dumps(options.state)
            request: W.CreateDecisionsRequest = {
                "model": model,
                "input": text
                if images is None
                else [
                    {
                        "role": "user",
                        "content": [
                            {"type": "input_text", "text": text},
                            *(part for i in images for part in _image_content(i)),
                        ],
                    }
                ],
                "questions": [_question(name, d) for name, d in options.decisions.items()],
            }
            return client.create_decisions(request).map(
                lambda response: DM.ProviderResponse(
                    _answers(response, options.decisions),
                    response.get("usage", {}).get("input_tokens"),
                    response.get("usage", {}).get("output_tokens"),
                )
            )

        return DM.make(decide=decide, probability_precision=2, supports_images=True)

    return OpenAiClient().flat_map(build)

layer

layer(*, model) -> L.Layer[DM.DecisionModel, Never, OpenAiClient]

DecisionModel over the OpenAiClient.

ParameterTypeDescription
modelModel | str

Returns L.Layer[DM.DecisionModel, Never, OpenAiClient]

def layer(*, model: Model | str) -> L.Layer[DM.DecisionModel, Never, OpenAiClient]:
    """``DecisionModel`` over the ``OpenAiClient``."""
    return L.effect(DM.DecisionModel, make(model=model))

model

model(model) -> M.Model[DM.DecisionModel, OpenAiClient]

The decision model as a Model (provider "openai").

ParameterTypeDescription
modelModel | str

Returns M.Model[DM.DecisionModel, OpenAiClient]

def model(model: Model | str) -> M.Model[DM.DecisionModel, OpenAiClient]:
    """The decision model as a ``Model`` (provider ``"openai"``)."""
    return M.make("openai", model, layer(model=model))