feat: simplify intrinsics (code and examples)#946
Conversation
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com> Assisted-by: CLAUDE:OPUS
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com> Assisted-by: CLAUDE:OPUS
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com> Assisted-by: CLAUDE:OPUS
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com> Assisted-by: CLAUDE:OPUS
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com>
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com>
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com> Assisted-by: CLAUDE:OPUS
ajbozarth
left a comment
There was a problem hiding this comment.
Three inline comments below. General notes:
Circular import pattern (start_backend.py ↔ session.py): session.py does a top-level import of start_backend, while start_backend.py defers its import of _resolve_backend_and_context inside the function body to avoid the cycle. Works at runtime, but fragile — the impl file depends on a private helper from another module. Cleaner to move _resolve_backend_and_context / _resolve_context into a _session_util.py that both files import independently.
Merge surface with #881: Both PRs touch _util.py, rag.py, and all the docs/examples/intrinsics/ files. The changes are orthogonal (this PR adds the coerce/resolve helpers; #881 extends call_intrinsic to support OpenAIBackend) but the merge will need care to keep both. Also: citations.py here drops the explicit doc_id="1" / doc_id="2" in favour of auto_doc_id=True (0-indexed). #881 also modifies that file — verify the final merged example has consistent IDs and matches whatever the intrinsic test fixtures expect.
Return type fixes — rewrite_question and check_context_relevance were both typed -> float; now correctly -> str. Good catches.
| ) | ||
| else: | ||
| model_id_str = str(model_id) | ||
| resolved_ctx, backend, model_id_str = _resolve_backend_and_context( |
There was a problem hiding this comment.
Regression: this constructs the backend (including passing model_options to the constructor) before the SESSION_PRE_INIT hook runs. In the original code the hook ran first and the backend was built with the hook's (potentially modified) model_options. Now the hook updates the local model_options variable on line 291 but the backend never sees it.
Fix: split this helper — call _resolve_context here for early argument validation, then construct the backend after the hook block.
There was a problem hiding this comment.
Resolved; split functionality up and calling the backend creation post hook.
…ssage for intrinsics Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com> Assisted-by: CLAUDE:OPUS
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com> Assisted-by: CLAUDE:OPUS
Fixed the circular imports. Split up functionality and moved everything to start backend. We don't need a separate utils function. session can just import from start_backend.
I tested all intrinsic examples. Functionality is the same. I will resolve merge conflicts in the other PR. This PR takes precedence. |
ajbozarth
left a comment
There was a problem hiding this comment.
All three issues from the previous round are addressed — hook ordering fixed, unreachable assert removed, misleading comment removed. One remaining concern with no specific line to attach: the hook ordering fix has no regression test. A unit test that patches invoke_hook to mutate model_options and asserts the backend was constructed with the updated value would lock this in.
| _resolve_context, | ||
| _resolve_model_id_str, | ||
| backend_name_to_class, | ||
| start_backend, |
There was a problem hiding this comment.
session.py imports start_backend here but never calls it. The only effect is exposing mellea.stdlib.session.start_backend as an importable path, which test_session_unit.py relies on. Remove this import and update the test to import from the canonical location (mellea.stdlib.start_backend or mellea) instead.
| if backend_class is None: | ||
| raise Exception( | ||
| f"Backend name {backend_name} unknown. Please see the docstring for " | ||
| "`mellea.stdlib.session.start_session` for a list of options." |
There was a problem hiding this comment.
This error references start_session's docstring, but this is start_backend. Either point to start_backend or list the valid backend names inline — they're short enough.
Misc PR
Type of PR
Description
I will likely have to fix merge conflicts between this and the other granite switch pr. I would ideally like to merge this first.
Changes:
Testing
Attribution