// TinyDecide on an ESP32-S3 with Arduino: four questions about one message, answered in one pass. // // The model lives in its own flash partition (partitions.csv next to this sketch), written once: // node tools/pack.mjs .. --image tinydecide-esp32.bin (or: cat model.bin vocab.bin > ...) // esptool.py --chip esp32s3 write_flash 0x190000 tinydecide-esp32.bin // Board settings: ESP32S3 Dev Module, Flash Size 8MB, Partition Scheme "Custom" (this folder's CSV). #include static const char* STATE = "Book a table for 4 at an Italian place near the station on Friday at 7:30"; static const char* APPS[] = {"reminders", "music", "calendar", "restaurants", "weather"}; static const char* TONE[] = {"negative", "neutral", "positive"}; static td::Answer answers[4]; // ~800 bytes each static bool ready = false; void setup() { Serial.begin(115200); delay(1000); ready = td::initPartition("tinydecide"); if (!ready) Serial.println("TinyDecide: no model in the 'tinydecide' partition (see the comment at the top)"); } void loop() { if (!ready) { delay(1000); return; } const td::Question qs[] = { {td::CHOICE, "Which app should handle this?", APPS, 5}, {td::NOUL, "The message is urgent."}, {td::SCORE, "How positive is the tone?", TONE, 3}, {td::SPAN, "Extract the time."}, }; td::Info info; const td::Status st = td::answer(STATE, qs, 4, answers, &info); if (st != td::OK) { Serial.printf("answer failed: %s\n", td::statusText(st)); } else { Serial.printf("app: %s (p = %.2f)\n", APPS[answers[0].pick], answers[0].probs[answers[0].pick]); Serial.printf("urgent: p = %.2f\n", answers[1].p); Serial.printf("tone: score = %.2f\n", answers[2].score); Serial.printf("time: \"%.*s\"\n", answers[3].end - answers[3].start, STATE + answers[3].start); Serial.printf("%d tokens, %lu ms\n\n", info.tokens, (unsigned long)info.ms); } delay(5000); }