Skip to content

Commit 790c319

Browse files
docs: add metadata to code block (#917)
* add metadata to code block Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com> * review comments Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com> --------- Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
1 parent 4b27e2e commit 790c319

29 files changed

Lines changed: 345 additions & 0 deletions

docs/docs/advanced/intrinsics.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ reliable than prompting a general-purpose model for these specialized micro-task
1919
Set up the backend once and reuse it across intrinsic calls:
2020

2121
```python
22+
# Requires: mellea[hf]
23+
# Returns: LocalHFBackend
2224
from mellea.backends.huggingface import LocalHFBackend
2325

2426
backend = LocalHFBackend(model_id="ibm-granite/granite-4.0-micro")
@@ -29,6 +31,8 @@ backend = LocalHFBackend(model_id="ibm-granite/granite-4.0-micro")
2931
Check whether a set of retrieved documents can answer a given question:
3032

3133
```python
34+
# Requires: mellea[hf]
35+
# Returns: bool
3236
from mellea.backends.huggingface import LocalHFBackend
3337
from mellea.stdlib.components import Document, Message
3438
from mellea.stdlib.components.intrinsic import rag
@@ -50,6 +54,8 @@ print(rag.check_answerability(question, docs_not_answerable, context, backend))
5054
Assess whether a document is relevant to a question:
5155

5256
```python
57+
# Requires: mellea[hf]
58+
# Returns: float
5359
from mellea.backends.huggingface import LocalHFBackend
5460
from mellea.stdlib.components import Document
5561
from mellea.stdlib.components.intrinsic import rag
@@ -72,6 +78,8 @@ print(result) # False — the document does not mention the CEO
7278
Flag sentences in an assistant response that are not grounded in the source documents:
7379

7480
```python
81+
# Requires: mellea[hf]
82+
# Returns: list[str]
7583
from mellea.backends.huggingface import LocalHFBackend
7684
from mellea.stdlib.components import Document, Message
7785
from mellea.stdlib.components.intrinsic import rag
@@ -99,6 +107,8 @@ print(result)
99107
Rewrite a vague or incomplete answer to be more grounded in the source documents:
100108

101109
```python
110+
# Requires: mellea[hf]
111+
# Returns: str
102112
from mellea.backends.huggingface import LocalHFBackend
103113
from mellea.stdlib.components import Document, Message
104114
from mellea.stdlib.components.intrinsic import rag
@@ -122,6 +132,8 @@ print(result)
122132
Rewrite an ambiguous user query using conversation history to improve retrieval:
123133

124134
```python
135+
# Requires: mellea[hf]
136+
# Returns: str
125137
from mellea.backends.huggingface import LocalHFBackend
126138
from mellea.stdlib.components import Message
127139
from mellea.stdlib.components.intrinsic import rag
@@ -147,6 +159,8 @@ print(result)
147159
Find supporting sentences in source documents for a given assistant response:
148160

149161
```python
162+
# Requires: mellea[hf]
163+
# Returns: dict
150164
from mellea.backends.huggingface import LocalHFBackend
151165
from mellea.stdlib.components import Document, Message
152166
from mellea.stdlib.components.intrinsic import rag
@@ -177,6 +191,8 @@ print(result)
177191
> `CustomIntrinsicAdapter` directly.
178192
179193
```python
194+
# Requires: mellea[hf]
195+
# Returns: dict
180196
import mellea.stdlib.functional as mfuncs
181197
from mellea.backends.adapters.adapter import CustomIntrinsicAdapter
182198
from mellea.backends.huggingface import LocalHFBackend

docs/docs/concepts/generative-functions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ is replaced by the LLM at call time — the signature and docstring guide the mo
1818
the output.
1919

2020
```python
21+
# Requires: mellea
22+
# Returns: str
2123
from typing import Literal
2224
from mellea import generative, start_session
2325

@@ -40,6 +42,8 @@ return anything else.
4042
Generative functions can also return Pydantic models for structured multi-field output:
4143

4244
```python
45+
# Requires: mellea, pydantic
46+
# Returns: FeedbackSummary
4347
from typing import Literal
4448
from pydantic import BaseModel
4549
from mellea import generative, start_session
@@ -70,6 +74,8 @@ Consider two independent libraries: one that summarizes documents, and one that
7074
decisions or risks from summaries.
7175

7276
```python
77+
# Requires: mellea
78+
# Returns: str
7379
from mellea import generative
7480

7581
# Summarizer library
@@ -105,6 +111,8 @@ To compose libraries safely without coupling them, use generative functions as c
105111
classifiers that gate whether a composition makes sense:
106112

107113
```python
114+
# Requires: mellea
115+
# Returns: str
108116
from typing import Literal
109117
from mellea import generative
110118

@@ -122,6 +130,8 @@ def has_structured_conclusion(summary: str) -> Literal["yes", "no"]:
122130
These contracts let you write dynamic composition logic in ordinary Python:
123131

124132
```python
133+
# Requires: mellea
134+
# Returns: None
125135
from mellea import start_session
126136

127137
m = start_session()

docs/docs/concepts/instruct-validate-repair.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ grounding context, few-shot examples, and images. The instruction is rendered th
1515
## Basic `instruct()`
1616

1717
```python
18+
# Requires: mellea
19+
# Returns: str
1820
import mellea
1921

2022
m = mellea.start_session()
@@ -32,6 +34,8 @@ Embed dynamic values in your description using `{{double_braces}}`. The descript
3234
is a Jinja2 template; values are injected at generation time via `user_variables`:
3335

3436
```python
37+
# Requires: mellea
38+
# Returns: str
3539
import mellea
3640

3741
def write_email(m: mellea.MelleaSession, name: str, notes: str) -> str:
@@ -60,6 +64,8 @@ Requirements are declarative constraints. They serve two purposes:
6064
Pass plain strings for LLM-checked requirements:
6165

6266
```python
67+
# Requires: mellea
68+
# Returns: str
6369
import mellea
6470

6571
m = mellea.start_session()
@@ -79,6 +85,8 @@ print(str(email))
7985
For deterministic checks, attach a `validation_fn` to a [`Requirement`](../reference/glossary#requirement):
8086

8187
```python
88+
# Requires: mellea
89+
# Returns: str
8290
from mellea import start_session
8391
from mellea.core import Requirement
8492
from mellea.stdlib.requirements import simple_validate
@@ -104,6 +112,8 @@ with a failure reason) into a validation function.
104112
`req()` and `check()` are concise constructors for `Requirement`:
105113

106114
```python
115+
# Requires: mellea
116+
# Returns: str
107117
from mellea import start_session
108118
from mellea.stdlib.requirements import check, req, simple_validate
109119

@@ -135,6 +145,8 @@ generates once, validates all requirements, and retries up to two times if any f
135145
Configure the loop explicitly with `strategy`:
136146

137147
```python
148+
# Requires: mellea
149+
# Returns: SamplingResult
138150
from mellea import start_session
139151
from mellea.stdlib.requirements import req, simple_validate
140152
from mellea.stdlib.sampling import RejectionSamplingStrategy

docs/docs/concepts/requirements-system.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ optional validation function. During the [instruct–validate–repair (IVR)](..
2626
4. The loop retries up to `loop_budget` times (default: 2).
2727

2828
```python
29+
# Requires: mellea
30+
# Returns: Requirement
2931
from mellea.core import Requirement
3032

3133
# Simplest form: natural-language string.
@@ -37,6 +39,8 @@ Passing plain strings directly to `instruct()` is equivalent — they are
3739
converted to `Requirement` objects internally:
3840

3941
```python
42+
# Requires: mellea
43+
# Returns: str
4044
import mellea
4145

4246
m = mellea.start_session()
@@ -51,6 +55,8 @@ email = m.instruct(
5155
`req()` and `check()` are concise constructors from `mellea.stdlib.requirements`:
5256

5357
```python
58+
# Requires: mellea
59+
# Returns: Requirement
5460
from mellea.stdlib.requirements import check, req
5561

5662
# req() creates a standard Requirement (description included in the prompt)
@@ -75,6 +81,8 @@ For deterministic checks, attach a `validation_fn`. Mellea skips LLM-as-a-judge
7581
runs your function directly:
7682

7783
```python
84+
# Requires: mellea
85+
# Returns: str
7886
from mellea import start_session
7987
from mellea.core import Requirement
8088
from mellea.stdlib.requirements import simple_validate
@@ -100,6 +108,8 @@ most recent model output as a string and returns either:
100108
repair request
101109

102110
```python
111+
# Requires: mellea
112+
# Returns: ValidationResult
103113
from mellea.stdlib.requirements import simple_validate
104114

105115
# Boolean return
@@ -117,6 +127,8 @@ within_limit = simple_validate(
117127
a full validation function directly, you construct `ValidationResult` yourself:
118128

119129
```python
130+
# Requires: mellea
131+
# Returns: ValidationResult
120132
from mellea.core import Context, ValidationResult
121133

122134

docs/docs/examples/resilient-rag-fallback.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Final answer
5858
### Inline script dependencies
5959

6060
```python
61+
# Requires: faiss-cpu, sentence-transformers, mellea
62+
# Returns: N/A
6163
# pytest: skip_always
6264
# /// script
6365
# requires-python = ">=3.12"
@@ -77,6 +79,8 @@ execution. No manual `pip install` is needed.
7779
### Imports and document corpus
7880

7981
```python
82+
# Requires: faiss-cpu, sentence-transformers, mellea
83+
# Returns: list[str]
8084
from faiss import IndexFlatIP
8185
from sentence_transformers import SentenceTransformer
8286

@@ -110,6 +114,8 @@ are L2-normalised, as `sentence-transformers` produces by default.
110114
### Index creation and querying
111115

112116
```python
117+
# Requires: faiss-cpu, sentence-transformers
118+
# Returns: IndexFlatIP
113119
def create_index(model, ds: list[str]) -> IndexFlatIP:
114120
print("running encoding... ")
115121
embeddings = model.encode(ds)
@@ -135,6 +141,8 @@ overwhelming the context window.
135141
### The relevance filter
136142

137143
```python
144+
# Requires: mellea
145+
# Returns: bool
138146
@generative
139147
def is_answer_relevant_to_question(answer: str, question: str) -> bool:
140148
"""For the given question, determine whether the answer is relevant or not."""
@@ -213,6 +221,8 @@ prompt correctly and trace each component independently.
213221
### Full file
214222

215223
```python
224+
# Requires: faiss-cpu, sentence-transformers, mellea
225+
# Returns: N/A
216226
# pytest: skip_always
217227
# /// script
218228
# requires-python = ">=3.12"

docs/docs/how-to/act-and-aact.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ fine-grained control, or building your own inference loops.
2222
These three snippets all produce the same result:
2323

2424
```python
25+
# Requires: mellea
26+
# Returns: str
2527
import mellea
2628
from mellea import start_session
2729
from mellea.stdlib import functional as mfuncs
@@ -49,6 +51,8 @@ result, new_ctx = mfuncs.act(instruction, context=ctx, backend=backend)
4951
Pass any `Component` to `act()`. It returns a `ModelOutputThunk`:
5052

5153
```python
54+
# Requires: mellea
55+
# Returns: str
5256
from mellea import start_session
5357
from mellea.stdlib.components import Instruction
5458

@@ -68,6 +72,8 @@ print(str(result))
6872
skip the IVR loop — this is what `chat()` does internally:
6973

7074
```python
75+
# Requires: mellea
76+
# Returns: str
7177
from mellea import start_session
7278
from mellea.stdlib.components import Message
7379

@@ -82,6 +88,8 @@ print(str(result))
8288
Pass document content directly in a `Message`:
8389

8490
```python
91+
# Requires: mellea
92+
# Returns: str
8593
from mellea import start_session
8694
from mellea.stdlib.components import Message
8795

@@ -106,6 +114,8 @@ For rich document processing (PDFs, tables), see
106114
The default is `RejectionSamplingStrategy(loop_budget=2)`:
107115

108116
```python
117+
# Requires: mellea
118+
# Returns: SamplingResult
109119
from mellea import start_session
110120
from mellea.core import Requirement
111121
from mellea.stdlib.components import Instruction
@@ -136,6 +146,8 @@ and validation.
136146
Pass a Pydantic `BaseModel` as the `format` parameter for constrained decoding:
137147

138148
```python
149+
# Requires: mellea, pydantic
150+
# Returns: Planet
139151
from pydantic import BaseModel
140152
from mellea import start_session
141153
from mellea.stdlib.components import Instruction
@@ -159,6 +171,8 @@ print(result.value) # A Planet instance
159171
> relying on a session to thread them.
160172
161173
```python
174+
# Requires: mellea
175+
# Returns: str
162176
from mellea.backends.ollama import OllamaModelBackend
163177
from mellea.stdlib import functional as mfuncs
164178
from mellea.stdlib.components import Instruction
@@ -185,6 +199,8 @@ simpler.
185199
`aact()` is the async counterpart. Same signature, same return types:
186200

187201
```python
202+
# Requires: mellea
203+
# Returns: None
188204
import asyncio
189205
from mellea import start_session
190206
from mellea.stdlib.components import Instruction
@@ -202,6 +218,8 @@ asyncio.run(main())
202218
The functional async version is `mfuncs.aact()`:
203219

204220
```python
221+
# Requires: mellea
222+
# Returns: tuple
205223
result, new_ctx = await mfuncs.aact(instruction, context=ctx, backend=backend)
206224
```
207225

0 commit comments

Comments
 (0)