Module: mellea.backends.types

Useful type definitions for models, formatters, and backends.

Classes

class mellea.backends.types.ModelOption()

A type that wraps around model options. Uses sentinel values (wrapped by @@@) to provide backend and model-agnostic keys for common model options. Create a dictionary containing model options like this:

from mellea.backends.types import ModelOption
model_options = { ModelOption.TEMPERATURE : 0.0, ModelOption.SYSTEM_PROMPT : "You are a helpful assistant" }

Methods

mellea.backends.types.ModelOption.replace_keys(options: dict, from_to: dict[str, str])
Returns a new dict with the keys in options replaced with the corresponding value for that key in from_to. If any keys already exist in options, don’t edit the associated value. Example:
>>> options = {"k1": "v1", "k2": "v2", "M1": "m1"}
>>> from_to = {"k1": "M1", "k2": "M2"}
>>> new_options = replace_keys(options, from_to)
>>> print(new_options)
... {"M1": "m1", "M2": "v2"}

mellea.backends.types.ModelOption.remove_special_keys(model_options)
Removes all sentiel-valued keys (i.e., those that start with @@@).
mellea.backends.types.ModelOption.merge_model_options(persistent_opts: dict[str, Any], overwrite_opts: dict[str, Any] | None)
Creates a new dict that contains all keys and values from persistent opts and overwrite opts. If there are duplicate keys, overwrite opts key value pairs will be used.