Skip to content

Commit 0388379

Browse files
committed
Adds a simple lazy example.
1 parent fd12ecb commit 0388379

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/examples/melp/lazy.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import asyncio
2+
from mellea.stdlib.span import Span, SimpleComponent
3+
from mellea.stdlib.base import SimpleContext, Context, CBlock, ModelOutputThunk
4+
from mellea.backends import Backend
5+
from mellea.backends.ollama import OllamaModelBackend
6+
7+
backend = OllamaModelBackend("granite4:latest")
8+
9+
10+
async def main(backend: Backend, ctx: Context):
11+
s1 = CBlock("What is 1+1? Respond with the number only.")
12+
s1_out, _ = await backend.generate_from_context(action=s1, ctx=SimpleContext())
13+
14+
s2 = CBlock("What is 2+2? Respond with the number only.")
15+
s2_out, _ = await backend.generate_from_context(action=s2, ctx=SimpleContext())
16+
17+
sc1 = SimpleComponent(
18+
instruction="What is x+y? Respond with the number only", x=s1_out, y=s2_out
19+
)
20+
21+
print(await s1_out.avalue())
22+
print(await s2_out.avalue())
23+
24+
sc1_out, _ = await backend.generate_from_context(action=sc1, ctx=SimpleContext())
25+
26+
print(await sc1_out.avalue())
27+
28+
29+
asyncio.run(main(backend, SimpleContext()))

0 commit comments

Comments
 (0)