Skip to content

Suggestion: Add a "mify objects" example to tutorial Chapter 5 #306

@psschwei

Description

@psschwei

As I was working my way through Chapter 5, one of the main questions I had was how to work with external dependencies. I found that info in one of the examples (

# You can also mify objects ad hoc.
class MyStoreClass:
def __init__(self, purchases: list[str]) -> None:
self.purchases: list[str]
store = MyStoreClass(["Beans", "Soil", "Watering Can"])
mify(store)
assert isinstance(store, MifiedProtocol)
# Now, you can use these objects in MelleaSessions.
store.format_for_llm()
m = start_session()
m.act(store)
# However, unless your object/class has a __str__ function,
# this won't do much good by itself. You need to specify how
# mellea should process these objects as text. You can do this by
# parameterizing mify.
@mify(stringify_func=lambda x: f"Chain Location: {x.location}") # type: ignore
class MyChain:
def __init__(self, location: str):
self.location = location
# M operations will now utilize that string representation of the
# object when interacting with it.
m.query(MyChain("Northeast"), "Where is my chain located?")
), but it could be helpful to include in the tutorial as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions