webscout 7.4__py3-none-any.whl → 7.5__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 (42) hide show
  1. webscout/Provider/C4ai.py +414 -0
  2. webscout/Provider/Cloudflare.py +18 -21
  3. webscout/Provider/DeepSeek.py +3 -32
  4. webscout/Provider/Deepinfra.py +30 -21
  5. webscout/Provider/GithubChat.py +362 -0
  6. webscout/Provider/HeckAI.py +20 -3
  7. webscout/Provider/HuggingFaceChat.py +462 -0
  8. webscout/Provider/Marcus.py +7 -50
  9. webscout/Provider/Netwrck.py +6 -53
  10. webscout/Provider/Phind.py +29 -3
  11. webscout/Provider/TTI/aiarta/__init__.py +2 -0
  12. webscout/Provider/TTI/aiarta/async_aiarta.py +482 -0
  13. webscout/Provider/TTI/aiarta/sync_aiarta.py +409 -0
  14. webscout/Provider/Venice.py +200 -200
  15. webscout/Provider/Youchat.py +1 -1
  16. webscout/Provider/__init__.py +13 -2
  17. webscout/Provider/akashgpt.py +8 -5
  18. webscout/Provider/copilot.py +416 -0
  19. webscout/Provider/flowith.py +181 -0
  20. webscout/Provider/granite.py +17 -53
  21. webscout/Provider/llamatutor.py +6 -46
  22. webscout/Provider/llmchat.py +7 -46
  23. webscout/Provider/multichat.py +29 -91
  24. webscout/exceptions.py +19 -9
  25. webscout/update_checker.py +55 -93
  26. webscout/version.py +1 -1
  27. webscout-7.5.dist-info/LICENSE.md +146 -0
  28. {webscout-7.4.dist-info → webscout-7.5.dist-info}/METADATA +5 -126
  29. {webscout-7.4.dist-info → webscout-7.5.dist-info}/RECORD +32 -33
  30. webscout/Local/__init__.py +0 -10
  31. webscout/Local/_version.py +0 -3
  32. webscout/Local/formats.py +0 -747
  33. webscout/Local/model.py +0 -1368
  34. webscout/Local/samplers.py +0 -125
  35. webscout/Local/thread.py +0 -539
  36. webscout/Local/ui.py +0 -401
  37. webscout/Local/utils.py +0 -388
  38. webscout/Provider/dgaf.py +0 -214
  39. webscout-7.4.dist-info/LICENSE.md +0 -211
  40. {webscout-7.4.dist-info → webscout-7.5.dist-info}/WHEEL +0 -0
  41. {webscout-7.4.dist-info → webscout-7.5.dist-info}/entry_points.txt +0 -0
  42. {webscout-7.4.dist-info → webscout-7.5.dist-info}/top_level.txt +0 -0
