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.
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 (
mellea/docs/examples/mify/mify.py
Lines 21 to 49 in 7013b04