Repository navigation
feat: rename generative slots -> generative stubs - #801
Conversation
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
d417e7d to
5ff79b5
Compare
There was a problem hiding this comment.
(testing out some things with this review. review was AI generated but human reviewed/approved)
Code Review
The rename is thorough and mechanically correct across ~40 files — nice work on the coverage. A few items to consider before merge:
1. No backward-compatibility shim for genslot import path
The module mellea.stdlib.components.genslot is deleted with no re-export. Multiple doc pages teach users from mellea.stdlib.components.genslot import PreconditionException — external code following current docs will get ModuleNotFoundError on upgrade.
Suggestion: Add a minimal genslot.py shim with a deprecation warning, or explicitly document this as a breaking change in the upcoming release's CHANGELOG (not by rewriting old entries).
2. docs/metrics/coverage-current.json not updated
Lines 1822, 1838, 1875 still reference mellea.stdlib.components.genslot. If this file is auto-generated and gets regenerated, no action needed — but if it's checked by CI it could break.
3. CHANGELOG history rewriting
Historical entries at lines 242/275 were changed from "genslot"/"gen slots" to "genstub"/"gen stubs". Standard practice is to leave historical entries untouched and add a rename note under the current version's section. I'd recommend reverting those edits and adding a new entry instead.
Minor
docs/docs/docs.json:448— Mintlify redirect still says/core-concept/generative-slots. This is arguably correct (preserves old bookmarks), but worth an explicit decision.- Notebook formatting — Two
.ipynbfiles had theirsourcearrays collapsed to single strings. Valid JSON but creates unnecessary diff noise.
Overall the rename itself is clean and consistent — template file + template_order are correctly in sync, all class/variable/error-message references are updated, and good call checking the tutorials repo too.
5ff79b5 to
f1da2ca
Compare
|
Makes sense!
I also added an |
|
@planetf1, can you please comment on:
I didn't see any code that references this and my understanding of the above statement is this is to make bookmarks keep working form the old version of the website. I think we should leave this as is? |
f1da2ca to
acc81ad
Compare
Yeah, I think so too (should've probably dropped that, was testing an automated PR review workflow, guess it could use a little tweaking still 😉 ) |
I think it may be too early to focus on keeping all our doc URLs stable.. I would stick to what we deem to be the main entry points (maybe just the docs themselves), otherwise we'll start making things complex to maintain. Most of the entries in docs.json are effectively 1:1 mappings for clarity - I'd mostly go for that approach unless we have a good reason not to. One thing to be careful of is any inbound links from the landing page (since that is a distinct repo). We could have a 'contract' where we keep that nominated list stable - but nothing formalized currently. That being said, the website doesn't currently point to generative-slots (or stubs) I'd therefore be inclined to update the source/destination to be in sync (which would break a bookmark) - but that's more driven by the lack of explicit policy to preserve links and keep things simple rather than any objection to the naming being used.... |
|
Sounds good. I will leave the bookmarks / links untouched for now. |
…ng#801) * feat: rename generative slots -> generative stubs * feat: add backwards compat with deprecation warning; add genslot fixer cli
…KING returns generative-computing#1504 fixed generative-computing#1503 by switching two `genstub.py` call sites to `inspect.signature(func, eval_str=True)`. That resolves postponed parameter annotations, but it also evaluates the return annotation, so an unresolvable return type — a `TYPE_CHECKING`-only import, or a forward reference — raises `NameError` at both sites even when every parameter resolves cleanly: - `get_argument` reads only the named parameter's annotation, so the return annotation is incidental and resolving it should never fail the call. - `describe_function` renders the signature into the prompt via `GenerativeStub.jinja2`, so the return annotation *is* consumed by the model. An unresolvable one is therefore left as its postponed string and renders quoted — `-> 'Decimal'` — which still names the type, rather than being dropped from the prompt. The alternative, omitting it entirely, tells the model less. Both now use the shared `resolve_signature_annotations` helper. The generative-computing#1503 behaviour is unchanged for resolvable annotations: the existing assertions that no parameter renders quoted still pass. Scope of what generative-computing#1504 actually broke: only *direct* calls to these two functions, which previously returned a quoted string rather than raising. No `@generative` user could observe it, because `create_response_format` already failed earlier in `GenerativeStub.__init__` — a separate defect dating to `88a4d754` (generative-computing#801), not to generative-computing#1504. That one is fixed in the following commit; see generative-computing#1529. Also renames `_pep563_fixtures.py` to `_postponed_annotation_samples.py` with its call sites, per review feedback on this PR: the module holds no `@pytest.fixture`, and the PEP number does not belong in the filename. The backends equivalent was renamed on that basis; this one merged under the old name via generative-computing#1504. The import and an assertion embedding the full module path are both updated. Verified: both new tests fail against the pre-fix code with `NameError`. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
…eturn types (generative-computing#1509) * fix(backends): resolve postponed annotations in ollama tool schema convert_function_to_ollama_tool read raw inspect.signature() annotations, which are unresolved strings under `from __future__ import annotations` (PEP 563). Pydantic could not build a schema for any non-builtin parameter type, raising PydanticUserError. Resolve with eval_str=True, matching the fix already applied to genstub.py for the same root cause. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(backends): resolve postponed annotations per-parameter to avoid return annotation regression Assisted-by: opencode Signed-off-by: Nigel Jones <[email protected]> * test(backends): fold postponed-annotation tests into existing tool test module Addresses review feedback on generative-computing#1509. The PEP 563 regression tests were moved into test_discriminated_union_tools.py, already the only module exercising convert_function_to_ollama_tool, rather than living in a second module for the same function. The previous change only renamed the standalone file instead of moving the tests, which did not address the review. Also renames the samples module to _postponed_annotation_samples.py, dropping the PEP number from the filename as requested. The module-level 'from __future__ import annotations' still requires the sample code to sit in its own module; only the tests move. Verified the moved tests are not vacuous: against the pre-fix baseline 2 of 4 fail, and against parameter-blind eval_str=True resolution 3 of 4 fail. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * test(backends): guard TC-only postponed-annotation tests against silent no-op Adds the same precondition assert the first test in TestPostponedAnnotations already has to the three TYPE_CHECKING-only cases, confirming their sample annotations are still postponed strings. Without it, dropping `from __future__ import annotations` from _postponed_annotation_samples.py would make these tests pass without exercising the resolution path at all. Ref generative-computing#1507 Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(backends): resolve tool annotations in the wrapped function's module `inspect.signature` follows `__wrapped__`, so the annotations reaching the per-parameter fallback can belong to a function in a different module than the object passed in. Reading globals from that object meant a `functools.wraps` decorator's module supplied the resolution namespace, so a colliding type name resolved to the wrong type and produced a silently incorrect tool schema where the previous code raised `PydanticUserError`. Take the namespace from `inspect.unwrap(func, stop=...)`, using the same stop predicate `inspect.signature` itself uses, so both read the same object. This is a no-op for undecorated functions. Also from review: - correct the lead comment, which described the per-parameter loop as being used instead of `eval_str=True` rather than as its fallback - log the unresolved annotation at debug rather than swallowing it silently - record why the `eval` is bounded, next to its noqa - guard the TYPE_CHECKING-only tests so they fail instead of passing vacuously if the sample module's import moves out of `if TYPE_CHECKING:` - match on the unresolved name in the `PydanticUserError` assertion Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * refactor(backends): log why the tool annotation fallback engaged The outer `except` around `inspect.signature(func, eval_str=True)` discarded the exception entirely, while the per-parameter handler inside it logs at debug. That asymmetry meant there was no way to tell why the fallback had engaged for a given tool without attaching a debugger. Log the exception type and message at debug, matching the inner handler. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * test(backends): cover a colliding type name in wrapped tool resolution `test_decorated_tool_resolves_in_wrapped_functions_module` covers a type name absent from the decorator's module, which degrades loudly to `PydanticUserError`. It does not cover the worse case the namespace fix exists for: a name that is present in the decorator's module but bound to a different type, where resolving in the wrong namespace succeeds and emits a plausible-looking schema for entirely the wrong type. Add `Zone` to the samples module and a shadowing `Zone` with a different field in the test module, so a wrapper defined in the test module resolves against the wrong binding under the previous behaviour. Verified the new test fails without the `inspect.unwrap` namespace fix, producing a schema with `wrong_field: integer` in place of `identifier: string` and raising nothing. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * refactor(backends): extract postponed-annotation resolution into a helper The try-`eval_str`-then-resolve-per-parameter logic is needed by more than one call site, so move it out of `convert_function_to_ollama_tool` into `mellea/helpers/annotation_helpers.resolve_signature_annotations`. Imported directly from the submodule rather than re-exported through `mellea/helpers/__init__.py`, matching how `tools.py` already imports `_run_async_in_thread`. That keeps it out of the public API surface. No behavioural change: the existing tool-conversion tests pass unmodified. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * test(backends): cover an unannotated parameter in the annotation fallback In the per-parameter fallback an unannotated parameter arrives as `inspect._empty` rather than a string, so it takes the branch that skips resolution. Nothing exercised that branch, leaving the helper at 75% branch coverage. Add a sample with one bare and one annotated parameter alongside a TYPE_CHECKING-only return, and assert the bare one still reaches the schema defaulting to `str`. Takes the helper to 100% statement and branch coverage. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(stdlib): resolve genstub annotations without failing on TYPE_CHECKING returns generative-computing#1504 fixed generative-computing#1503 by switching two `genstub.py` call sites to `inspect.signature(func, eval_str=True)`. That resolves postponed parameter annotations, but it also evaluates the return annotation, so an unresolvable return type — a `TYPE_CHECKING`-only import, or a forward reference — raises `NameError` at both sites even when every parameter resolves cleanly: - `get_argument` reads only the named parameter's annotation, so the return annotation is incidental and resolving it should never fail the call. - `describe_function` renders the signature into the prompt via `GenerativeStub.jinja2`, so the return annotation *is* consumed by the model. An unresolvable one is therefore left as its postponed string and renders quoted — `-> 'Decimal'` — which still names the type, rather than being dropped from the prompt. The alternative, omitting it entirely, tells the model less. Both now use the shared `resolve_signature_annotations` helper. The generative-computing#1503 behaviour is unchanged for resolvable annotations: the existing assertions that no parameter renders quoted still pass. Scope of what generative-computing#1504 actually broke: only *direct* calls to these two functions, which previously returned a quoted string rather than raising. No `@generative` user could observe it, because `create_response_format` already failed earlier in `GenerativeStub.__init__` — a separate defect dating to `88a4d754` (generative-computing#801), not to generative-computing#1504. That one is fixed in the following commit; see generative-computing#1529. Also renames `_pep563_fixtures.py` to `_postponed_annotation_samples.py` with its call sites, per review feedback on this PR: the module holds no `@pytest.fixture`, and the PEP number does not belong in the filename. The backends equivalent was renamed on that basis; this one merged under the old name via generative-computing#1504. The import and an assertion embedding the full module path are both updated. Verified: both new tests fail against the pre-fix code with `NameError`. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(stdlib): survive an unresolvable return type at stub decoration time `create_response_format` resolves annotations with `get_type_hints`, which evaluates every annotation including the return type. `GenerativeStub.__init__` calls it, so a `@generative` stub whose return type exists only under `if TYPE_CHECKING:` raised `NameError` at decoration time — meaning the containing module could not be imported at all, with no model call involved. Only the return type is read here, and an unannotated function already falls back to `Any` via `type_hints.get("return", Any)`. Degrade an unresolvable return to that same `Any` rather than failing the decoration. The response model then parses the result as `Any` instead of the declared type, which is the behaviour an unannotated stub already gets. The earlier commit in this PR fixed `describe_function` and `get_argument` but missed this site, and CI passed regardless: both tests called those functions directly, so nothing exercised the `@generative` decoration path. Add a test at that entry point as well as one for `create_response_format` itself. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]>
Misc PR
Type of PR
Description
We were requested to rename GenerativeSlots -> GenerativeStubs. I've gone through this repo and other mellea repos (tutorials, demos, contribs, website). The only other reference was in tutorials. I've opened a PR here.
Testing