Hansimov commited on
Commit
e125cf3
1 Parent(s): 44c5e78

:zap: [Enhance] Remove unnecessary info for authentication

Browse files
Files changed (1) hide show
  1. chathub_request_constructor.py +14 -63
chathub_request_constructor.py CHANGED
@@ -3,50 +3,29 @@ import uuid
3
  from datetime import datetime
4
 
5
 
6
- def generate_random_hex_str(length: int = 32) -> str:
7
- return "".join(random.choice("0123456789abcdef") for _ in range(length))
8
-
9
-
10
- def generate_random_uuid():
11
- return str(uuid.uuid4())
12
-
13
-
14
- def get_locale():
15
- return "en-US"
16
-
17
-
18
- def get_timestamp_str():
19
- now = datetime.now()
20
- now_utc = datetime.utcnow()
21
- timezone_offset = now - now_utc
22
- offset_seconds = timezone_offset.total_seconds()
23
- offset_hours = int(offset_seconds // 3600)
24
- offset_minutes = int((offset_seconds % 3600) // 60)
25
- offset_string = f"{offset_hours:+03d}:{offset_minutes:02d}"
26
- timestamp_str = datetime.now().strftime("%Y-%m-%dT%H:%M:%S") + offset_string
27
- # print(timestamp_str)
28
- return timestamp_str
29
-
30
-
31
- def get_prompt():
32
- return "Hello, who are you?"
33
-
34
-
35
  class ChathubRequestConstructor:
36
  def __init__(
37
  self,
38
- conversation_style: str,
39
  client_id: str,
40
  conversation_id: str,
41
  invocation_id: int = 0,
 
42
  ):
 
43
  self.client_id = client_id
44
  self.conversation_id = conversation_id
45
- self.message_id = generate_random_uuid()
46
  self.invocation_id = invocation_id
47
  self.conversation_style = conversation_style
 
48
  self.construct()
49
 
 
 
 
 
 
 
50
  def construct(self):
51
  self.request_message = {
52
  "arguments": [
@@ -119,7 +98,7 @@ class ChathubRequestConstructor:
119
  "plugins": [
120
  {"id": "c310c353-b9f0-4d76-ab0d-1dd5e979cf68"},
121
  ],
122
- "traceId": generate_random_hex_str(),
123
  "conversationHistoryOptionsSets": [
124
  "autosave",
125
  "savemem",
@@ -129,46 +108,18 @@ class ChathubRequestConstructor:
129
  "isStartOfSession": self.invocation_id == 0,
130
  "requestId": self.message_id,
131
  "message": {
132
- "locale": get_locale(), # "en-US"
133
- "market": get_locale(), # "en-US"
134
- "region": get_locale()[-2:], # "US"
135
- "location": "lat:47.639557;long:-122.128159;re=1000m;",
136
- "locationHints": [
137
- {
138
- "SourceType": 1,
139
- "RegionType": 2,
140
- "Center": {
141
- "Latitude": 38.668399810791016,
142
- "Longitude": -121.14900207519531,
143
- },
144
- "Radius": 24902,
145
- "Name": "Folsom, California",
146
- "Accuracy": 24902,
147
- "FDConfidence": 0.5,
148
- "CountryName": "United States",
149
- "CountryConfidence": 8,
150
- "Admin1Name": "California",
151
- "PopulatedPlaceName": "Folsom",
152
- "PopulatedPlaceConfidence": 5,
153
- "PostCodeName": "95630",
154
- "UtcOffset": -8,
155
- "Dma": 862,
156
- }
157
- ],
158
- "userIpAddress": "192.55.55.51",
159
- "timestamp": get_timestamp_str(), # "2023-11-20T12:50:17+08:00",
160
  "author": "user",
161
  "inputMethod": "Keyboard",
162
- "text": get_prompt(),
163
  "messageType": "Chat",
164
  "requestId": self.message_id, # "a6ecd3aa-1007-6959-52fb-9e23f34e86be",
165
  "messageId": self.message_id, # "a6ecd3aa-1007-6959-52fb-9e23f34e86be",
166
  },
167
  "tone": self.conversation_style.capitalize(),
168
  "spokenTextMode": "None",
169
- "conversationId": self.conversation_id, # "51D|BingProd|30FA137663F2BDBA514A0F31EE0A99E082B5AF8C0DA05696D2A5C6B56C10CF99",
170
  "participant": {
171
- "id": self.client_id, # "1055519195774559",
172
  },
173
  }
174
  ],
 
3
  from datetime import datetime
4
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  class ChathubRequestConstructor:
7
  def __init__(
8
  self,
9
+ prompt,
10
  client_id: str,
11
  conversation_id: str,
12
  invocation_id: int = 0,
13
+ conversation_style: str = "precise",
14
  ):
15
+ self.prompt = prompt
16
  self.client_id = client_id
17
  self.conversation_id = conversation_id
 
18
  self.invocation_id = invocation_id
19
  self.conversation_style = conversation_style
20
+ self.message_id = self._generate_random_uuid()
21
  self.construct()
22
 
23
+ def _generate_random_uuid(self):
24
+ return str(uuid.uuid4())
25
+
26
+ def _generate_random_hex_str(self, length: int = 32) -> str:
27
+ return "".join(random.choice("0123456789abcdef") for _ in range(length))
28
+
29
  def construct(self):
30
  self.request_message = {
31
  "arguments": [
 
98
  "plugins": [
99
  {"id": "c310c353-b9f0-4d76-ab0d-1dd5e979cf68"},
100
  ],
101
+ "traceId": self._generate_random_hex_str(),
102
  "conversationHistoryOptionsSets": [
103
  "autosave",
104
  "savemem",
 
108
  "isStartOfSession": self.invocation_id == 0,
109
  "requestId": self.message_id,
110
  "message": {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  "author": "user",
112
  "inputMethod": "Keyboard",
113
+ "text": self.prompt,
114
  "messageType": "Chat",
115
  "requestId": self.message_id, # "a6ecd3aa-1007-6959-52fb-9e23f34e86be",
116
  "messageId": self.message_id, # "a6ecd3aa-1007-6959-52fb-9e23f34e86be",
117
  },
118
  "tone": self.conversation_style.capitalize(),
119
  "spokenTextMode": "None",
120
+ "conversationId": self.conversation_id, # "51D|BingProdUnAuthenticatedUsers|65761F31183134340AFD8F9AF1532EA90DC7F11ED348765DE9BAC956C9BA4669",
121
  "participant": {
122
+ "id": self.client_id, # "23EBCCB7073868D70172DF780674692D",
123
  },
124
  }
125
  ],