Inspiration
We were inspired by the need for chat experiences that are not just conversational. Most existing messaging apps are one-dimensional, people always say the same boring thing. We wanted to build an engine that could read the room, understand the user's emotional state, and choose a risk/reward level for its response, improving the human social interaction.
What it does
SparkChat is a dynamic chat response engine that intercepts a user message and, based on a sophisticated probability model, decides whether to respond normally or to escalate the suggestive tone.
Emotional Sensitivity: It analyzes the user's message for underlying emotion (e.g., anger, surprise, disgust).
Contextual Memory: It tracks the message count (how long the conversation has been going) as a proxy for comfort level.
Tiered Escalation: It uses a tiered system (Level 1-5) to apply increasing degrees of suggestive filtering and editing to the original message, from adding a subtle emoji to completely rewriting the text. Each level is gets its probability modified as a function of the above points.
How we built it
SparkChat is built on a two-part system designed for both performance and intelligence:
Emotion & Probability Engine (The Brain):
We use a pre-trained Hugging Face Transformer model (j-hartmann/emotion-english-distilroberta-base) to instantly classify the user's emotional state.
This emotion score, combined with the running message_count, feeds into a customizable probability function (p).
The choose_level() function uses these probabilities, along with a user-tunable none_weight (which we set to 5.0), to randomly select a Level (1-5) or choose to return the original message.
Generative Response Module (The Voice):
We utilize the Google Gemini API (gemini-2.5-flash) for fast, creative text generation.
Each of the five "Levels" is a unique System Prompt designed to guide the LLM to perform a specific, suggestive task (e.g., "choose a word and make it horny/funny").
The chosen Level's prompt is combined with the user's message and sent to the LLM to generate the final, dynamic response.
Challenges we ran into
Probability Tuning: Achieving the right "feel" for the trigger frequency was surprisingly complex. A simple linear increase in probability (e.g., message_count * 0.1) quickly led to a guaranteed trigger. We realized we needed to use a logarithmic curve to ensure the chance of a "none" (normal) response always persisted, even in long conversations, providing a more human, unpredictable feel.
Performance: Integrating two heavy ML components (the local Transformer for emotion and the Gemini API for generation) required careful optimization. We implemented GPU checks (torch.cuda.is_available()) for the local model and would incorporate caching (@lru_cache) to avoid redundant API calls.
We also struggled to integrate the message conversion system into the chat
Accomplishments that we're proud of
We are most proud of building a functional Emotional & Contextual Probability Engine.
We successfully created a system where the AI's response is not a fixed script, but a weighted decision based on both what the user said and how much the user has said (context).
The system's modularity, built around a ChatProcessor class, means the probability weights and LLM prompts can be easily tuned, providing a simple interface for adjusting the entire personality of the chat agent.
We also created a working chat bot which incorporates this message transformation system
What we learned
We gained deep insights into the practical limitations of LLMs and the power of combined ML models: Combining Models is Efficient: It's more resource-efficient to use a smaller, faster local model (Transformer for emotion) for simple tasks than to query an expensive cloud LLM for every single data point. We also leaned about creating working chat systems and integrating uncommon features
What's next for SparkChat
Our next steps are focused on expanding and productizing the core engine:
More Inputs: Integrate other factors into the probability engine, such as message length, sentiment analysis (positive/negative), and time of day.
User Profiles: Allow the system to learn and tune the probability weights for individual users over time, creating a genuinely personalized experience.
Alternative Models: Test smaller, locally-run language models for the Level 1/2 prompts to further reduce latency and API costs.
improve the speed and add more features to the chat
Built With
- css
- django
- geminiapi
- html
- javascript
- python
Log in or sign up for Devpost to join the conversation.