On a classroom computer
Leave “Remember this key” unchecked. Your key stays in the tab’s session. Ask your teacher which provider to use.
Meet the building blocks behind your first AI chatbot. Learn a little, change something, and see what happens.
A chatbot reads a message and sends a reply. You decide its purpose; your Python code connects the pieces.
Open a guided project. Start with Study Buddy, Quiz Master, Story Studio, or Idea Lab.
Describe how your bot should help. The guided builder turns your choices into four editable Python files.
Open your project in the playground and select Run my bot. When chat says Ready, send a message. Stop the bot before running changed code again.
The playground saves code on this device. In demo mode it echoes messages; an AI connection enables generated replies.
Want account projects and AI credits? Create a workspace, then manage your saved projects from My projects.
Select Connect AI in the playground. Choose a provider, use its “Get a key” link, then paste your API key into the labelled field and save.
Leave “Remember this key” unchecked. Your key stays in the tab’s session. Ask your teacher which provider to use.
You can choose to remember a key. Use Remove key in connection settings when you want to delete it from browser storage.
Saving a key doesn’t verify it. Run your bot and send a message to test the connection. Keys are sent with run requests to Dhiora’s server for provider calls, and provider usage may cost money.
Try the suggested questions or write your own. Enter sends a message; Shift + Enter adds a new line. On a phone, switch between Your code and Test your bot.
Select Style in the chat panel to customise colours, backgrounds, and message bubbles. Use the expand control when you want more room.
Ask “What is gravity?”, then tell your bot to explain using a football example. Stop, run again, and compare. AI answers can be incorrect: checking them is part of building.
Start with the personality file. You can explore the other pieces as you get comfortable.
prompt.pyThe personalityInstructions in plain English. Tell your AI what to do, how to speak, and what to focus on.
# These instructions shape every answer. Experiment with them!
SYSTEM_PROMPT = "You are a friendly study buddy for students. Explain ideas in simple language, use a relatable example, and ask one question to check understanding. Give hints before giving answers. If you are unsure, say so."
config.pyThe name tagA home for your bot’s settings. Change BOT_NAME to give your creation a new name.
# Give your chatbot a name.
BOT_NAME = "Study Buddy"
logic.pyThe thinking stepsThe respond() function combines your instructions with the message and asks the AI for a reply.
# Keep the last three exchanges so your bot can follow a conversation.
# Restarting the bot clears this memory.
from collections import deque
from ai import ask
from prompt import SYSTEM_PROMPT
conversation = deque(maxlen=6)
def respond(message: str) -> str:
history = "\n".join(conversation)
answer = ask(f"{SYSTEM_PROMPT}\n\nRecent conversation:\n{history}\nStudent: {message}\nAssistant:")
conversation.append(f"Student: {message[:2000]}")
conversation.append(f"Assistant: {answer[:2000]}")
return answer
main.pyThe on switchConnects the files, creates your chatbot, and starts it. Keep bot.start() at the bottom.
# This is the starting point of your chatbot — the file that runs first.
# The real work happens in the other 3 tabs (config.py, prompt.py, logic.py);
# this file just plugs them together. You usually won't need to change much
# here — try editing the other files first!
from ai import *
from config import BOT_NAME
from logic import respond
bot = ChatBot(BOT_NAME)
# Whenever someone sends your chatbot a message, Python runs this function
# and sends whatever it returns back as the reply.
@bot.on_message
def handle_message(message):
return respond(message)
# This line switches your chatbot on. Keep it at the very bottom of the file.
bot.start()
These predefined functions save you from writing everything yourself. Expand a function for its explanation and examples.
11 functions found
ChatBotclassAvailableChatBot(name: str = "Assistant")A text chatbot.
bot = ChatBot()
@bot.on_message
def respond(message):
return "Hello " + message
bot.start()
on_messagemethodAvailable@bot.on_messageChatBot method. Decorator: registers the function below it as the handler called for every incoming message. The handler receives the visitor's message (str) and must return the reply (str).
startmethodAvailablebot.start()ChatBot method. Starts the bot — the platform automatically exposes it as a live chat endpoint in the preview panel. Call this once, last, at module level.
askfunctionAvailableask(question: str) -> strAsk the AI a question and get a text answer back.
answer = ask("What is the capital of France?")
replyfunctionAvailablereply(text: str) -> strSame as ask() — reads more naturally inside a chatbot handler.
@bot.on_message
def respond(message):
return reply(message)
memoryfunctionAvailablememory() -> MemoryCreate a new, empty conversation memory buffer.
mem = memory()
mem.append("user", "hi")
databasefunctionAvailabledatabase() -> DatabaseGet a handle to this project's simple key-value database.
db = database()
db.set("visits", db.get("visits", 0) + 1)
savefunctionAvailablesave(key: str, value) -> NoneSave a value under a name so you can load() it later.
save("high_score", 42)
loadfunctionAvailableload(key: str, default=None)Load a value previously saved with save().
score = load("high_score", 0)
create_tablefunctionAvailablecreate_table(name: str) -> TableCreate (or open) a named table for structured rows.
users = create_table("users")
users.insert({"name": "Ada"})
queryfunctionAvailablequery(table: str, **filters) -> list[dict]Query rows from a table made with create_table(), filtered by exact-match keyword arguments.
query("users", name="Ada")
Ask your bot to explain photosynthesis to a 12-year-old. Then change its instructions to teach using a story.
Play three rounds of your quiz. Try a wrong answer: does your bot explain why?
Give your bot an unexpected character and setting. Change the instructions to make every story a mystery.
Ask for ideas to reduce waste on campus. Can you make the suggestions more practical by changing the prompt?
You’re in demo mode. Connect an AI provider, save your key, then stop and run your bot again. Without a provider, an echo is expected.
Open Run console below the code. Read the last error line for a typo or missing quote. If it mentions your provider, check the key and provider account. Never share your key in a screenshot.
A running bot uses the files it started with. Select Stop bot, then Run my bot to apply your changes. This also resets the conversation memory.
Check your connection and the run console. If the provider isn’t responding, stop the bot, review AI settings, and run again.
Playground projects are stored in this browser. Clearing browser data removes them. Export your code before moving to another computer; account projects live in your signed-in workspace.