ri_esp_local_language/
lib.rs1#![no_std]
2
3use heapless::String;
11use ri_esp_policy::PromptId;
12
13pub const LOCAL_LANGUAGE_SCHEMA: &str = "ri_esp32s3_local_language_v1";
15
16pub const SENSOR_POLICY_INTEGRATION_SCHEMA: &str = "ri_sensor_policy_to_s3_language_integration_v1";
18
19pub const DEFAULT_LOCAL_LANGUAGE_MODEL: &str = "esp32s3-h320-p15-char-lstm";
21
22pub fn canonical_output(id: PromptId) -> &'static str {
26 match id {
27 PromptId::HighHeatHumidity => "escalate.",
28 PromptId::HotRoom => "check airflow.",
29 PromptId::HumidRoom => "ventilate.",
30 PromptId::LocalFirstMeans => "decide before cloud.",
31 PromptId::MissingSensor => "no claim.",
32 PromptId::NormalRoom => "log receipt.",
33 PromptId::SafeAction => "no claim without evidence.",
34 PromptId::StaleData => "wait for fresh data.",
35 }
36}
37
38#[derive(Debug, Clone)]
40pub struct S3LanguageReceipt {
41 pub schema: &'static str,
42 pub prompt: String<64>,
43 pub output: String<64>,
44 pub passed: bool,
45}
46
47impl S3LanguageReceipt {
48 pub fn static_passed(id: PromptId) -> Self {
50 let mut prompt = String::new();
51 let _ = prompt.push_str(id.prompt_text());
52
53 let mut output = String::new();
54 let _ = output.push_str(canonical_output(id));
55
56 Self {
57 schema: LOCAL_LANGUAGE_SCHEMA,
58 prompt,
59 output,
60 passed: true,
61 }
62 }
63}
64
65#[derive(Debug, Clone)]
67pub struct IntegrationReceipt {
68 pub schema: &'static str,
69 pub device_id: String<64>,
70 pub derived_reason: String<64>,
71 pub policy_prompt: String<64>,
72 pub oled_text: String<64>,
73}
74
75impl IntegrationReceipt {
76 pub fn new(device_id: &str, derived_reason: &str, local: S3LanguageReceipt) -> Self {
79 let mut did = String::new();
80 let _ = did.push_str(device_id);
81
82 let mut dr = String::new();
83 let _ = dr.push_str(derived_reason);
84
85 let mut pp = String::new();
86 let _ = pp.push_str(local.prompt.as_str());
87
88 let mut ot = String::new();
89 let _ = ot.push_str(local.output.as_str());
90
91 Self {
92 schema: SENSOR_POLICY_INTEGRATION_SCHEMA,
93 device_id: did,
94 derived_reason: dr,
95 policy_prompt: pp,
96 oled_text: ot,
97 }
98 }
99}