Skip to content

Migrate some required functions from plugin sdk to lab facade#1363

Merged
deep1401 merged 9 commits intomainfrom
migrate/plugin-sdk-local-provider
Feb 23, 2026
Merged

Migrate some required functions from plugin sdk to lab facade#1363
deep1401 merged 9 commits intomainfrom
migrate/plugin-sdk-local-provider

Conversation

@deep1401
Copy link
Copy Markdown
Member

@deep1401 deep1401 commented Feb 19, 2026

Summary by CodeRabbit

Release Notes - Version 0.0.81

  • New Features

    • Local text generation support with configurable endpoints and optional system prompts
    • New facade methods to load generation models and update individual job data fields
  • Chores

    • Bumped transformerlab dependency and added requests to dependencies
  • Tests

    • Added tests covering generation model configuration and loading

@deep1401 deep1401 marked this pull request as ready for review February 19, 2026 16:06
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f7f097 and ddfd74b.

📒 Files selected for processing (1)
  • lab-sdk/pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • lab-sdk/pyproject.toml

📝 Walkthrough

Walkthrough

Adds a new library-agnostic text generation module with a Local HTTP backend, exposes generation model creation and a synchronous job-data setter on the Lab facade, and bumps package versions/dependencies to 0.0.81; also adds a smoke test for loading the local generation model.

Changes

Cohort / File(s) Summary
Version Bumps
api/pyproject.toml, lab-sdk/pyproject.toml
Bump packages to 0.0.81; lab-sdk adds requests dependency.
Generation module
lab-sdk/src/lab/generation.py
New module: GenerationModel interface, _run_async helper, LocalHTTPGenerationModel (POST /chat/completions), and load_generation_model factory supporting local provider.
Lab facade
lab-sdk/src/lab/lab_facade.py
Added Lab.set_job_data_field(key, value) synchronous wrapper and Lab.load_generation_model(config) delegating to generation loader; imports GenerationModel and load_generation_model.
Tests
lab-sdk/tests/test_lab_facade.py
New smoke test test_lab_load_generation_model_smoke asserting LocalHTTPGenerationModel is returned with expected config.

Sequence Diagram

sequenceDiagram
    participant Client as Lab Client
    participant Facade as Lab Facade
    participant GenModule as generation.py
    participant HTTPServer as Local HTTP Server

    Client->>Facade: load_generation_model(config)
    Facade->>GenModule: load_generation_model(config)
    GenModule->>GenModule: Normalize config & validate provider
    GenModule->>GenModule: Create LocalHTTPGenerationModel(base_url, model, api_key)
    GenModule-->>Facade: Return GenerationModel instance
    Facade-->>Client: Return GenerationModel instance

    Client->>Facade: set_job_data_field(key, value)
    Facade->>Facade: Call async updater synchronously
    Facade-->>Client: Field updated

    Client->>GenModule: generate(prompt, system_prompt)
    GenModule->>HTTPServer: POST /chat/completions (JSON)
    HTTPServer-->>GenModule: JSON response with messages
    GenModule->>GenModule: Parse & extract first message content
    GenModule-->>Client: Return generated text
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I nibbled configs, hopped through code,

Sent prompts across a local node,
A facade held the keys just so,
Responses came in gentle flow,
Bravo — the Lab begins to grow!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title describes migrating functions from plugin sdk to lab facade, which matches the main changes: addition of generation model functionality to the lab facade.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch migrate/plugin-sdk-local-provider

Comment @coderabbitai help to get the list of available commands and usage tips.

@sentry
Copy link
Copy Markdown

sentry bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lab-sdk/src/lab/generation.py`:
- Line 9: The lab.generation module imports the external library requests but
that package is not listed in the lab-sdk project's dependencies; update
lab-sdk/pyproject.toml to add "requests" (with an appropriate version
constraint) to the project dependencies so installs include it and runtime
import errors are avoided—ensure the new entry is placed in the
[tool.poetry.dependencies] or equivalent dependencies section that the project
uses.
- Around line 12-29: Add proper type hints to _run_async: declare a TypeVar T
and annotate the parameter as coro: Coroutine[Any, Any, T] and the return type
as -> T; also import TypeVar, Coroutine, and Any from typing at the top of the
module. Update the signature to def _run_async(coro: Coroutine[Any, Any, T]) ->
T: and add the corresponding from typing import TypeVar, Coroutine, Any
(ensuring no unused-import errors) so static type checkers can validate the
async/sync bridging in the _run_async helper.

In `@lab-sdk/tests/test_lab_facade.py`:
- Around line 1003-1028: Add type hints to the pytest fixtures in the test
function test_lab_load_generation_model_smoke: annotate tmp_path as Path and
monkeypatch as pytest.MonkeyPatch, and give the function an explicit return type
of None; also add the required imports "from pathlib import Path" and "import
pytest" at the top of the file (or apply equivalent typing across all test
functions if you prefer whole-file consistency).

Comment on lines +12 to +29
def _run_async(coro):
"""
Helper to run async code from sync context.
Mirrors lab_facade._run_async behavior.
"""
try:
asyncio.get_running_loop()
running = True
except RuntimeError:
running = False

if not running:
return asyncio.run(coro)

loop = asyncio.get_event_loop()
if loop.is_closed():
return asyncio.run(coro)
return loop.run_until_complete(coro)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n lab-sdk/src/lab/generation.py | head -40

Repository: transformerlab/transformerlab-app

Length of output: 1216


🏁 Script executed:

rg -n "def _run_async" lab-sdk/src/lab/generation.py -A 20

Repository: transformerlab/transformerlab-app

Length of output: 588


🏁 Script executed:

rg -n "^from typing import|^import" lab-sdk/src/lab/generation.py | head -15

Repository: transformerlab/transformerlab-app

Length of output: 178


Add type hints to _run_async.

The function signature is missing argument and return type hints, which violates the mandatory type hints requirement for Python files.

✍️ Suggested update
-from typing import Any, Dict, Optional
+from typing import Any, Coroutine, Dict, Optional, TypeVar
+
+T = TypeVar("T")
 
-def _run_async(coro):
+def _run_async(coro: Coroutine[Any, Any, T]) -> T:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lab-sdk/src/lab/generation.py` around lines 12 - 29, Add proper type hints to
_run_async: declare a TypeVar T and annotate the parameter as coro:
Coroutine[Any, Any, T] and the return type as -> T; also import TypeVar,
Coroutine, and Any from typing at the top of the module. Update the signature to
def _run_async(coro: Coroutine[Any, Any, T]) -> T: and add the corresponding
from typing import TypeVar, Coroutine, Any (ensuring no unused-import errors) so
static type checkers can validate the async/sync bridging in the _run_async
helper.

