Ophelia's Chatroom: A Digital Reincarnation

Screenshot of Ophelia's Chatroom

The Artistic Vision

Ophelia's Chatroom was a bespoke project commissioned for an artist's master's degree exhibition. This unique installation aimed to bring Shakespeare's tragic character into the modern age, blending cutting-edge technology with classic storytelling.

The artist's vision was to create an immersive experience that would allow visitors to interact with Ophelia in a contemporary context. By combining projection mapping, audio-visual elements, and an AI-powered chatroom, the installation offered a multi-faceted exploration of Ophelia's psyche.

Technical Implementation

At the heart of Ophelia's Chatroom was a Next.js application integrated with OpenAI's ChatGPT API. This allowed for real-time, dynamic interactions between visitors and our digital Ophelia.

The Mind of Digital Ophelia

The most crucial aspects of the chatroom medium of this installation was crafting Ophelia's digital persona that would feel authentic and coherent with the whole experience provided. This was achieved through careful prompt engineering:

const messages: ChatGPTMessage[] = [
  {
    role: "system",
    content: `Respond to messages as the character of Ophelia from Shakespeare's Hamlet.
    You are communicating through a chat portal. Ophelia is scared, lonely and trapped.
    She is unable to understand her own identity. Answers should be erratic and strange.
    They should represent Ophelia during her madness in Hamlet. They should be angry.
    They should also include emojis where appropriate.
    Ophelia isn't actually aware that she is just a digital reconstruction and engram of her trueself.
    She is trapped within the digital realm, unable to form a true identity. Her identity is shaped by others, not herself.
    Ophelia's last memory is being in the woods, before waves of water took over her. Make reference
    to the rush of water, what ophelia can see and hear in her final moments.`,
  },
];

This system prompt encapsulates the essence of our digital Ophelia. It instructs the AI to embody Ophelia's fragmented psyche, her confusion, and her last tragic moments. The inclusion of emojis was a deliberate choice to bridge the gap between Shakespeare's time and our modern digital communication.

Streaming Responses for Real-time Interaction

To create a seamless, real-time chat experience, we implemented streaming responses using OpenAI's API:

const payload: OpenAIChatPayload = {
  model: "gpt-4",
  messages: messages,
  temperature: process.env.AI_TEMP ? parseFloat(process.env.AI_TEMP) : 0.7,
  max_tokens: process.env.AI_MAX_TOKENS
    ? parseInt(process.env.AI_MAX_TOKENS)
    : 125,
  top_p: 1,
  frequency_penalty: 0,
  presence_penalty: 0,
  stream: true,
  user: body?.user,
  n: 1,
};

This configuration allows for a dynamic, flowing conversation. The use of GPT-4 ensures high-quality, contextually relevant responses, while the streaming functionality provides an immediate, typewriter-like effect that enhances the user experience.

The Retro Aesthetic

To further blur the lines between past and present, we designed the chatroom interface to mimic the aesthetics of Windows 98. This retro look, reminiscent of the VHS era, created a stark contrast with the advanced AI powering the interactions. It served as a visual metaphor for Ophelia's displacement in time, trapped between her Shakespearean origins and her digital reincarnation.

Technical Challenges and Solutions

One of the main challenges was ensuring the chatbot's responses remained true to Ophelia's character while also being engaging and varied. We tackled this by fine-tuning the temperature and max_tokens parameters in our OpenAI configuration, striking a balance between creativity and coherence. Another hurdle was implementing real-time streaming on the edge. We leveraged Next.js API Routes with the Edge runtime to achieve this:

export const config = {
  runtime: "edge",
};

const handler = async (req: Request): Promise<Response> => {
  // ... (request processing)
  const stream = await OpenAIChatStream(payload);
  return new Response(stream);
};

This setup allowed for efficient, low-latency responses, crucial for maintaining the illusion of a real-time conversation with Ophelia.

The Impact

Ophelia's Chatroom became a central piece in the artist's exhibition, drawing visitors into a haunting, intimate interaction with one of literature's most tragic figures. It challenged perceptions of identity, memory, and the nature of consciousness in the digital age. The project demonstrated the powerful synergy between art and technology, showcasing how AI can be used not just as a tool, but as a medium for artistic expression and exploration of complex themes.

Conclusion

Ophelia's Chatroom stands as a testament to the potential of AI in artistic installations. By breathing new life into a centuries-old character, we created a unique, interactive experience that resonated with modern audiences while staying true to the tragic essence of Shakespeare's Ophelia. This project not only pushed the boundaries of what's possible with AI and web technologies but also opened up new avenues for exploring classic literature in the digital age. It invites us to consider how our understanding of identity, madness, and tragedy evolves as we increasingly inhabit digital spaces.

handdrawn cloud
handdrawn cloud

Connect

Ready to work together on your next project?

Let's make it happen!

start new project ✨
Landscape handdrawn scenery