Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "gen-worker"
version = "0.25.0"
version = "0.25.1"
description = "A library used to build custom functions in Cozy Creator's serverless function platform."
readme = "README.md"
license = "MIT"
Expand Down
8 changes: 6 additions & 2 deletions src/gen_worker/discovery/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,19 @@ def _stamp_family(binding_manifest: Dict[str, Any], family: str) -> None:

def _model_ref_to_manifest(ref: Any) -> Dict[str, Any]:
"""``default_checkpoint``/curated-choice ref shape shared by the slots
block: ``{source, path, tag?, flavor?, components?}`` — a structured
ModelRef (pgw#511; ``components`` added pgw#505)."""
block: ``{source, path, tag?, flavor?, revision?, version?, components?}``
— a structured ModelRef (pgw#511; ``components`` added pgw#505)."""
out: Dict[str, Any] = {"source": ref.source, "path": ref.path}
if ref.tag and ref.tag != "latest":
out["tag"] = ref.tag
if ref.flavor:
out["flavor"] = ref.flavor
if ref.components:
out["components"] = list(ref.components)
if ref.source in ("huggingface", "modelscope") and ref.revision:
out["revision"] = ref.revision
if ref.source == "civitai" and ref.version:
out["version"] = ref.version
return out


Expand Down
41 changes: 41 additions & 0 deletions tests/test_slot_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,47 @@ def generate(self, ctx: RequestContext, data: In_) -> Out_:
assert fn["bindings"]["vae"]["provider"] == "huggingface"


def test_slot_preserves_provider_pins_in_binding_and_default(tmp_pkg: Path) -> None:
from gen_worker.discovery.discover import discover_functions

pkg = tmp_pkg / "ep_slot_pins"
pkg.mkdir()
(pkg / "__init__.py").write_text("")
(pkg / "main.py").write_text(textwrap.dedent("""
import msgspec
from gen_worker import Civitai, HF, ModelScope, RequestContext, Slot, endpoint

class In_(msgspec.Struct):
prompt: str = ""

class Out_(msgspec.Struct):
y: str

@endpoint(models={
"pipeline": Slot(object, default_checkpoint=Civitai("827184", version="2883731")),
"hf": Slot(object, default_checkpoint=HF("owner/repo", revision="deadbeef")),
"modelscope": Slot(object, default_checkpoint=ModelScope("owner/repo", revision="v1")),
})
class Gen:
def setup(self, pipeline: object, hf: object, modelscope: object) -> None: ...
def generate(self, ctx: RequestContext, data: In_) -> Out_:
return Out_(y="ok")
"""))

(fn,) = discover_functions(tmp_pkg, main_module="ep_slot_pins.main")
slots = {slot["name"]: slot for slot in fn["slots"]}

assert fn["bindings"]["pipeline"]["ref"] == "827184"
assert fn["bindings"]["pipeline"]["version"] == "2883731"
assert slots["pipeline"]["default_checkpoint"] == {
"source": "civitai", "path": "827184", "version": "2883731",
}
assert fn["bindings"]["hf"]["revision"] == "deadbeef"
assert slots["hf"]["default_checkpoint"]["revision"] == "deadbeef"
assert fn["bindings"]["modelscope"]["revision"] == "v1"
assert slots["modelscope"]["default_checkpoint"]["revision"] == "v1"


def test_slot_with_no_selected_by_or_default_emits_minimal_block(tmp_pkg: Path) -> None:
from gen_worker.discovery.discover import discover_functions

Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading