On Day 9, we took our chatbot from a rough classroom prototype to something that feels like a real, modern web application. We had two major problems to solve: conversation memory and the annoying full-page reload.

1. Teaching the Bot to Remember (Session State)

Standard web requests are stateless—every time you send a message, the server forgets who you are. If you tell the bot 'my name is Sagar' and then ask 'what's my name?', it has no idea. We fixed this using Flask sessions (encrypted cookies). Now, each user gets their own private chat history stored in their session, and we send the last few messages along with every new prompt.

2. Multiple AI Personalities

We also built a personality switcher. With a simple dropdown, the user can change the system prompt: StudyBot (helpful student tutor), CodeBot (strict senior developer who only writes clean code), or CasualBot (chill, friendly conversationalist). The backend dynamically swaps the system instructions on the fly.

3. Ditching the Clunky Page Reload with AJAX

The official assignment had students submitting an HTML form that caused the entire browser tab to reload every time you hit send. It felt laggy and flickered. I refused to ship that. Instead, I set up an asynchronous API endpoint (/api/chat) and wrote a quick JavaScript controller using the browser's native fetch() API.

Now, when you press Enter, the user message appears instantly, a subtle 'thinking...' bubble pops up, and the AI answer smoothly fades in without the page reloading once. When I demoed it to the room, the whole cohort was impressed. Rashmi loved it and pointed out to the class that asynchronous fetch requests are the exact industry standard for modern web apps.

Key Learnings

  • Persisting conversation history between messages using Flask session cookies.
  • Switching system prompts dynamically to give the chatbot multiple personalities.
  • Building clean RESTful JSON endpoints in Flask (/api/chat).
  • Replacing clunky page reloads with smooth, asynchronous JavaScript fetch() requests.

Tools & Stack

  • Flask Sessions
  • Fetch API
  • JavaScript
  • JSON
  • Qwen-7B

Challenges Overcome

  • Keeping session cookies secure and handling edge cases where sessions expire.
  • Limiting the conversation history buffer so it doesn't exceed the model's token limits.

Task to be Performed

  • Store rolling conversation turns inside Flask session storage.
  • Build a personality selector that updates the AI's system prompt.
  • Write frontend JavaScript to send messages via fetch() and render bubbles dynamically.

Related Logs

Day 00

Day 00: Onboarding, Orientation, and the 2-Week AI Roadmap

Walking into Virtual Height for day zero: getting our badges, meeting our lead mentors, and mapping out what we will build over the next two weeks.

May 29, 2026 • 4 min readRead Log ➔
Day 01

Day 01: First Day as an AI Intern, Python Basics, and a Wild Flex

Day 1 kicks off with lead mentor Rashmi. We break down AI vs ML vs Deep Learning, test Python terminal scripts, and demo my custom chatbot to the room.

Jun 01, 2026 • 4 min readRead Log ➔