Skip to content

Conversation

@knutdrand
Copy link

Summary

This PR enables integration between chapkit and the CHAP R SDK by:

  1. ShellModelRunner now writes run_info.yml to the workspace

    • Available via {run_info_file} variable in command templates
    • Written for both train and predict operations
    • Contains prediction_length, additional_continuous_covariates, future_covariate_origin
  2. Added R model integration example (examples/ml_r/)

    • Demonstrates using chap.r.sdk with chapkit
    • Uses create_chapkit_cli() for named argument interface
    • Shows info --format json for metadata discovery

Usage

R models using chap.r.sdk can now receive run_info via the CLI:

runner = ShellModelRunner(
    train_command="Rscript model.R train --data {data_file} --run-info {run_info_file}",
    predict_command="Rscript model.R predict --historic {historic_file} --future {future_file} --output {output_file} --run-info {run_info_file}"
)

The R SDK's info --format json command outputs structured metadata for chapkit:

$ Rscript model.R info --format json
{
  "service_info": {
    "period_type": "any",
    "required_covariates": [],
    "allows_additional_continuous_covariates": false
  },
  "config_schema": { ... }
}

Test plan

  • All existing tests pass (636 passed)
  • R example info --format json works correctly
  • Manual test with full train/predict cycle

🤖 Generated with Claude Code

knutdrand and others added 3 commits December 19, 2025 09:24
Add RunInfo class containing runtime information passed from CHAP to models:
- prediction_length: Number of periods to predict
- additional_continuous_covariates: User-specified additional covariates
- future_covariate_origin: Origin/source of future covariate forecasts

Update all model runner implementations (BaseModelRunner, FunctionalModelRunner,
ShellModelRunner) to accept and pass run_info parameter. Update TrainRequest
and PredictRequest schemas to include run_info field.

This change aligns chapkit with the model contract defined in chap_core,
enabling models to receive runtime configuration separately from user-defined
model configuration.
Add PeriodType StrEnum (any, week, month, year) to specify which time
period types a model supports. MLServiceInfo now exposes this field
in the /api/v1/info endpoint for CHAP to read model capabilities.
This enables integration with the CHAP R SDK by:

1. ShellModelRunner now writes run_info.yml to the workspace
   - Available via {run_info_file} variable in command templates
   - Written for both train and predict operations
   - Contains prediction_length, additional_continuous_covariates, etc.

2. Added R model integration example (examples/ml_r/)
   - Demonstrates using chap.r.sdk with chapkit
   - Uses create_chapkit_cli() for named argument interface
   - Shows info --format json for metadata discovery

The R SDK's info command outputs structured JSON that chapkit can use
for configuration schema validation and model metadata discovery.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

knutdrand and others added 3 commits December 19, 2025 20:12
This enables automatic configuration schema discovery from R models
(or any external script that implements an info command).

New features:
- discover_model_info(): Execute info command and parse JSON output
- create_config_from_schema(): Convert JSON Schema to Pydantic BaseConfig
- ModelInfo: Container for discovered service_info and config_class

The R example now uses schema discovery instead of duplicating the
schema in Python. The schema is defined once in R and automatically
discovered at service startup.

Usage:
```python
from chapkit.ml import discover_model_info, ShellModelRunner

model_info = discover_model_info("Rscript model.R info --format json")
# model_info.config_class is a Pydantic model matching the R schema
# model_info.period_type, required_covariates, etc. from service_info

app = MLServiceBuilder(
    config_schema=model_info.config_class,
    ...
)
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Use Path(__file__).parent to locate model.R script, allowing
the example to run from any working directory.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant