AI Toolkit
For your scripts
Chat with an AI, give it tools and hold spoken conversations from your own scripts.
A module, not an app: it shows nothing by itself and adds functions that your scripts import.
- Topic
- Miscellaneous
- Includes
- Module
Runs on
- Does not run on 32×8 (TC001 & DIY) Needs a voice that reads text aloud and an AWTRIX that listens and answers.
- Runs on 52×16 (TC002) Voice: choose this app under System → Voice assistant on your AWTRIX.
- Does not run on 32×8 with AWTRIX 3 (TC001 & DIY) Made for AWTRIX NG.
Choose your display in the next step.
Script description
Chat, tools and spoken conversations for your own scripts, in a few lines of Berry. The module knows no services, models or prompts: your script brings all of that, so it fits any service that speaks the OpenAI format, online or on your own computer.
import ai
var chat = ai.chat({'url': url, 'model': model, 'key': '{secret:openai_key}', 'system': 'Answer briefly.'})
chat.tool('get_time', 'Tells the time', {}, / args, done -> done({'hour': hour(), 'minute': minute()}))
chat.ask('What time is it?', / text, status -> self.show(text, status))
chat keeps the conversation, runs the tools the model asks for, and hands you the final answer. chat.cancel() drops an open question and chat.forget() starts over. A failed request gives nil and a status, and chat.detail holds the service's own message.
On a TC002, ai.converse runs the whole spoken loop and tells you what to draw:
ai.converse(chat, {'hear': {'url': stt_url, 'language': 'en'}, 'followup': true, 'wait': 5},
/ state, talk -> self.changed(state, talk))
state is listening, thinking, speaking, done or error. On error, talk.failed names the step and talk.status the reason. ai.hear and ai.say do one step on their own.
To use it, add this line to your script's header, with the twelve characters at the end of this page's address as the ID. Installing your script then fetches the module too:
# @requires ai <id>
Needs AWTRIX NG 1.2.3 or newer. It takes about 23 KB of memory, which is a lot on a TC001. Lumen Assistant is a complete app built on it.
Sign in to view and copy the code of this script.
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
More scripts in Miscellaneous
Something wrong with this script? Report it.
Have an idea?
Sign in to ask questions and join the conversation.