Comment on lines +1003 to +1028
def test_lab_load_generation_model_smoke(tmp_path, monkeypatch):
_fresh(monkeypatch)
home = tmp_path / ".tfl_home"
ws = tmp_path / ".tfl_ws"
home.mkdir()
ws.mkdir()
monkeypatch.setenv("TFL_HOME_DIR", str(home))
monkeypatch.setenv("TFL_WORKSPACE_DIR", str(ws))

from lab.lab_facade import Lab
from lab.generation import LocalHTTPGenerationModel

lab = Lab()
# load_generation_model should NOT require lab.init; it's stateless config
model = lab.load_generation_model(
{
"provider": "local",
"base_url": "http://localhost:9999/v1",
"model": "test-model",
"api_key": "test-key",
}
)

assert isinstance(model, LocalHTTPGenerationModel)
assert model.base_url == "http://localhost:9999/v1"
assert model.model == "test-model"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the test function signature and surrounding code
rg -n --type=py -C5 "def test_lab_load_generation_model_smoke" lab-sdk/tests/test_lab_facade.py

Repository: transformerlab/transformerlab-app

Length of output: 432


🏁 Script executed:

#!/bin/bash
# Check the current imports in the test file
head -50 lab-sdk/tests/test_lab_facade.py | rg -n "^import|^from"

Repository: transformerlab/transformerlab-app

Length of output: 138


🏁 Script executed:

#!/bin/bash
# Check if Path and pytest are already imported in the file
rg -n "from pathlib import|import pytest" lab-sdk/tests/test_lab_facade.py

Repository: transformerlab/transformerlab-app

Length of output: 59


🏁 Script executed:

#!/bin/bash
# Search entire file for any pytest or Path imports
rg -n "pytest|from pathlib" lab-sdk/tests/test_lab_facade.py

Repository: transformerlab/transformerlab-app

Length of output: 59


🏁 Script executed:

#!/bin/bash
# Check a few other test function signatures to see if they have type hints
rg -n "^def test_" lab-sdk/tests/test_lab_facade.py | head -10

Repository: transformerlab/transformerlab-app

Length of output: 625


🏁 Script executed:

#!/bin/bash
# Get the complete imports section of the file
sed -n '1,100p' lab-sdk/tests/test_lab_facade.py | cat -n

Repository: transformerlab/transformerlab-app

Length of output: 3494


Add type hints for pytest fixtures in the new smoke test.

The new test function lacks argument and return type hints, which violates the mandatory type hints coding guideline. However, note that the entire test file currently lacks type hints on all test functions; adding them to this function alone would create an inconsistency with the rest of the file. Consider either:

  1. Adding type hints only to this function (requires importing Path from pathlib and pytest.MonkeyPatch)
  2. Applying type hints across all test functions in the file for consistency
✍️ Suggested update
-def test_lab_load_generation_model_smoke(tmp_path, monkeypatch):
+def test_lab_load_generation_model_smoke(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:

Requires adding these imports at the top of the file if not already present:

from pathlib import Path
import pytest
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lab-sdk/tests/test_lab_facade.py` around lines 1003 - 1028, Add type hints to
the pytest fixtures in the test function test_lab_load_generation_model_smoke:
annotate tmp_path as Path and monkeypatch as pytest.MonkeyPatch, and give the
function an explicit return type of None; also add the required imports "from
pathlib import Path" and "import pytest" at the top of the file (or apply
equivalent typing across all test functions if you prefer whole-file
consistency).

@deep1401 deep1401 requested a review from dadmobile February 23, 2026 14:35
@deep1401 deep1401 merged commit 60d7c84 into main Feb 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants