File size: 1,544 Bytes
6b6eb1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Run only the published runtime, without any source model weights."""

import asyncio
import json
import math

from transformers import PreTrainedModel

from coreai_d3 import D3CoreAI


def forbid_weights(*args, **kwargs):
    raise AssertionError("Runtime attempted to load PyTorch model weights")


async def main():
    PreTrainedModel.from_pretrained = forbid_weights
    engine = await D3CoreAI.load(".")
    result = await engine.system_one(
        state="The customer was charged twice and has a receipt.",
        questions={
            "team": {
                "type": "choice",
                "instructions": "Which team?",
                "criteria": {"billing": "Payments", "shipping": "Delivery"},
            },
            "receipt": {
                "type": "noul",
                "instructions": "Does the customer have a receipt?",
            },
            "severity": {
                "type": "score",
                "instructions": "How severe?",
                "criteria": ["Minor", "Major", "Complete"],
            },
        },
    )
    assert result["answers"]["team"]["choice"] in {"billing", "shipping"}
    assert 0 <= result["answers"]["receipt"]["noul"] <= 1
    assert math.isfinite(result["answers"]["severity"]["score"])
    print(json.dumps(result, indent=2))
    open("runtime-smoke.json", "w").write(
        json.dumps(
            {"passed": True, "source_weights_loaded": False, "result": result}, indent=2
        )
        + "\n"
    )


if __name__ == "__main__":
    asyncio.run(main())