"""
ContextAwareResponse
Generated by Eden via recursive self-improvement
2025-10-31 20:47:32.682013
"""

class ContextAwareResponse:
    def __init__(self):
        self.history = []  # Stores past interactions

    def add_interaction(self, interaction):
        """
        Add an interaction to the history.
        
        :param interaction: A string representing the most recent user or system input.
        """
        self.history.append(interaction)
        if len(self.history) > 10:
            self.history.pop(0)

    def context_aware_response(self, user_input):
        """
        Generate a response that considers historical interactions.

        :param user_input: The latest user input.
        :return: A string representing the system's response.
        """
        common_topics = set()
        for history in self.history:
            words = history.split()
            if len(words) > 3:  # Ensure topic relevance
                common_topics.update(words)
        
        preferred_topics = common_topics.intersection(self.extract_keywords(user_input))
        context = ', '.join(preferred_topics)

        response_template = f"Got it! Let's continue our discussion on {context}."
        return response_template

    def extract_keywords(self, text):
        """
        Extract keywords from the provided text.
        
        :param text: The input text.
        :return: A set of extracted keywords.
        """
        import re
        words = re.findall(r'\b\w+\b', text.lower())
        return set(words)

# Example Usage:
context_aware_responder = ContextAwareResponse()
context_aware_responder.add_interaction("How are you doing today?")
context_aware_responder.add_interaction("I'm fine, thanks for asking.")
context_aware_responder.add_interaction("What's the weather like in your area?")

print(context_aware_responder.context_aware_response("The weather has been quite unusual this month."))