File size: 811 Bytes
551b309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Run an AffixIO-authorised Hugging Face chat completion."""

# Credit: @paparichens

from affix_huggingface import AdmissionChecks, AffixHuggingFace, ModelRef


def main() -> None:
    model = ModelRef(
        model_id="meta-llama/Llama-3.1-8B-Instruct",
        provider="hf-inference",
    )
    checks = AdmissionChecks(
        entitled=True,
        data_route_allowed=True,
        controls_satisfied=True,
    )

    with AffixHuggingFace() as client:
        result = client.chat_completion(
            [{"role": "user", "content": "Summarise the supplied operational note."}],
            model=model,
            checks=checks,
            max_tokens=150,
        )

    print(result.output)
    print(f"AffixIO receipt: {result.receipt.gate.receipt_id}")


if __name__ == "__main__":
    main()