webscout 7.8__py3-none-any.whl → 8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webscout might be problematic. Click here for more details.
- webscout/Bard.py +5 -25
- webscout/DWEBS.py +476 -476
- webscout/Extra/GitToolkit/__init__.py +10 -0
- webscout/Extra/GitToolkit/gitapi/__init__.py +12 -0
- webscout/Extra/GitToolkit/gitapi/repository.py +195 -0
- webscout/Extra/GitToolkit/gitapi/user.py +96 -0
- webscout/Extra/GitToolkit/gitapi/utils.py +62 -0
- webscout/Extra/YTToolkit/ytapi/video.py +232 -103
- webscout/Extra/__init__.py +2 -0
- webscout/Extra/autocoder/__init__.py +1 -1
- webscout/Extra/autocoder/{rawdog.py → autocoder.py} +849 -849
- webscout/Extra/tempmail/__init__.py +26 -0
- webscout/Extra/tempmail/async_utils.py +141 -0
- webscout/Extra/tempmail/base.py +156 -0
- webscout/Extra/tempmail/cli.py +187 -0
- webscout/Extra/tempmail/mail_tm.py +361 -0
- webscout/Extra/tempmail/temp_mail_io.py +292 -0
- webscout/Provider/AISEARCH/__init__.py +5 -1
- webscout/Provider/AISEARCH/hika_search.py +194 -0
- webscout/Provider/AISEARCH/monica_search.py +246 -0
- webscout/Provider/AISEARCH/scira_search.py +320 -0
- webscout/Provider/AISEARCH/webpilotai_search.py +281 -0
- webscout/Provider/AllenAI.py +255 -122
- webscout/Provider/DeepSeek.py +1 -2
- webscout/Provider/Deepinfra.py +296 -286
- webscout/Provider/ElectronHub.py +709 -716
- webscout/Provider/ExaAI.py +261 -0
- webscout/Provider/ExaChat.py +28 -6
- webscout/Provider/Gemini.py +167 -165
- webscout/Provider/GithubChat.py +2 -1
- webscout/Provider/Groq.py +38 -24
- webscout/Provider/LambdaChat.py +2 -1
- webscout/Provider/Netwrck.py +3 -2
- webscout/Provider/OpenGPT.py +199 -0
- webscout/Provider/PI.py +39 -24
- webscout/Provider/TextPollinationsAI.py +232 -230
- webscout/Provider/Youchat.py +326 -296
- webscout/Provider/__init__.py +10 -4
- webscout/Provider/ai4chat.py +58 -56
- webscout/Provider/akashgpt.py +34 -22
- webscout/Provider/copilot.py +427 -427
- webscout/Provider/freeaichat.py +9 -2
- webscout/Provider/labyrinth.py +121 -20
- webscout/Provider/llmchatco.py +306 -0
- webscout/Provider/scira_chat.py +271 -0
- webscout/Provider/typefully.py +280 -0
- webscout/Provider/uncovr.py +312 -299
- webscout/Provider/yep.py +64 -12
- webscout/__init__.py +38 -36
- webscout/cli.py +293 -293
- webscout/conversation.py +350 -17
- webscout/litprinter/__init__.py +59 -667
- webscout/optimizers.py +419 -419
- webscout/update_checker.py +14 -12
- webscout/version.py +1 -1
- webscout/webscout_search.py +1346 -1282
- webscout/webscout_search_async.py +877 -813
- {webscout-7.8.dist-info → webscout-8.0.dist-info}/METADATA +44 -39
- {webscout-7.8.dist-info → webscout-8.0.dist-info}/RECORD +63 -46
- webscout/Provider/DARKAI.py +0 -225
- webscout/Provider/EDITEE.py +0 -192
- webscout/litprinter/colors.py +0 -54
- {webscout-7.8.dist-info → webscout-8.0.dist-info}/LICENSE.md +0 -0
- {webscout-7.8.dist-info → webscout-8.0.dist-info}/WHEEL +0 -0
- {webscout-7.8.dist-info → webscout-8.0.dist-info}/entry_points.txt +0 -0
- {webscout-7.8.dist-info → webscout-8.0.dist-info}/top_level.txt +0 -0
webscout/Provider/uncovr.py
CHANGED
|
@@ -1,299 +1,312 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import json
|
|
3
|
-
import uuid
|
|
4
|
-
import re
|
|
5
|
-
from typing import Any, Dict, Optional, Generator, Union
|
|
6
|
-
from webscout.AIutel import Optimizers
|
|
7
|
-
from webscout.AIutel import Conversation
|
|
8
|
-
from webscout.AIutel import AwesomePrompts
|
|
9
|
-
from webscout.AIbase import Provider
|
|
10
|
-
from webscout import exceptions
|
|
11
|
-
from webscout.litagent import LitAgent
|
|
12
|
-
|
|
13
|
-
class UncovrAI(Provider):
|
|
14
|
-
"""
|
|
15
|
-
A class to interact with the Uncovr AI chat API.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
AVAILABLE_MODELS = [
|
|
19
|
-
"default",
|
|
20
|
-
"gpt-4o-mini",
|
|
21
|
-
"gemini-2-flash",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"qwen-
|
|
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
|
-
self.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"Accept
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"Sec-CH-UA
|
|
71
|
-
"
|
|
72
|
-
"Sec-
|
|
73
|
-
"
|
|
74
|
-
"Sec-Fetch-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
self.session.
|
|
80
|
-
|
|
81
|
-
self.
|
|
82
|
-
|
|
83
|
-
self.
|
|
84
|
-
self.
|
|
85
|
-
self.
|
|
86
|
-
self.
|
|
87
|
-
self.
|
|
88
|
-
|
|
89
|
-
self.
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
import uuid
|
|
4
|
+
import re
|
|
5
|
+
from typing import Any, Dict, Optional, Generator, Union
|
|
6
|
+
from webscout.AIutel import Optimizers
|
|
7
|
+
from webscout.AIutel import Conversation
|
|
8
|
+
from webscout.AIutel import AwesomePrompts
|
|
9
|
+
from webscout.AIbase import Provider
|
|
10
|
+
from webscout import exceptions
|
|
11
|
+
from webscout.litagent import LitAgent
|
|
12
|
+
|
|
13
|
+
class UncovrAI(Provider):
|
|
14
|
+
"""
|
|
15
|
+
A class to interact with the Uncovr AI chat API.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
AVAILABLE_MODELS = [
|
|
19
|
+
"default",
|
|
20
|
+
"gpt-4o-mini",
|
|
21
|
+
"gemini-2-flash",
|
|
22
|
+
"gemini-2-flash-lite",
|
|
23
|
+
"groq-llama-3-1-8b"
|
|
24
|
+
# The following models are not available in the free plan:
|
|
25
|
+
# "o3-mini",
|
|
26
|
+
# "claude-3-7-sonnet",
|
|
27
|
+
# "gpt-4o",
|
|
28
|
+
# "claude-3-5-sonnet-v2",
|
|
29
|
+
# "deepseek-r1-distill-llama-70b",
|
|
30
|
+
# "deepseek-r1-distill-qwen-32b",
|
|
31
|
+
# "gemini-2-flash-lite-preview",
|
|
32
|
+
# "qwen-qwq-32b"
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
is_conversation: bool = True,
|
|
38
|
+
max_tokens: int = 2049,
|
|
39
|
+
timeout: int = 30,
|
|
40
|
+
intro: str = None,
|
|
41
|
+
filepath: str = None,
|
|
42
|
+
update_file: bool = True,
|
|
43
|
+
proxies: dict = {},
|
|
44
|
+
history_offset: int = 10250,
|
|
45
|
+
act: str = None,
|
|
46
|
+
model: str = "default",
|
|
47
|
+
chat_id: str = None,
|
|
48
|
+
user_id: str = None,
|
|
49
|
+
browser: str = "chrome"
|
|
50
|
+
):
|
|
51
|
+
"""Initializes the Uncovr AI API client."""
|
|
52
|
+
if model not in self.AVAILABLE_MODELS:
|
|
53
|
+
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
|
|
54
|
+
|
|
55
|
+
self.url = "https://uncovr.app/api/workflows/chat"
|
|
56
|
+
|
|
57
|
+
# Initialize LitAgent for user agent generation
|
|
58
|
+
self.agent = LitAgent()
|
|
59
|
+
# Use fingerprinting to create a consistent browser identity
|
|
60
|
+
self.fingerprint = self.agent.generate_fingerprint(browser)
|
|
61
|
+
|
|
62
|
+
# Use the fingerprint for headers
|
|
63
|
+
self.headers = {
|
|
64
|
+
"Accept": self.fingerprint["accept"],
|
|
65
|
+
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
66
|
+
"Accept-Language": self.fingerprint["accept_language"],
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"Origin": "https://uncovr.app",
|
|
69
|
+
"Referer": "https://uncovr.app/",
|
|
70
|
+
"Sec-CH-UA": self.fingerprint["sec_ch_ua"] or '"Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127"',
|
|
71
|
+
"Sec-CH-UA-Mobile": "?0",
|
|
72
|
+
"Sec-CH-UA-Platform": f'"{self.fingerprint["platform"]}"',
|
|
73
|
+
"User-Agent": self.fingerprint["user_agent"],
|
|
74
|
+
"Sec-Fetch-Dest": "empty",
|
|
75
|
+
"Sec-Fetch-Mode": "cors",
|
|
76
|
+
"Sec-Fetch-Site": "same-origin"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
self.session = requests.Session()
|
|
80
|
+
self.session.headers.update(self.headers)
|
|
81
|
+
self.session.proxies.update(proxies)
|
|
82
|
+
|
|
83
|
+
self.is_conversation = is_conversation
|
|
84
|
+
self.max_tokens_to_sample = max_tokens
|
|
85
|
+
self.timeout = timeout
|
|
86
|
+
self.last_response = {}
|
|
87
|
+
self.model = model
|
|
88
|
+
self.chat_id = chat_id or str(uuid.uuid4())
|
|
89
|
+
self.user_id = user_id or f"user_{str(uuid.uuid4())[:8].upper()}"
|
|
90
|
+
|
|
91
|
+
self.__available_optimizers = (
|
|
92
|
+
method
|
|
93
|
+
for method in dir(Optimizers)
|
|
94
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
95
|
+
)
|
|
96
|
+
Conversation.intro = (
|
|
97
|
+
AwesomePrompts().get_act(
|
|
98
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
99
|
+
)
|
|
100
|
+
if act
|
|
101
|
+
else intro or Conversation.intro
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
self.conversation = Conversation(
|
|
105
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
106
|
+
)
|
|
107
|
+
self.conversation.history_offset = history_offset
|
|
108
|
+
|
|
109
|
+
def refresh_identity(self, browser: str = None):
|
|
110
|
+
"""
|
|
111
|
+
Refreshes the browser identity fingerprint.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
browser: Specific browser to use for the new fingerprint
|
|
115
|
+
"""
|
|
116
|
+
browser = browser or self.fingerprint.get("browser_type", "chrome")
|
|
117
|
+
self.fingerprint = self.agent.generate_fingerprint(browser)
|
|
118
|
+
|
|
119
|
+
# Update headers with new fingerprint
|
|
120
|
+
self.headers.update({
|
|
121
|
+
"Accept": self.fingerprint["accept"],
|
|
122
|
+
"Accept-Language": self.fingerprint["accept_language"],
|
|
123
|
+
"Sec-CH-UA": self.fingerprint["sec_ch_ua"] or self.headers["Sec-CH-UA"],
|
|
124
|
+
"Sec-CH-UA-Platform": f'"{self.fingerprint["platform"]}"',
|
|
125
|
+
"User-Agent": self.fingerprint["user_agent"],
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
# Update session headers
|
|
129
|
+
for header, value in self.headers.items():
|
|
130
|
+
self.session.headers[header] = value
|
|
131
|
+
|
|
132
|
+
return self.fingerprint
|
|
133
|
+
|
|
134
|
+
def ask(
|
|
135
|
+
self,
|
|
136
|
+
prompt: str,
|
|
137
|
+
stream: bool = False,
|
|
138
|
+
raw: bool = False,
|
|
139
|
+
optimizer: str = None,
|
|
140
|
+
conversationally: bool = False,
|
|
141
|
+
temperature: int = 32,
|
|
142
|
+
creativity: str = "medium",
|
|
143
|
+
selected_focus: list = ["web"],
|
|
144
|
+
selected_tools: list = ["quick-cards"]
|
|
145
|
+
) -> Union[Dict[str, Any], Generator]:
|
|
146
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
147
|
+
if optimizer:
|
|
148
|
+
if optimizer in self.__available_optimizers:
|
|
149
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
150
|
+
conversation_prompt if conversationally else prompt
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
raise Exception(f"Optimizer is not one of {self.__available_optimizers}")
|
|
154
|
+
|
|
155
|
+
# Prepare the request payload
|
|
156
|
+
payload = {
|
|
157
|
+
"content": conversation_prompt,
|
|
158
|
+
"chatId": self.chat_id,
|
|
159
|
+
"userMessageId": str(uuid.uuid4()),
|
|
160
|
+
"ai_config": {
|
|
161
|
+
"selectedFocus": selected_focus,
|
|
162
|
+
"selectedTools": selected_tools,
|
|
163
|
+
"agentId": "chat",
|
|
164
|
+
"modelId": self.model,
|
|
165
|
+
"temperature": temperature,
|
|
166
|
+
"creativity": creativity
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
def for_stream():
|
|
171
|
+
try:
|
|
172
|
+
with self.session.post(self.url, json=payload, stream=True, timeout=self.timeout) as response:
|
|
173
|
+
if response.status_code != 200:
|
|
174
|
+
# If we get a non-200 response, try refreshing our identity once
|
|
175
|
+
if response.status_code in [403, 429]:
|
|
176
|
+
self.refresh_identity()
|
|
177
|
+
# Retry with new identity
|
|
178
|
+
with self.session.post(self.url, json=payload, stream=True, timeout=self.timeout) as retry_response:
|
|
179
|
+
if not retry_response.ok:
|
|
180
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
181
|
+
f"Failed to generate response after identity refresh - ({retry_response.status_code}, {retry_response.reason}) - {retry_response.text}"
|
|
182
|
+
)
|
|
183
|
+
response = retry_response
|
|
184
|
+
else:
|
|
185
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
186
|
+
f"Request failed with status code {response.status_code}"
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
streaming_text = ""
|
|
190
|
+
for line in response.iter_lines():
|
|
191
|
+
if line:
|
|
192
|
+
try:
|
|
193
|
+
line = line.decode('utf-8')
|
|
194
|
+
# Use regex to match content messages
|
|
195
|
+
content_match = re.match(r'^0:\s*"?(.*?)"?$', line)
|
|
196
|
+
if content_match: # Content message
|
|
197
|
+
content = content_match.group(1)
|
|
198
|
+
streaming_text += content
|
|
199
|
+
resp = dict(text=content)
|
|
200
|
+
yield resp if raw else resp
|
|
201
|
+
# Check for error messages
|
|
202
|
+
error_match = re.match(r'^2:\[{"type":"error","error":"(.*?)"}]$', line)
|
|
203
|
+
if error_match:
|
|
204
|
+
error_msg = error_match.group(1)
|
|
205
|
+
raise exceptions.FailedToGenerateResponseError(f"API Error: {error_msg}")
|
|
206
|
+
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
207
|
+
continue
|
|
208
|
+
|
|
209
|
+
self.last_response = {"text": streaming_text}
|
|
210
|
+
self.conversation.update_chat_history(prompt, streaming_text)
|
|
211
|
+
|
|
212
|
+
except requests.RequestException as e:
|
|
213
|
+
raise exceptions.FailedToGenerateResponseError(f"Request failed: {str(e)}")
|
|
214
|
+
|
|
215
|
+
def for_non_stream():
|
|
216
|
+
try:
|
|
217
|
+
response = self.session.post(self.url, json=payload, timeout=self.timeout)
|
|
218
|
+
if response.status_code != 200:
|
|
219
|
+
if response.status_code in [403, 429]:
|
|
220
|
+
self.refresh_identity()
|
|
221
|
+
response = self.session.post(self.url, json=payload, timeout=self.timeout)
|
|
222
|
+
if not response.ok:
|
|
223
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
224
|
+
f"Failed to generate response after identity refresh - ({response.status_code}, {response.reason}) - {response.text}"
|
|
225
|
+
)
|
|
226
|
+
else:
|
|
227
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
228
|
+
f"Request failed with status code {response.status_code}"
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
full_response = ""
|
|
232
|
+
for line in response.iter_lines():
|
|
233
|
+
if line:
|
|
234
|
+
try:
|
|
235
|
+
line = line.decode('utf-8')
|
|
236
|
+
content_match = re.match(r'^0:\s*"?(.*?)"?$', line)
|
|
237
|
+
if content_match:
|
|
238
|
+
content = content_match.group(1)
|
|
239
|
+
full_response += content
|
|
240
|
+
# Check for error messages
|
|
241
|
+
error_match = re.match(r'^2:\[{"type":"error","error":"(.*?)"}]$', line)
|
|
242
|
+
if error_match:
|
|
243
|
+
error_msg = error_match.group(1)
|
|
244
|
+
raise exceptions.FailedToGenerateResponseError(f"API Error: {error_msg}")
|
|
245
|
+
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
246
|
+
continue
|
|
247
|
+
|
|
248
|
+
self.last_response = {"text": full_response}
|
|
249
|
+
self.conversation.update_chat_history(prompt, full_response)
|
|
250
|
+
return {"text": full_response}
|
|
251
|
+
except Exception as e:
|
|
252
|
+
raise exceptions.FailedToGenerateResponseError(f"Request failed: {e}")
|
|
253
|
+
|
|
254
|
+
return for_stream() if stream else for_non_stream()
|
|
255
|
+
|
|
256
|
+
def chat(
|
|
257
|
+
self,
|
|
258
|
+
prompt: str,
|
|
259
|
+
stream: bool = False,
|
|
260
|
+
optimizer: str = None,
|
|
261
|
+
conversationally: bool = False,
|
|
262
|
+
temperature: int = 32,
|
|
263
|
+
creativity: str = "medium",
|
|
264
|
+
selected_focus: list = ["web"],
|
|
265
|
+
selected_tools: list = []
|
|
266
|
+
) -> Union[str, Generator[str, None, None]]:
|
|
267
|
+
def for_stream():
|
|
268
|
+
for response in self.ask(
|
|
269
|
+
prompt, True, optimizer=optimizer, conversationally=conversationally,
|
|
270
|
+
temperature=temperature, creativity=creativity,
|
|
271
|
+
selected_focus=selected_focus, selected_tools=selected_tools
|
|
272
|
+
):
|
|
273
|
+
yield self.get_message(response)
|
|
274
|
+
def for_non_stream():
|
|
275
|
+
return self.get_message(
|
|
276
|
+
self.ask(
|
|
277
|
+
prompt, False, optimizer=optimizer, conversationally=conversationally,
|
|
278
|
+
temperature=temperature, creativity=creativity,
|
|
279
|
+
selected_focus=selected_focus, selected_tools=selected_tools
|
|
280
|
+
)
|
|
281
|
+
)
|
|
282
|
+
return for_stream() if stream else for_non_stream()
|
|
283
|
+
|
|
284
|
+
def get_message(self, response: dict) -> str:
|
|
285
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
286
|
+
return response["text"].replace('\\n', '\n').replace('\\n\\n', '\n\n')
|
|
287
|
+
|
|
288
|
+
if __name__ == "__main__":
|
|
289
|
+
print("-" * 80)
|
|
290
|
+
print(f"{'Model':<50} {'Status':<10} {'Response'}")
|
|
291
|
+
print("-" * 80)
|
|
292
|
+
|
|
293
|
+
for model in UncovrAI.AVAILABLE_MODELS:
|
|
294
|
+
try:
|
|
295
|
+
test_ai = UncovrAI(model=model, timeout=60)
|
|
296
|
+
response = test_ai.chat("Say 'Hello' in one word", stream=True)
|
|
297
|
+
response_text = ""
|
|
298
|
+
for chunk in response:
|
|
299
|
+
response_text += chunk
|
|
300
|
+
|
|
301
|
+
if response_text and len(response_text.strip()) > 0:
|
|
302
|
+
status = "✓"
|
|
303
|
+
# Clean and truncate response
|
|
304
|
+
clean_text = response_text.strip().encode('utf-8', errors='ignore').decode('utf-8')
|
|
305
|
+
display_text = clean_text[:50] + "..." if len(clean_text) > 50 else clean_text
|
|
306
|
+
else:
|
|
307
|
+
status = "✗"
|
|
308
|
+
display_text = "Empty or invalid response"
|
|
309
|
+
print(f"\r{model:<50} {status:<10} {display_text}")
|
|
310
|
+
except Exception as e:
|
|
311
|
+
print(f"\r{model:<50} {'✗':<10} {str(e)}")
|
|
312
|
+
|