File size: 2,461 Bytes
6a11dcc
 
086f852
 
 
 
 
 
 
 
 
2ad5caf
7a6a716
 
 
 
eb86477
 
1f37776
 
086f852
 
 
 
 
 
 
 
 
 
 
 
 
 
7a6a716
 
1f37776
cb4bfbc
 
086f852
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a6a716
 
0c26c6f
7a6a716
 
cb4bfbc
 
1f37776
 
086f852
 
 
 
7a6a716
0c26c6f
086f852
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
from typing import List, Dict, Any
from typing_extensions import TypedDict

class ExtractedInformation(TypedDict):
    first_name: str | None = None  # Customer's first name
    last_name: str | None = None  # Customer's last name
    email: str | None = None  # Customer's contact email
    phone: str | None = None  # Customer's contact phone number
    address: str | None = None  # Customer's physical address
    invoice_number: str | None = None  # Reference number for invoices
    contract_number: str | None = None  # Reference number for contracts

class ExtractedTicket(TypedDict):
    title: str | None = None
    ticket_num: int | None = None
    ticket_description: str | None = None
    ticket_type_name: str | None = None 
    ticket_type_code: str | None = None 


class TicketState(TypedDict):
    """
    Contains structured information extracted from support request emails.
    Fields are optional as not all emails will contain all information types.
    """
    # Email Information
    email: Dict[str, Any]  # Contains subject, sender, body, etc.

    # Extracted Information
    extracted_information: Dict[str, Any]  # Contains extracted information from the email

    # user identification
    user_id: str | None = None  # ID of the user in the system

    # Extracted Tickets
    extracted_tickets: List[ExtractedTicket] # Contains separated tickets from the email 

    ticket_type_name: str | None = None  # Type of ticket (e.g., invoice_copy, invoice_due_date, etc.)
    ticket_type_code: str | None = None  # Code for corresponding type of ticket

    response: str | None = None  # Response generated by the LLM

    # Processing metadata
    messages: List[Dict[str, Any]]  # Track conversation with LLM for analysis

def create_ticket_state() -> TicketState:
    extracted_information = ExtractedInformation(
        first_name=None,
        last_name=None,
        email=None,
        phone=None,
        address=None,
        invoice_number=None,
        contract_number=None
    )

    extracted_tickets: List[ExtractedTicket] = [
        ExtractedTicket(
            title=None,
            ticket_num=None,
            ticket_description=None,
            ticket_type_name=None,
            ticket_type_code=None,
        )
    ]
    return TicketState(
        email={},
        extracted_information=extracted_information,
        user_id=None,
        extracted_tickets=extracted_tickets,
        messages=[],
    )