Documentation / Widgets / System / AI Assistant

AI Assistant

A button to talk to and the answer underneath it. Press it and it listens; press again, or wait, and it sends what it heard to a service, shows what the service made of the speech, then the answer - and speaks the answer too when the design has a speaker. It needs a microphone, which dropping the widget switches on, and WiFi. Arduino export, ESP32 family.

Part of Pro when code is generated. Dropping it on a design and trying it in preview is free, and the export dialog says so before anything is asked for.

Group: System · Default size: 240 × 180 · Style parts: Main

A dropped AI Assistant: a white card with the word Ready, the line The answer appears here, and scrolls when it is long, and a blue Talk button.
An AI Assistant as it is dropped.
The first of the AI Assistant settings: Base URL https://api.openai.com/v1, API key not set, Speech-to-text model whisper-1, Chat model gpt-4o-mini, Instructions.
The first of its settings. The API key is typed masked.
SettingDefaultWhat it does
Base URLhttps://api.openai.com/v1Where the service is, up to its version. Any service that speaks the OpenAI API will do - a hosted one, or one on your own network.
API keynoneSent with every request. See below before you set it.
Speech-to-text modelwhisper-1What turns the recording into words.
Chat modelgpt-4o-miniWhat answers.
Instructionsa short oneWhat the assistant is told it is, before each question. A small screen wants short answers; say so here.
Speak the answeronSends the answer for speech and plays it. Needs an audio output; without one the answer is shown only.
Voice model / Voicetts-1 / alloyWhat speaks, and in which voice.
Listen for up to6 sIt sends when this runs out, or sooner when the button is pressed again.
Button textTalkWhile it listens the button reads Send.

Three requests go to the service, one after another: the recording to /audio/transcriptions, the words to /chat/completions, and the answer to /audio/speech. Each starts when the one before has answered, so an answer takes a few seconds, and the line at the top says which step it is on. Each question stands alone - the assistant is not told what was asked before. If a step fails, the line says which and, where the service gave a reason, the reason.

The key

The API key is a setting of the widget, typed masked in the Inspector. It is kept in your design and written into the firmware, in plain text, because the board has to send it. That means anybody with the board, the exported folder or the saved design has the key. Use one you can revoke, give it a spending limit where the service offers one, and take it out of the export before putting the folder in a repository - the export's README says so when it carries one. Publishing to the gallery removes it: the gallery's copy has an empty key, and whoever opens a copy types their own. A server of your own that asks for no key can be used with the field left empty.

The connection is encrypted when the address is https, but the certificate is not checked - the firmware carries no list of authorities to check one against - so it does not prove the service is who it says.

Example: on a board with a microphone

  1. Start on a board that has a microphone. The LCDWIKI 2.8" ESP32-S3 (ES3C28P) has an ES8311 codec with one, and a speaker output for the answer.
  2. Drag an AI Assistant onto the screen. The microphone is switched on: Hardware > Audio > Microphone, ES8311 microphone.
  3. Under AI Assistant settings type your key into API key, and say what the assistant is under Instructions. The Problems tab says so while there is no key.
  4. It asks over the internet, so the board needs a network: add a WiFi Setup on a screen of its own. The Problems tab says that too.
Hardware, Audio, Microphone: Listen on this board ticked and the ES8311 microphone chosen, with its data pin 6 and a gain of +36 dB.
The microphone the drop switched on.