| --- |
| library_name: peft |
| base_model: ibm-granite/granite-4.0-micro |
| tags: |
| - mellea |
| --- |
| |
| # stembolts Intrinsic Adapter |
|
|
| This intrinsic adapter analyzes plain text descriptions of vehicle engine issues to identify potential defective parts and provides a diagnostic likelihood score. |
|
|
| ## Training Data |
|
|
| The training dataset consists of JSONL formatted strings where each line contains an 'item' field with a description of the engine issue, and a 'label' field containing a JSON object specifying the suspected 'defective_part' and its corresponding 'diag_likelihood'. |
|
|
| ### Examples |
|
|
| **Input examples:** |
|
|
| - Airflow to the intake seems restricted; it bogs under throttle. |
|
|
| - Intermittent sputter at high RPM after sitting overnight. |
|
|
| - Oil seepage around the lower end suggests wear over time. |
|
|
| - Popping noises then it sputters to a stop. |
|
|
| - Starts on choke but dies the moment choke is opened. |
|
|
|
|
| **Output examples:** |
|
|
| - {"defective_part":"air filter","diag_likelihood":0.78} |
|
|
| - {"defective_part":"fuel line","diag_likelihood":0.62} |
|
|
| - {"defective_part":"piston rings","diag_likelihood":0.71} |
|
|
| - {"defective_part":"mini-carburetor","diag_likelihood":0.96} |
|
|
| - {"defective_part":"mini-carburetor","diag_likelihood":0.92} |
|
|
|
|
| ## How to Use |
|
|
| To use this intrinsic adapter in your application, you need to define an adapter class |
| and an intrinsic component. The adapter connects to the HuggingFace model repository |
| where the trained weights are stored, and the intrinsic wraps it as a composable Mellea |
| component that can be used with any compatible backend. |
|
|
| Make sure you have Mellea installed (`uv pip install mellea`), then use the code below to |
| integrate this intrinsic into your application. |
|
|
| ```python |
| import mellea.stdlib.functional as mfuncs |
| from mellea.core import Context |
| from mellea.backends import Backend |
| from mellea.stdlib.components.simple import SimpleComponent |
| from mellea.backends.adapters import AdapterMixin |
| from mellea.backends.adapters.adapter import CustomGraniteCommonAdapter |
| from mellea.stdlib.components.intrinsic import Intrinsic |
| |
| |
| _INTRINSIC_MODEL_ID = "nfulton/stembolts" |
| _INTRINSIC_ADAPTER_NAME = "stembolts" |
| |
| |
| class StemBoltsAdapter(CustomGraniteCommonAdapter): |
| def __init__(self, base_model_name: str): |
| super().__init__( |
| model_id=_INTRINSIC_MODEL_ID, |
| intrinsic_name=_INTRINSIC_ADAPTER_NAME, |
| base_model_name=base_model_name, |
| ) |
| |
| |
| class StemBoltsIntrinsic(Intrinsic, SimpleComponent): |
| def __init__(self, defect_description: str): |
| Intrinsic.__init__(self, intrinsic_name=_INTRINSIC_ADAPTER_NAME) |
| SimpleComponent.__init__(self, defect_description=defect_description) |
| |
| def format_for_llm(self): |
| return SimpleComponent.format_for_llm(self) |
| |
| async def async_stembolts(defect_description: str, ctx: Context, backend: Backend | AdapterMixin): |
| # Backend.add_adapter should be idempotent, but we'll go ahead and check just in case. |
| if adapter.qualified_name not in backend.list_adapters(): |
| backend.add_adapter(StemBoltsAdapter(backend.base_model_name)) |
| action = StemBoltsIntrinsic("stembolts", defect_description) |
| mot = await backend.generate_from_context(action, ctx) |
| return mot |
| |
| |
| def stembolts(defect_description: str, ctx: Context, backend: Backend | AdapterMixin): |
| # Backend.add_adapter should be idempotent, but we'll go ahead and check just in case. |
| adapter = StemBoltsAdapter(backend.base_model_name) |
| if adapter.qualified_name not in backend.list_adapters(): |
| backend.add_adapter(adapter) |
| action = StemBoltsIntrinsic(defect_description) |
| return mfuncs.act(action, ctx, backend) |
| |
| if __name__ == "__main__": |
| from mellea.backends.huggingface import LocalHFBackend |
| from mellea.backends.model_ids import IBM_GRANITE_4_MICRO_3B |
| from mellea.stdlib.context import ChatContext |
| backend = LocalHFBackend(IBM_GRANITE_4_MICRO_3B) |
| result, ctx = stembolts(defect_description='Airflow to the intake seems restricted; it bogs under throttle.', ctx=ChatContext(), backend=backend) |
| print(result.value) |
| ``` |