Module: mellea.stdlib.mify

Mify classes and objects.

Functions

mellea.stdlib.mify.mify(query_type: type = Query, transform_type: type = Transform, fields_include: set[str] | None = None, fields_exclude: set[str] | None = None, funcs_include: set[str] | None = None, funcs_exclude: set[str] | None = None, template: str | None = None, template_order: str | list[str] | None = None, parsing_func: Callable[[str], T] | None = None, stringify_func: Callable[[T], str] | None = None)


mellea.stdlib.mify.mify(obj: T, query_type: type = Query, transform_type: type = Transform, fields_include: set[str] | None = None, fields_exclude: set[str] | None = None, funcs_include: set[str] | None = None, funcs_exclude: set[str] | None = None, template: str | None = None, template_order: str | list[str] | None = None, parsing_func: Callable[[str], T] | None = None, stringify_func: Callable[[T], str] | None = None)


mellea.stdlib.mify.mify(*args, **kwargs)

M-ify an object or class. Allows the object (or instances of the class) to be used in m sessions and with m functions. For the args below, only specify an _include or an _exclude of for fields and funcs. If both are specified, include takes precedence. If you specify the same item to be included and excluded, nothing will be included. If fields_include or fields_exclude are set:
  • the stringify_func will not be used to represent this object to the model
  • you must specify a template field or a template in the template_order field that handles a dict with those fields as keys
  • it’s advised to use fields_include due to the many dunder fields and inherited fields an object/class might have
Mify sets attributes on the object/class. If the object isn’t already an mified/mobject, it will overwrite the attributes and methods of the object/class necessary for it to be mified.

Arguments

  • obj: either a class or an instance of the class
  • fields_include: fields of the object to include in its representation to models
  • fields_exclude: fields of the object to exclude from its representation to models
  • funcs_include: functions of the object to include in its representation to models
  • funcs_exclude: functions of the object to exclude from its representation to models
  • query_type: a specific query component type to use when querying a model
  • transform_type: a specific transform component type to use when transforming with a model
  • template: a string representation of a jinja template; takes precedence over template_order
  • template_order: a template ordering to use when searching for applicable templates
  • parsing_func: not yet implemented
  • stringify_func: used to create a string representation of the object
An object if an object was passed in or a decorator (callable) to mify classes. If an object is returned, that object will be the same object that was passed in. For example,
obj = mify(obj)
obj.format_for_llm()
and
mify(obj)
obj.format_for_llm()
are equivalent. Most IDEs will not correctly show the type hints for the newly added functions for either an mify object or instances of an mified class. For IDE support, write
assert isinstance(obj, MifiedProtocol)

mellea.stdlib.mify._mify(obj: T | None = None, query_type: type = Query, transform_type: type = Transform, fields_include: set[str] | None = None, fields_exclude: set[str] | None = None, funcs_include: set[str] | None = None, funcs_exclude: set[str] | None = None, template: str | None = None, template_order: str | list[str] | None = None, parsing_func: Callable[[str], object] | None = None, stringify_func: Callable[[object], str] | None = None)

Returns either a decorator or the mified object.

mellea.stdlib.mify._get_non_duplicate_members(object: object, check_duplicates: object)

Returns all methods/functions unique to the object.

mellea.stdlib.mify._get_non_duplicate_fields(object: object, check_duplicates: object)

Returns all fields unique to the object.

Classes

class mellea.stdlib.mify.MifiedProtocol()

Adds additional functionality to the MObjectProtocol and modifies MObject functions so that mified objects can be more easily interacted with and modified. See the mify decorator for more information.

Methods

mellea.stdlib.mify.MifiedProtocol.parts()
Returns a list of parts for MObject. [no-index]
mellea.stdlib.mify.MifiedProtocol.get_query_object(query: str)
Returns the instantiated query object. [no-index]

Arguments

  • query: The query string.

mellea.stdlib.mify.MifiedProtocol.get_transform_object(transformation: str)
Returns the instantiated transform object. [no-index]

Arguments

  • transformation: the transform string

mellea.stdlib.mify.MifiedProtocol.content_as_string()
Returns the content of the Mified object as a string. [no-index] Will use the passed in stringify function if provided.
mellea.stdlib.mify.MifiedProtocol._get_all_members()
Returns a dict of methods from this object that are not shared with the object base class. Undocumented methods and methods with [no-index] in doc string are ignored. It will also take into consideration its funcs_include and funcs_exclude fields. Functions that were specifically included will ignore the undocumented and [no-index] requirements. See mify decorator for more info.
mellea.stdlib.mify.MifiedProtocol._get_all_fields()
Returns a dict of fields that are not shared with the object superclass. This will return dunder fields as well. As a result, it’s advised to always set fields_include if using this. [no-index] It will also take into consideration its fields_include and fields_exclude fields. See mify decorator for more info.
mellea.stdlib.mify.MifiedProtocol.format_for_llm()
The representation of an object given to the backend. [no-index] Sets the TemplateRepresentation fields based on the object and the values specified during mify. See mify decorator for more details.