webscout 7.8__py3-none-any.whl → 7.9__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.

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