File size: 2,800 Bytes
102dc72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from legal_llama.bill_retrieval import BillRetriever
from legal_llama.summarizer import BillSummarizer


class DialogManager:
    """
    A class for managing conversation frames.
    """

    def __init__(self):
        """
        Initialize the DialogManager with predefined frames.
        """
        self.frames = {
            "bill_summarization": {
                "intent": "bill_summarization",
                "bill_query": None,
            },
            # Add more frames here as needed
        }
        self.current_frame = None

    def set_frame(self, intent, slot):
        """
        Set the current frame based on the recognized intent and provided slot value.

        Parameters:
            intent (str): The recognized intent.
            slot (str): The value of the slot provided by the user.
        """
        # Update this function in the future to check for intent.
        self.current_frame = self.frames.get(intent, {}).copy()
        if self.current_frame is not None:
            self.update_slot('bill_query', slot)
        else:
            print(f"Unrecognized intent: {intent}")

    def update_slot(self, slot_name, slot_value):
        """
        Update the value of a slot in the current frame.

        Parameters:
            slot_name (str): The name of the slot.
            slot_value (str): The new value of the slot.
        """
        if self.current_frame is not None and slot_name in self.current_frame:
            # If the current frame is set and the slot name exists in the frame, update the slot value
            self.current_frame[slot_name] = slot_value
        else:
            print(f"Cannot update slot '{slot_name}' - no current frame or slot does not exist")

    def generate_response(self):
        """
        Generate a response based on the current frame.

        Returns:
            str: The generated response.
        """
        # Check if a frame has been set
        if self.current_frame is None:
            print("No frame has been set")
            return None

        frame = self.current_frame
        if frame['intent'] == 'bill_summarization':
            # Extract the bill's text
            bill_retriever = BillRetriever()
            bill_text = bill_retriever.get_bill_by_query(frame['bill_query'])
            if bill_text is None:
                print("Unable to retrieve bill text")
                return None

            # Summarize the bill's text
            summarizer = BillSummarizer()
            summary = summarizer.summarize(bill_text)
            if summary is None:
                print("Unable to summarize bill text")
                return None

            return summary
        else:
            print(f"Unrecognized frame intent: {frame['intent']}")
            return None