-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathquickstart.py
More file actions
38 lines (30 loc) · 1.1 KB
/
Copy pathquickstart.py
File metadata and controls
38 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# pytest: ollama, e2e
#
# Quick Start — your first Mellea plugin in under 30 lines.
#
# This example registers a single function hook that logs every generation
# call, then runs a normal instruct() to show it in action.
#
# Run:
# uv run python docs/examples/plugins/quickstart.py
import logging
from mellea import start_session
from mellea.plugins import HookType, hook, register
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
)
logging.getLogger("httpx").setLevel(logging.ERROR)
logging.getLogger("mellea").setLevel(logging.ERROR)
log = logging.getLogger("quickstart")
@hook(HookType.GENERATION_PRE_CALL)
async def log_generation(payload, ctx):
"""Log a one-line summary before every LLM call."""
action_preview = str(payload.action)[:80].replace("\n", " ")
log.info("[log_generation] About to call LLM: %r", action_preview)
register(log_generation)
if __name__ == "__main__":
with start_session() as m:
result = m.instruct("What is the capital of France?")
log.info("Result: %s", result)