File size: 6,885 Bytes
44c5e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import random
import uuid
from datetime import datetime


def generate_random_hex_str(length: int = 32) -> str:
    return "".join(random.choice("0123456789abcdef") for _ in range(length))


def generate_random_uuid():
    return str(uuid.uuid4())


def get_locale():
    return "en-US"


def get_timestamp_str():
    now = datetime.now()
    now_utc = datetime.utcnow()
    timezone_offset = now - now_utc
    offset_seconds = timezone_offset.total_seconds()
    offset_hours = int(offset_seconds // 3600)
    offset_minutes = int((offset_seconds % 3600) // 60)
    offset_string = f"{offset_hours:+03d}:{offset_minutes:02d}"
    timestamp_str = datetime.now().strftime("%Y-%m-%dT%H:%M:%S") + offset_string
    # print(timestamp_str)
    return timestamp_str


def get_prompt():
    return "Hello, who are you?"


class ChathubRequestConstructor:
    def __init__(
        self,
        conversation_style: str,
        client_id: str,
        conversation_id: str,
        invocation_id: int = 0,
    ):
        self.client_id = client_id
        self.conversation_id = conversation_id
        self.message_id = generate_random_uuid()
        self.invocation_id = invocation_id
        self.conversation_style = conversation_style
        self.construct()

    def construct(self):
        self.request_message = {
            "arguments": [
                {
                    "source": "cib",
                    "optionsSets": [
                        "nlu_direct_response_filter",
                        "deepleo",
                        "disable_emoji_spoken_text",
                        "responsible_ai_policy_235",
                        "enablemm",
                        "dv3sugg",
                        "autosave",
                        "uquopt",
                        "enelecintl",
                        "gndeleccf",
                        "gndlogcf",
                        "logprobsc",
                        "fluxprod",
                        "eredirecturl",
                    ],
                    "allowedMessageTypes": [
                        "ActionRequest",
                        "Chat",
                        "ConfirmationCard",
                        "Context",
                        "InternalSearchQuery",
                        "InternalSearchResult",
                        "Disengaged",
                        "InternalLoaderMessage",
                        "InvokeAction",
                        "Progress",
                        "RenderCardRequest",
                        "RenderContentRequest",
                        "AdsQuery",
                        "SemanticSerp",
                        "GenerateContentQuery",
                        "SearchQuery",
                    ],
                    "sliceIds": [
                        "cruisecf",
                        "adssqovr",
                        "gbacf",
                        "bggrey",
                        "1366cf",
                        "vnextvoice",
                        "caccnctat3",
                        "specedgecf",
                        "inosanewsmob",
                        "wrapnoins",
                        "readaloud",
                        "autotts",
                        "styleoffall",
                        "rwt2",
                        "dismmaslp",
                        "1117gndelecs0",
                        "713logprobsc",
                        "1118wcpdcl",
                        "1119backos",
                        "1103gndlog",
                        "1107reviewss0",
                        "fluxnosearch",
                        "727nrprdrt3",
                        "codecreator1",
                        "kchero50cf",
                        "cacmuidarb",
                    ],
                    "verbosity": "verbose",
                    "scenario": "SERP",
                    "plugins": [
                        {"id": "c310c353-b9f0-4d76-ab0d-1dd5e979cf68"},
                    ],
                    "traceId": generate_random_hex_str(),
                    "conversationHistoryOptionsSets": [
                        "autosave",
                        "savemem",
                        "uprofupd",
                        "uprofgen",
                    ],
                    "isStartOfSession": self.invocation_id == 0,
                    "requestId": self.message_id,
                    "message": {
                        "locale": get_locale(),  # "en-US"
                        "market": get_locale(),  # "en-US"
                        "region": get_locale()[-2:],  # "US"
                        "location": "lat:47.639557;long:-122.128159;re=1000m;",
                        "locationHints": [
                            {
                                "SourceType": 1,
                                "RegionType": 2,
                                "Center": {
                                    "Latitude": 38.668399810791016,
                                    "Longitude": -121.14900207519531,
                                },
                                "Radius": 24902,
                                "Name": "Folsom, California",
                                "Accuracy": 24902,
                                "FDConfidence": 0.5,
                                "CountryName": "United States",
                                "CountryConfidence": 8,
                                "Admin1Name": "California",
                                "PopulatedPlaceName": "Folsom",
                                "PopulatedPlaceConfidence": 5,
                                "PostCodeName": "95630",
                                "UtcOffset": -8,
                                "Dma": 862,
                            }
                        ],
                        "userIpAddress": "192.55.55.51",
                        "timestamp": get_timestamp_str(),  # "2023-11-20T12:50:17+08:00",
                        "author": "user",
                        "inputMethod": "Keyboard",
                        "text": get_prompt(),
                        "messageType": "Chat",
                        "requestId": self.message_id,  # "a6ecd3aa-1007-6959-52fb-9e23f34e86be",
                        "messageId": self.message_id,  # "a6ecd3aa-1007-6959-52fb-9e23f34e86be",
                    },
                    "tone": self.conversation_style.capitalize(),
                    "spokenTextMode": "None",
                    "conversationId": self.conversation_id,  # "51D|BingProd|30FA137663F2BDBA514A0F31EE0A99E082B5AF8C0DA05696D2A5C6B56C10CF99",
                    "participant": {
                        "id": self.client_id,  # "1055519195774559",
                    },
                }
            ],
            "invocationId": str(self.invocation_id),
            "target": "chat",
            "type": 4,
        }