@@ -16,39 +16,48 @@ class DeepInfra(Provider):
16
16
  """
17
17
 
18
18
  AVAILABLE_MODELS = [
19
- "deepseek-ai/DeepSeek-R1-Turbo",
19
+ "anthropic/claude-3-7-sonnet-latest",
20
20
  "deepseek-ai/DeepSeek-R1",
21
21
  "deepseek-ai/DeepSeek-R1-Distill-Llama-70B",
22
- "deepseek-ai/DeepSeek-V3",
23
- "meta-llama/Llama-3.3-70B-Instruct-Turbo",
24
- "mistralai/Mistral-Small-24B-Instruct-2501",
25
22
  "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
26
- "microsoft/phi-4",
23
+ "deepseek-ai/DeepSeek-R1-Turbo",
24
+ "deepseek-ai/DeepSeek-V3",
25
+ "google/gemma-2-27b-it",
26
+ "google/gemma-2-9b-it",
27
+ "google/gemma-3-27b-it",
28
+ "google/gemini-1.5-flash",
29
+ "google/gemini-1.5-flash-8b",
30
+ "google/gemini-2.0-flash-001",
31
+ "Gryphe/MythoMax-L2-13b",
32
+ "meta-llama/Llama-3.2-1B-Instruct",
33
+ "meta-llama/Llama-3.2-3B-Instruct",
34
+ "meta-llama/Llama-3.2-90B-Vision-Instruct",
35
+ "meta-llama/Llama-3.2-11B-Vision-Instruct",
36
+ "meta-llama/Meta-Llama-3-70B-Instruct",
37
+ "meta-llama/Meta-Llama-3-8B-Instruct",
27
38
  "meta-llama/Meta-Llama-3.1-70B-Instruct",
39
+ "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
28
40
  "meta-llama/Meta-Llama-3.1-8B-Instruct",
29
- "meta-llama/Meta-Llama-3.1-405B-Instruct",
30
41
  "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
31
- "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
32
- "Qwen/Qwen2.5-Coder-32B-Instruct",
42
+ "meta-llama/Meta-Llama-3.1-405B-Instruct",
43
+ "microsoft/phi-4",
44
+ "microsoft/Phi-4-multimodal-instruct",
45
+ "microsoft/WizardLM-2-8x22B",
46
+ "mistralai/Mixtral-8x7B-Instruct-v0.1",
47
+ "mistralai/Mistral-7B-Instruct-v0.3",
48
+ "mistralai/Mistral-Nemo-Instruct-2407",
49
+ "mistralai/Mistral-Small-24B-Instruct-2501",
33
50
  "nvidia/Llama-3.1-Nemotron-70B-Instruct",
34
- "Qwen/Qwen2.5-72B-Instruct",
35
- "meta-llama/Llama-3.2-90B-Vision-Instruct",
36
- "meta-llama/Llama-3.2-11B-Vision-Instruct",
37
- "Gryphe/MythoMax-L2-13b",
38
51
  "NousResearch/Hermes-3-Llama-3.1-405B",
39
52
  "NovaSky-AI/Sky-T1-32B-Preview",
53
+ "Qwen/QwQ-32B",
40
54
  "Qwen/Qwen2.5-7B-Instruct",
55
+ "Qwen/Qwen2.5-72B-Instruct",
56
+ "Qwen/Qwen2.5-Coder-32B-Instruct",
41
57
  "Sao10K/L3.1-70B-Euryale-v2.2",
42
58
  "Sao10K/L3.3-70B-Euryale-v2.3",
43
- "google/gemma-2-27b-it",
44
- "google/gemma-2-9b-it",
45
- "meta-llama/Llama-3.2-1B-Instruct",
46
- "meta-llama/Llama-3.2-3B-Instruct",
47
- "meta-llama/Meta-Llama-3-70B-Instruct",
48
- "meta-llama/Meta-Llama-3-8B-Instruct",
49
- "mistralai/Mistral-Nemo-Instruct-2407",
50
- "mistralai/Mistral-7B-Instruct-v0.3",
51
- "mistralai/Mixtral-8x7B-Instruct-v0.1"
59
+ "meta-llama/Llama-3.3-70B-Instruct",
60
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo",
52
61
  ]
53
62
 
54
63
  def __init__(
@@ -0,0 +1,362 @@
1
+ import requests
2
+ import json
3
+ import time
4
+ from typing import Any, Dict, List, Optional, Union, Generator
5
+
6
+ from webscout.AIutel import Conversation
7
+ from webscout.AIutel import Optimizers
8
+ from webscout.AIutel import AwesomePrompts
9
+ from webscout.AIbase import Provider
10
+ from webscout import exceptions
11
+ from webscout import LitAgent
12
+
13
+ class GithubChat(Provider):
14
+ """
15
+ A class to interact with the GitHub Copilot Chat API.
16
+ Uses cookies for authentication and supports streaming responses.
17
+ """
18
+
19
+ # Available models
20
+ AVAILABLE_MODELS = [
21
+ "gpt-4o",
22
+ "o3-mini",
23
+ "o1",
24
+ "claude-3.5-sonnet",
25
+ "claude-3.7-sonnet",
26
+ "claude-3.7-sonnet-thought",
27
+ "gemini-2.0-flash-001"
28
+
29
+ ]
30
+
31
+ def __init__(
32
+ self,
33
+ is_conversation: bool = True,
34
+ max_tokens: int = 2000,
35
+ timeout: int = 60,
36
+ intro: str = None,
37
+ filepath: str = None,
38
+ update_file: bool = True,
39
+ proxies: dict = {},
40
+ history_offset: int = 10250,
41
+ act: str = None,
42
+ model: str = "gpt-4o",
43
+ cookie_path: str = "cookies.json"
44
+ ):
45
+ """Initialize the GithubChat client."""
46
+ if model not in self.AVAILABLE_MODELS:
47
+ raise ValueError(f"Invalid model: {model}. Choose from: {', '.join(self.AVAILABLE_MODELS)}")
48
+
49
+ self.url = "https://github.com/copilot"
50
+ self.api_url = "https://api.individual.githubcopilot.com"
51
+ self.cookie_path = cookie_path
52
+ self.session = requests.Session()
53
+ self.session.proxies.update(proxies)
54
+
55
+ # Load cookies for authentication
56
+ self.cookies = self.load_cookies()
57
+
58
+ # Set up headers for all requests
59
+ self.headers = {
60
+ "Content-Type": "application/json",
61
+ "User-Agent": LitAgent().random(),
62
+ "Accept": "*/*",
63
+ "Accept-Encoding": "gzip, deflate, br",
64
+ "Accept-Language": "en-US,en;q=0.5",
65
+ "Origin": "https://github.com",
66
+ "Referer": "https://github.com/copilot",
67
+ "GitHub-Verified-Fetch": "true",
68
+ "X-Requested-With": "XMLHttpRequest",
69
+ "Connection": "keep-alive",
70
+ "Sec-Fetch-Dest": "empty",
71
+ "Sec-Fetch-Mode": "cors",
72
+ "Sec-Fetch-Site": "same-origin",
73
+ }
74
+
75
+ # Apply cookies to session
76
+ if self.cookies:
77
+ self.session.cookies.update(self.cookies)
78
+
79
+ # Set default model
80
+ self.model = model
81
+
82
+ # Provider settings
83
+ self.is_conversation = is_conversation
84
+ self.max_tokens_to_sample = max_tokens
85
+ self.timeout = timeout
86
+ self.last_response = {}
87
+
88
+ # Available optimizers
89
+ self.__available_optimizers = (
90
+ method
91
+ for method in dir(Optimizers)
92
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
93
+ )
94
+
95
+ # Set up conversation
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
+ # Store conversation data
110
+ self._conversation_id = None
111
+ self._access_token = None
112
+
113
+ def load_cookies(self):
114
+ """Load cookies from a JSON file"""
115
+ try:
116
+ with open(self.cookie_path, 'r') as f:
117
+ cookies_data = json.load(f)
118
+
119
+ # Convert the cookie list to a dictionary format for requests
120
+ cookies = {}
121
+ for cookie in cookies_data:
122
+ # Only include cookies that are not expired and have a name and value
123
+ if 'name' in cookie and 'value':
124
+ # Check if the cookie hasn't expired
125
+ if 'expirationDate' not in cookie or cookie['expirationDate'] > time.time():
126
+ cookies[cookie['name']] = cookie['value']
127
+
128
+ return cookies
129
+ except Exception:
130
+ return {}
131
+
132
+ def get_access_token(self):
133
+ """Get GitHub Copilot access token."""
134
+ if self._access_token:
135
+ return self._access_token
136
+
137
+ url = "https://github.com/github-copilot/chat/token"
138
+
139
+ try:
140
+ response = self.session.post(url, headers=self.headers)
141
+
142
+ if response.status_code == 401:
143
+ raise exceptions.AuthenticationError("Authentication failed. Please check your cookies.")
144
+
145
+ if response.status_code != 200:
146
+ raise exceptions.FailedToGenerateResponseError(f"Failed to get access token: {response.status_code}")
147
+
148
+ data = response.json()
149
+ self._access_token = data.get("token")
150
+
151
+ if not self._access_token:
152
+ raise exceptions.FailedToGenerateResponseError("Failed to extract access token from response")
153
+
154
+ return self._access_token
155
+
156
+ except requests.exceptions.RequestException as e:
157
+ raise exceptions.FailedToGenerateResponseError(f"Failed to get access token: {str(e)}")
158
+
159
+ def create_conversation(self):
160
+ """Create a new conversation with GitHub Copilot."""
161
+ if self._conversation_id:
162
+ return self._conversation_id
163
+
164
+ access_token = self.get_access_token()
165
+ url = f"{self.api_url}/github/chat/threads"
166
+
167
+ headers = self.headers.copy()
168
+ headers["Authorization"] = f"GitHub-Bearer {access_token}"
169
+
170
+ try:
171
+ response = self.session.post(url, headers=headers)
172
+
173
+ if response.status_code == 401:
174
+ # Token might be expired, try refreshing
175
+ self._access_token = None
176
+ access_token = self.get_access_token()
177
+ headers["Authorization"] = f"GitHub-Bearer {access_token}"
178
+ response = self.session.post(url, headers=headers)
179
+
180
+ if response.status_code not in [200, 201]:
181
+ raise exceptions.FailedToGenerateResponseError(f"Failed to create conversation: {response.status_code}")
182
+
183
+ data = response.json()
184
+ self._conversation_id = data.get("thread_id")
185
+
186
+ if not self._conversation_id:
187
+ raise exceptions.FailedToGenerateResponseError("Failed to extract conversation ID from response")
188
+
189
+ return self._conversation_id
190
+
191
+ except requests.exceptions.RequestException as e:
192
+ raise exceptions.FailedToGenerateResponseError(f"Failed to create conversation: {str(e)}")
193
+
194
+ def process_response(self, response, prompt: str):
195
+ """Process streaming response and extract content."""
196
+ full_text = ""
197
+
198
+ for line in response.iter_lines(decode_unicode=True):
199
+ if not line or not line.startswith("data: "):
200
+ continue
201
+
202
+ try:
203
+ # Parse each line (remove "data: " prefix)
204
+ json_str = line[6:]
205
+ if json_str == "[DONE]":
206
+ break
207
+
208
+ data = json.loads(json_str)
209
+
210
+ # Handle different response types
211
+ if data.get("type") == "content":
212
+ token = data.get("body", "")
213
+ full_text += token
214
+ resp = {"text": token}
215
+ yield resp
216
+
217
+ except json.JSONDecodeError:
218
+ continue
219
+
220
+ # Update conversation history only for saving to file if needed
221
+ if full_text:
222
+ self.last_response = {"text": full_text}
223
+ self.conversation.update_chat_history(prompt, full_text)
224
+
225
+ def ask(
226
+ self,
227
+ prompt: str,
228
+ stream: bool = False,
229
+ raw: bool = False,
230
+ optimizer: str = None,
231
+ conversationally: bool = False,
232
+ ) -> Union[Dict[str, Any], Generator]:
233
+ """Send a message to the GitHub Copilot Chat API"""
234
+
235
+ # Apply optimizers if specified
236
+ conversation_prompt = self.conversation.gen_complete_prompt(prompt)
237
+ if optimizer:
238
+ if optimizer in self.__available_optimizers:
239
+ conversation_prompt = getattr(Optimizers, optimizer)(
240
+ conversation_prompt if conversationally else prompt
241
+ )
242
+ else:
243
+ raise Exception(f"Optimizer is not one of {self.__available_optimizers}")
244
+
245
+ # Make sure we have a conversation ID
246
+ try:
247
+ conversation_id = self.create_conversation()
248
+ except exceptions.FailedToGenerateResponseError as e:
249
+ raise exceptions.FailedToGenerateResponseError(f"Failed to create conversation: {e}")
250
+
251
+ access_token = self.get_access_token()
252
+
253
+ url = f"{self.api_url}/github/chat/threads/{conversation_id}/messages"
254
+
255
+ # Update headers for this specific request
256
+ headers = self.headers.copy()
257
+ headers["Authorization"] = f"GitHub-Bearer {access_token}"
258
+
259
+ # Prepare the request payload
260
+ request_data = {
261
+ "content": conversation_prompt,
262
+ "intent": "conversation",
263
+ "references": [],
264
+ "context": [],
265
+ "currentURL": f"https://github.com/copilot/c/{conversation_id}",
266
+ "streaming": True,
267
+ "confirmations": [],
268
+ "customInstructions": [],
269
+ "model": self.model,
270
+ "mode": "immersive"
271
+ }
272
+
273
+ def for_stream():
274
+ try:
275
+ response = self.session.post(
276
+ url,
277
+ json=request_data,
278
+ headers=headers,
279
+ stream=True,
280
+ timeout=self.timeout
281
+ )
282
+
283
+ if response.status_code == 401:
284
+ # Token might be expired, try refreshing
285
+ self._access_token = None
286
+ access_token = self.get_access_token()
287
+ headers["Authorization"] = f"GitHub-Bearer {access_token}"
288
+ response = self.session.post(
289
+ url,
290
+ json=request_data,
291
+ headers=headers,
292
+ stream=True,
293
+ timeout=self.timeout
294
+ )
295
+
296
+ # If still not successful, raise exception
297
+ if response.status_code != 200:
298
+ raise exceptions.FailedToGenerateResponseError(f"Request failed with status code {response.status_code}")
299
+
300
+ # Process the streaming response
301
+ yield from self.process_response(response, prompt)
302
+
303
+ except Exception as e:
304
+ if isinstance(e, requests.exceptions.RequestException):
305
+ if hasattr(e, 'response') and e.response is not None:
306
+ status_code = e.response.status_code
307
+ if status_code == 401:
308
+ raise exceptions.AuthenticationError("Authentication failed. Please check your cookies.")
309
+
310
+ # If anything else fails
311
+ raise exceptions.FailedToGenerateResponseError(f"Request failed: {str(e)}")
312
+
313
+ def for_non_stream():
314
+ response_text = ""
315
+ for response in for_stream():
316
+ if "text" in response:
317
+ response_text += response["text"]
318
+ self.last_response = {"text": response_text}
319
+ return self.last_response
320
+
321
+ return for_stream() if stream else for_non_stream()
322
+
323
+ def chat(
324
+ self,
325
+ prompt: str,
326
+ stream: bool = False,
327
+ optimizer: str = None,
328
+ conversationally: bool = False,
329
+ ) -> Union[str, Generator]:
330
+ """Generate a response to a prompt"""
331
+ def for_stream():
332
+ for response in self.ask(
333
+ prompt, True, optimizer=optimizer, conversationally=conversationally
334
+ ):
335
+ yield self.get_message(response)
336
+
337
+ def for_non_stream():
338
+ return self.get_message(
339
+ self.ask(
340
+ prompt, False, optimizer=optimizer, conversationally=conversationally
341
+ )
342
+ )
343
+
344
+ return for_stream() if stream else for_non_stream()
345
+
346
+ def get_message(self, response: dict) -> str:
347
+ """Extract message text from response"""
348
+ assert isinstance(response, dict), "Response should be of dict data-type only"
349
+ return response.get("text", "")
350
+
351
+ if __name__ == "__main__":
352
+ # Simple test code
353
+ from rich import print
354
+
355
+ try:
356
+ ai = GithubChat()
357
+ response = ai.chat("Python code to count r in strawberry", stream=True)
358
+ for chunk in response:
359
+ print(chunk, end="", flush=True)
360
+ print()
361
+ except Exception as e:
362
+ print(f"An error occurred: {e}")
@@ -170,6 +170,21 @@ class HeckAI(Provider):
170
170
 
171
171
  return for_stream() if stream else for_non_stream()
172
172
 
173
+ @staticmethod
174
+ def fix_encoding(text):
175
+ if isinstance(text, dict) and "text" in text:
176
+ try:
177
+ text["text"] = text["text"].encode("latin1").decode("utf-8")
178
+ return text
179
+ except (UnicodeError, AttributeError) as e:
180
+ return text
181
+ elif isinstance(text, str):
182
+ try:
183
+ return text.encode("latin1").decode("utf-8")
184
+ except (UnicodeError, AttributeError) as e:
185
+ return text
186
+ return text
187
+
173
188
  def chat(
174
189
  self,
175
190
  prompt: str,
@@ -195,6 +210,8 @@ class HeckAI(Provider):
195
210
  if __name__ == "__main__":
196
211
  from rich import print
197
212
  ai = HeckAI(timeout=120)
198
- response = ai.chat("Write a short poem about artificial intelligence", stream=True)
199
- for chunk in response:
200
- print(chunk, end="", flush=True)
213
+ response = ai.chat("Write a short poem about artificial intelligence", stream=False)
214
+ print(response)
215
+ # for chunk in response:
216
+ # chunk = ai.fix_encoding(chunk)
217
+ # print(chunk, end="", flush=True)