File size: 4,070 Bytes
023335c
 
3518830
023335c
 
 
 
13da569
 
3518830
13da569
 
 
3518830
13da569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775f8b5
13da569
 
 
 
 
 
 
 
 
 
 
 
f8130dc
ccf1340
13da569
 
3518830
13da569
 
 
 
 
 
 
 
3518830
 
13da569
3518830
13da569
 
 
 
3518830
13da569
 
3518830
 
13da569
 
 
 
3518830
13da569
3518830
13da569
 
3518830
13da569
d5e0093
 
 
 
 
 
3518830
d5e0093
13da569
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
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)
```