File size: 1,410 Bytes
5f0301f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import logging

class FactCheckerState:
    """
    A class to manage the state of a fact checking system. It holds a question 
    and its corresponding response, and provides methods to set and get these 
    attributes dynamically.

    Parameters
    ----------
    question : str
        The question to be fact-checked.
    response : str
        The response to the question.
    """
    def __init__(self, question: str = None, response: str = None):
        """
        Initialize the FactCheckerState object.
        """
        self.question: str = question
        self.response: str = response

    def set(self, name, value):
        """
        Set an attribute of the state object.
        """
        if hasattr(self, name):
            logging.warning(f"FactCheckerState.set: Modifying existing attribute {name}")
        setattr(self, name, value)

    def get(self, name):
        """
        Get an attribute of the state object.
        """
        if not hasattr(self, name):
            raise ValueError(f"FactCheckerState.get: Attribute {name} does not exist")
        return getattr(self, name, None)

    def __str__(self):
        """
        Return a string representation of the state object.
        """
        return str(self.__dict__)

    def to_dict(self):
        """
        Return a dictionary representation of the state object.
        """
        return self.__dict__