Skip to content

Commit 3326c18

Browse files
HendrikStrobeltGitHub Enterprise
authored andcommitted
making MCP example a bit faster to respond + adding comments; (#31)
small bugfix in project file
1 parent 4588540 commit 3326c18

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

docs/examples/tutorial/mcp_example.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
"""Example of an MCP server
2+
3+
You need to install the mcp package:
4+
uv pip install "mcp[cli]"
5+
6+
and run the example in MCP debug UI:
7+
uv run mcp dev docs/examples/tutorial/mcp_example.py
8+
"""
9+
110
from mcp.server.fastmcp import FastMCP
211

312
from mellea import MelleaSession
4-
from mellea.backends import model_ids
13+
from mellea.backends import ModelOption, model_ids
514
from mellea.backends.ollama import OllamaModelBackend
615
from mellea.stdlib.base import ModelOutputThunk
716
from mellea.stdlib.requirement import Requirement, simple_validate
817
from mellea.stdlib.sampling import RejectionSamplingStrategy
918

1019
# #################
11-
# run MCP debug UI with: uv run mcp dev docs/examples/mcp/mcp_example.py
20+
# run MCP debug UI with: uv run mcp dev docs/examples/tutorial/mcp_example.py
1221
# ##################
1322

1423

@@ -19,7 +28,12 @@
1928
@mcp.tool()
2029
def write_a_poem(word_limit: int) -> str:
2130
"""Write a poem with a word limit."""
22-
m = MelleaSession(OllamaModelBackend(model_ids.QWEN3_8B))
31+
m = MelleaSession(
32+
OllamaModelBackend(
33+
model_ids.HF_SMOLLM2_2B,
34+
model_options={ModelOption.MAX_NEW_TOKENS: word_limit + 10},
35+
)
36+
)
2337
wl_req = Requirement(
2438
f"Use only {word_limit} words.",
2539
validation_fn=simple_validate(lambda x: len(x.split(" ")) < word_limit),
@@ -28,7 +42,7 @@ def write_a_poem(word_limit: int) -> str:
2842
res = m.instruct(
2943
"Write a poem",
3044
requirements=[wl_req],
31-
strategy=RejectionSamplingStrategy(loop_budget=4),
45+
strategy=RejectionSamplingStrategy(loop_budget=2),
3246
)
3347
assert isinstance(res, ModelOutputThunk)
3448
return str(res.value)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ authors = [
1515
{ name = "Xiaojie Guo", email = "[email protected]" },
1616
{ name = "Jake LoRocco", email = "[email protected]" }
1717
]
18-
description = "mellea is a librarty for writing generative programs"
18+
description = "mellea is a library for writing generative programs"
1919
readme = "README.md"
2020
requires-python = ">=3.11"
2121
classifiers = [

0 commit comments

Comments
 (0)