Spaces:
Runtime error
Runtime error
:recycle: [Refactor] ChathubPayload: Extract steps from construct()
Browse files
networks/chathub_request_payload_constructor.py
CHANGED
@@ -34,6 +34,7 @@ class ChathubRequestPayloadConstructor:
|
|
34 |
invocation_id: int = 0,
|
35 |
conversation_style: str = ConversationStyle.PRECISE.value,
|
36 |
system_prompt: str = None,
|
|
|
37 |
):
|
38 |
self.prompt = prompt
|
39 |
self.client_id = client_id
|
@@ -42,6 +43,7 @@ class ChathubRequestPayloadConstructor:
|
|
42 |
self.conversation_style = conversation_style
|
43 |
self.message_id = self.generate_random_uuid()
|
44 |
self.system_prompt = system_prompt
|
|
|
45 |
self.construct()
|
46 |
|
47 |
def generate_random_uuid(self):
|
@@ -50,7 +52,7 @@ class ChathubRequestPayloadConstructor:
|
|
50 |
def generate_random_hex_str(self, length: int = 32) -> str:
|
51 |
return "".join(random.choice("0123456789abcdef") for _ in range(length))
|
52 |
|
53 |
-
def
|
54 |
options_sets_body = [
|
55 |
"nlu_direct_response_filter",
|
56 |
"deepleo",
|
@@ -68,7 +70,8 @@ class ChathubRequestPayloadConstructor:
|
|
68 |
"rcaltimeans",
|
69 |
"eredirecturl",
|
70 |
]
|
71 |
-
|
|
|
72 |
"precise": options_sets_body
|
73 |
+ [
|
74 |
"h3precise",
|
@@ -87,16 +90,30 @@ class ChathubRequestPayloadConstructor:
|
|
87 |
"gencontentv3",
|
88 |
],
|
89 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
|
|
91 |
self.system_context = SystemPromptContextConstructor(
|
92 |
self.system_prompt
|
93 |
).system_context
|
94 |
|
|
|
|
|
|
|
|
|
|
|
95 |
self.request_payload = {
|
96 |
"arguments": [
|
97 |
{
|
98 |
"source": "cib",
|
99 |
-
"optionsSets":
|
100 |
"allowedMessageTypes": [
|
101 |
"ActionRequest",
|
102 |
"Chat",
|
@@ -142,9 +159,7 @@ class ChathubRequestPayloadConstructor:
|
|
142 |
],
|
143 |
"verbosity": "verbose",
|
144 |
"scenario": "SERP",
|
145 |
-
"plugins":
|
146 |
-
{"id": "c310c353-b9f0-4d76-ab0d-1dd5e979cf68"},
|
147 |
-
],
|
148 |
"previousMessages": self.system_context,
|
149 |
"traceId": self.generate_random_hex_str(),
|
150 |
"conversationHistoryOptionsSets": [
|
|
|
34 |
invocation_id: int = 0,
|
35 |
conversation_style: str = ConversationStyle.PRECISE.value,
|
36 |
system_prompt: str = None,
|
37 |
+
enable_search: bool = True,
|
38 |
):
|
39 |
self.prompt = prompt
|
40 |
self.client_id = client_id
|
|
|
43 |
self.conversation_style = conversation_style
|
44 |
self.message_id = self.generate_random_uuid()
|
45 |
self.system_prompt = system_prompt
|
46 |
+
self.enable_search = enable_search
|
47 |
self.construct()
|
48 |
|
49 |
def generate_random_uuid(self):
|
|
|
52 |
def generate_random_hex_str(self, length: int = 32) -> str:
|
53 |
return "".join(random.choice("0123456789abcdef") for _ in range(length))
|
54 |
|
55 |
+
def set_options_sets(self):
|
56 |
options_sets_body = [
|
57 |
"nlu_direct_response_filter",
|
58 |
"deepleo",
|
|
|
70 |
"rcaltimeans",
|
71 |
"eredirecturl",
|
72 |
]
|
73 |
+
|
74 |
+
options_sets_by_styles = {
|
75 |
"precise": options_sets_body
|
76 |
+ [
|
77 |
"h3precise",
|
|
|
90 |
"gencontentv3",
|
91 |
],
|
92 |
}
|
93 |
+
self.options_sets = options_sets_by_styles[self.conversation_style]
|
94 |
+
|
95 |
+
def set_search_options(self):
|
96 |
+
self.plugins = []
|
97 |
+
if self.enable_search:
|
98 |
+
self.plugins.append({"id": "c310c353-b9f0-4d76-ab0d-1dd5e979cf68"})
|
99 |
+
else:
|
100 |
+
self.options_sets.append("nosearchall")
|
101 |
|
102 |
+
def set_system_context(self):
|
103 |
self.system_context = SystemPromptContextConstructor(
|
104 |
self.system_prompt
|
105 |
).system_context
|
106 |
|
107 |
+
def construct(self):
|
108 |
+
self.set_options_sets()
|
109 |
+
self.set_search_options()
|
110 |
+
self.set_system_context()
|
111 |
+
|
112 |
self.request_payload = {
|
113 |
"arguments": [
|
114 |
{
|
115 |
"source": "cib",
|
116 |
+
"optionsSets": self.options_sets,
|
117 |
"allowedMessageTypes": [
|
118 |
"ActionRequest",
|
119 |
"Chat",
|
|
|
159 |
],
|
160 |
"verbosity": "verbose",
|
161 |
"scenario": "SERP",
|
162 |
+
"plugins": self.plugins,
|
|
|
|
|
163 |
"previousMessages": self.system_context,
|
164 |
"traceId": self.generate_random_hex_str(),
|
165 |
"conversationHistoryOptionsSets": [
|