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.
- webscout/Provider/C4ai.py +414 -0
- webscout/Provider/Cloudflare.py +18 -21
- webscout/Provider/DeepSeek.py +3 -32
- webscout/Provider/Deepinfra.py +30 -21
- webscout/Provider/GithubChat.py +362 -0
- webscout/Provider/HeckAI.py +20 -3
- webscout/Provider/HuggingFaceChat.py +462 -0
- webscout/Provider/Marcus.py +7 -50
- webscout/Provider/Netwrck.py +6 -53
- webscout/Provider/Phind.py +29 -3
- webscout/Provider/TTI/aiarta/__init__.py +2 -0
- webscout/Provider/TTI/aiarta/async_aiarta.py +482 -0
- webscout/Provider/TTI/aiarta/sync_aiarta.py +409 -0
- webscout/Provider/Venice.py +200 -200
- webscout/Provider/Youchat.py +1 -1
- webscout/Provider/__init__.py +13 -2
- webscout/Provider/akashgpt.py +8 -5
- webscout/Provider/copilot.py +416 -0
- webscout/Provider/flowith.py +181 -0
- webscout/Provider/granite.py +17 -53
- webscout/Provider/llamatutor.py +6 -46
- webscout/Provider/llmchat.py +7 -46
- webscout/Provider/multichat.py +29 -91
- webscout/exceptions.py +19 -9
- webscout/update_checker.py +55 -93
- webscout/version.py +1 -1
- webscout-7.5.dist-info/LICENSE.md +146 -0
- {webscout-7.4.dist-info → webscout-7.5.dist-info}/METADATA +5 -126
- {webscout-7.4.dist-info → webscout-7.5.dist-info}/RECORD +32 -33
- webscout/Local/__init__.py +0 -10
- webscout/Local/_version.py +0 -3
- webscout/Local/formats.py +0 -747
- webscout/Local/model.py +0 -1368
- webscout/Local/samplers.py +0 -125
- webscout/Local/thread.py +0 -539
- webscout/Local/ui.py +0 -401
- webscout/Local/utils.py +0 -388
- webscout/Provider/dgaf.py +0 -214
- webscout-7.4.dist-info/LICENSE.md +0 -211
- {webscout-7.4.dist-info → webscout-7.5.dist-info}/WHEEL +0 -0
- {webscout-7.4.dist-info → webscout-7.5.dist-info}/entry_points.txt +0 -0
- {webscout-7.4.dist-info → webscout-7.5.dist-info}/top_level.txt +0 -0
webscout/Provider/multichat.py
CHANGED
|
@@ -6,7 +6,6 @@ from datetime import datetime
|
|
|
6
6
|
from webscout.AIutel import Optimizers, Conversation, AwesomePrompts
|
|
7
7
|
from webscout.AIbase import Provider
|
|
8
8
|
from webscout import exceptions
|
|
9
|
-
from webscout.Litlogger import Logger, LogFormat
|
|
10
9
|
from webscout.litagent import LitAgent
|
|
11
10
|
|
|
12
11
|
# Model configurations
|
|
@@ -21,14 +20,18 @@ MODEL_CONFIGS = {
|
|
|
21
20
|
},
|
|
22
21
|
"cohere": {
|
|
23
22
|
"endpoint": "https://www.multichatai.com/api/chat/cohere",
|
|
24
|
-
"models": {
|
|
23
|
+
"models": {
|
|
24
|
+
"command-r": {"contextLength": 128000},
|
|
25
|
+
"command": {"contextLength": 4096},
|
|
26
|
+
},
|
|
25
27
|
},
|
|
26
28
|
"google": {
|
|
27
29
|
"endpoint": "https://www.multichatai.com/api/chat/google",
|
|
28
30
|
"models": {
|
|
29
31
|
"gemini-1.5-flash-002": {"contextLength": 1048576},
|
|
30
32
|
"gemma2-9b-it": {"contextLength": 8192},
|
|
31
|
-
|
|
33
|
+
"gemini-2.0-flash": {"contextLength": 128000},
|
|
34
|
+
},
|
|
32
35
|
"message_format": "parts",
|
|
33
36
|
},
|
|
34
37
|
"deepinfra": {
|
|
@@ -38,6 +41,9 @@ MODEL_CONFIGS = {
|
|
|
38
41
|
"Gryphe/MythoMax-L2-13b": {"contextLength": 8192},
|
|
39
42
|
"nvidia/Llama-3.1-Nemotron-70B-Instruct": {"contextLength": 131072},
|
|
40
43
|
"deepseek-ai/DeepSeek-V3": {"contextLength": 32000},
|
|
44
|
+
"meta-llama/Meta-Llama-3.1-405B-Instruct": {"contextLength": 131072},
|
|
45
|
+
"NousResearch/Hermes-3-Llama-3.1-405B": {"contextLength": 131072},
|
|
46
|
+
"gemma-2-27b-it": {"contextLength": 8192},
|
|
41
47
|
},
|
|
42
48
|
},
|
|
43
49
|
"mistral": {
|
|
@@ -49,6 +55,14 @@ MODEL_CONFIGS = {
|
|
|
49
55
|
"open-mixtral-8x7b": {"contextLength": 8000},
|
|
50
56
|
},
|
|
51
57
|
},
|
|
58
|
+
"alibaba": {
|
|
59
|
+
"endpoint": "https://www.multichatai.com/api/chat/alibaba",
|
|
60
|
+
"models": {
|
|
61
|
+
"Qwen/Qwen2.5-72B-Instruct": {"contextLength": 32768},
|
|
62
|
+
"Qwen/Qwen2.5-Coder-32B-Instruct": {"contextLength": 32768},
|
|
63
|
+
"Qwen/QwQ-32B-Preview": {"contextLength": 32768},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
class MultiChatAI(Provider):
|
|
@@ -68,20 +82,9 @@ class MultiChatAI(Provider):
|
|
|
68
82
|
temperature: float = 0.5,
|
|
69
83
|
presence_penalty: int = 0,
|
|
70
84
|
frequency_penalty: int = 0,
|
|
71
|
-
top_p: float = 1
|
|
72
|
-
logging: bool = False,
|
|
85
|
+
top_p: float = 1
|
|
73
86
|
):
|
|
74
|
-
"""Initializes the MultiChatAI API client
|
|
75
|
-
# Initialize logger first
|
|
76
|
-
self.logger = Logger(
|
|
77
|
-
name="MultiChatAI",
|
|
78
|
-
format=LogFormat.MODERN_EMOJI,
|
|
79
|
-
|
|
80
|
-
) if logging else None
|
|
81
|
-
|
|
82
|
-
if self.logger:
|
|
83
|
-
self.logger.debug("Initializing MultiChatAI")
|
|
84
|
-
|
|
87
|
+
"""Initializes the MultiChatAI API client."""
|
|
85
88
|
self.session = requests.Session()
|
|
86
89
|
self.is_conversation = is_conversation
|
|
87
90
|
self.max_tokens_to_sample = max_tokens
|
|
@@ -106,9 +109,6 @@ class MultiChatAI(Provider):
|
|
|
106
109
|
"user-agent": self.agent.random(),
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
if self.logger:
|
|
110
|
-
self.logger.debug(f"Setting up session with headers: {self.headers}")
|
|
111
|
-
|
|
112
112
|
self.session.headers.update(self.headers)
|
|
113
113
|
self.session.proxies = proxies
|
|
114
114
|
self.session.cookies.update({"session": uuid.uuid4().hex})
|
|
@@ -131,24 +131,17 @@ class MultiChatAI(Provider):
|
|
|
131
131
|
)
|
|
132
132
|
self.conversation.history_offset = history_offset
|
|
133
133
|
|
|
134
|
-
# Get provider after logger initialization
|
|
135
134
|
self.provider = self._get_provider_from_model(self.model)
|
|
136
135
|
self.model_name = self.model
|
|
137
136
|
|
|
138
|
-
if self.logger:
|
|
139
|
-
self.logger.info(f"MultiChatAI initialized with model: {self.model}")
|
|
140
|
-
|
|
141
137
|
def _get_endpoint(self) -> str:
|
|
142
138
|
"""Get the API endpoint for the current provider."""
|
|
143
|
-
|
|
144
|
-
if self.logger:
|
|
145
|
-
self.logger.debug(f"Using endpoint: {endpoint}")
|
|
146
|
-
return endpoint
|
|
139
|
+
return MODEL_CONFIGS[self.provider]["endpoint"]
|
|
147
140
|
|
|
148
141
|
def _get_chat_settings(self) -> Dict[str, Any]:
|
|
149
142
|
"""Get chat settings for the current model."""
|
|
150
143
|
base_settings = MODEL_CONFIGS[self.provider]["models"][self.model_name]
|
|
151
|
-
|
|
144
|
+
return {
|
|
152
145
|
"model": self.model,
|
|
153
146
|
"prompt": self.system_prompt,
|
|
154
147
|
"temperature": self.temperature,
|
|
@@ -157,45 +150,30 @@ class MultiChatAI(Provider):
|
|
|
157
150
|
"includeWorkspaceInstructions": True,
|
|
158
151
|
"embeddingsProvider": "openai"
|
|
159
152
|
}
|
|
160
|
-
if self.logger:
|
|
161
|
-
self.logger.debug(f"Chat settings: {settings}")
|
|
162
|
-
return settings
|
|
163
153
|
|
|
164
154
|
def _get_system_message(self) -> str:
|
|
165
155
|
"""Generate system message with current date."""
|
|
166
156
|
current_date = datetime.now().strftime("%d/%m/%Y")
|
|
167
|
-
|
|
168
|
-
if self.logger:
|
|
169
|
-
self.logger.debug(f"System message: {message}")
|
|
170
|
-
return message
|
|
157
|
+
return f"Today is {current_date}.\n\nUser Instructions:\n{self.system_prompt}"
|
|
171
158
|
|
|
172
159
|
def _build_messages(self, conversation_prompt: str) -> list:
|
|
173
160
|
"""Build messages array based on provider type."""
|
|
174
161
|
if self.provider == "google":
|
|
175
|
-
|
|
162
|
+
return [
|
|
176
163
|
{"role": "user", "parts": self._get_system_message()},
|
|
177
164
|
{"role": "model", "parts": "I will follow your instructions."},
|
|
178
165
|
{"role": "user", "parts": conversation_prompt}
|
|
179
166
|
]
|
|
180
167
|
else:
|
|
181
|
-
|
|
168
|
+
return [
|
|
182
169
|
{"role": "system", "content": self._get_system_message()},
|
|
183
170
|
{"role": "user", "content": conversation_prompt}
|
|
184
171
|
]
|
|
185
|
-
|
|
186
|
-
if self.logger:
|
|
187
|
-
self.logger.debug(f"Built messages: {messages}")
|
|
188
|
-
return messages
|
|
189
172
|
|
|
190
173
|
def _get_provider_from_model(self, model: str) -> str:
|
|
191
174
|
"""Determine the provider based on the model name."""
|
|
192
|
-
if self.logger:
|
|
193
|
-
self.logger.debug(f"Getting provider for model: {model}")
|
|
194
|
-
|
|
195
175
|
for provider, config in MODEL_CONFIGS.items():
|
|
196
176
|
if model in config["models"]:
|
|
197
|
-
if self.logger:
|
|
198
|
-
self.logger.info(f"Found provider: {provider} for model: {model}")
|
|
199
177
|
return provider
|
|
200
178
|
|
|
201
179
|
available_models = []
|
|
@@ -204,16 +182,10 @@ class MultiChatAI(Provider):
|
|
|
204
182
|
available_models.append(f"{provider}/{model_name}")
|
|
205
183
|
|
|
206
184
|
error_msg = f"Invalid model: {model}\nAvailable models: {', '.join(available_models)}"
|
|
207
|
-
if self.logger:
|
|
208
|
-
self.logger.error(error_msg)
|
|
209
185
|
raise ValueError(error_msg)
|
|
210
186
|
|
|
211
187
|
def _make_request(self, payload: Dict[str, Any]) -> requests.Response:
|
|
212
|
-
"""Make the API request with proper error handling
|
|
213
|
-
if self.logger:
|
|
214
|
-
self.logger.debug(f"Making request to endpoint: {self._get_endpoint()}")
|
|
215
|
-
self.logger.debug(f"Request payload: {json.dumps(payload, indent=2)}")
|
|
216
|
-
|
|
188
|
+
"""Make the API request with proper error handling."""
|
|
217
189
|
try:
|
|
218
190
|
response = self.session.post(
|
|
219
191
|
self._get_endpoint(),
|
|
@@ -222,15 +194,8 @@ class MultiChatAI(Provider):
|
|
|
222
194
|
timeout=self.timeout,
|
|
223
195
|
)
|
|
224
196
|
response.raise_for_status()
|
|
225
|
-
|
|
226
|
-
if self.logger:
|
|
227
|
-
self.logger.info(f"Request successful: {response.status_code}")
|
|
228
|
-
self.logger.debug(f"Response content: {response.text[:200]}...")
|
|
229
|
-
|
|
230
197
|
return response
|
|
231
198
|
except requests.exceptions.RequestException as e:
|
|
232
|
-
if self.logger:
|
|
233
|
-
self.logger.error(f"Request failed: {str(e)}")
|
|
234
199
|
raise exceptions.FailedToGenerateResponseError(f"API request failed: {e}") from e
|
|
235
200
|
|
|
236
201
|
def ask(
|
|
@@ -241,21 +206,14 @@ class MultiChatAI(Provider):
|
|
|
241
206
|
conversationally: bool = False,
|
|
242
207
|
) -> Dict[str, Any]:
|
|
243
208
|
"""Sends a prompt to the MultiChatAI API and returns the response."""
|
|
244
|
-
if self.logger:
|
|
245
|
-
self.logger.debug(f"ask() called with prompt: {prompt}")
|
|
246
|
-
|
|
247
209
|
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
248
210
|
if optimizer:
|
|
249
211
|
if optimizer in self.__available_optimizers:
|
|
250
|
-
if self.logger:
|
|
251
|
-
self.logger.info(f"Applying optimizer: {optimizer}")
|
|
252
212
|
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
253
213
|
conversation_prompt if conversationally else prompt
|
|
254
214
|
)
|
|
255
215
|
else:
|
|
256
216
|
error_msg = f"Optimizer is not one of {self.__available_optimizers}"
|
|
257
|
-
if self.logger:
|
|
258
|
-
self.logger.error(error_msg)
|
|
259
217
|
raise exceptions.FailedToGenerateResponseError(error_msg)
|
|
260
218
|
|
|
261
219
|
payload = {
|
|
@@ -269,15 +227,8 @@ class MultiChatAI(Provider):
|
|
|
269
227
|
full_response = response.text.strip()
|
|
270
228
|
self.last_response = {"text": full_response}
|
|
271
229
|
self.conversation.update_chat_history(prompt, full_response)
|
|
272
|
-
|
|
273
|
-
if self.logger:
|
|
274
|
-
self.logger.info("Successfully processed response")
|
|
275
|
-
self.logger.debug(f"Final response: {full_response[:200]}...")
|
|
276
|
-
|
|
277
230
|
return self.last_response
|
|
278
231
|
except json.JSONDecodeError as e:
|
|
279
|
-
if self.logger:
|
|
280
|
-
self.logger.error(f"Failed to decode JSON response: {e}")
|
|
281
232
|
raise exceptions.FailedToGenerateResponseError(f"Invalid JSON response: {e}") from e
|
|
282
233
|
|
|
283
234
|
def chat(
|
|
@@ -286,17 +237,10 @@ class MultiChatAI(Provider):
|
|
|
286
237
|
optimizer: str = None,
|
|
287
238
|
conversationally: bool = False,
|
|
288
239
|
) -> str:
|
|
289
|
-
"""Generate response
|
|
290
|
-
if self.logger:
|
|
291
|
-
self.logger.debug(f"chat() called with prompt: {prompt}")
|
|
292
|
-
|
|
240
|
+
"""Generate response."""
|
|
293
241
|
response = self.ask(
|
|
294
242
|
prompt, optimizer=optimizer, conversationally=conversationally
|
|
295
243
|
)
|
|
296
|
-
|
|
297
|
-
if self.logger:
|
|
298
|
-
self.logger.info("Chat response generated successfully")
|
|
299
|
-
|
|
300
244
|
return self.get_message(response)
|
|
301
245
|
|
|
302
246
|
def get_message(self, response: Dict[str, Any] | str) -> str:
|
|
@@ -309,21 +253,15 @@ class MultiChatAI(Provider):
|
|
|
309
253
|
Returns:
|
|
310
254
|
str: The extracted message text
|
|
311
255
|
"""
|
|
312
|
-
if self.logger:
|
|
313
|
-
self.logger.debug(f"Extracting message from response type: {type(response)}")
|
|
314
|
-
|
|
315
256
|
if isinstance(response, dict):
|
|
316
|
-
|
|
317
|
-
if self.logger:
|
|
318
|
-
self.logger.debug(f"Extracted message from dict: {message[:200]}...")
|
|
319
|
-
return message
|
|
257
|
+
return response.get("text", "")
|
|
320
258
|
return str(response)
|
|
321
259
|
|
|
322
260
|
if __name__ == "__main__":
|
|
323
261
|
from rich import print
|
|
324
262
|
|
|
325
|
-
# Example usage
|
|
326
|
-
ai = MultiChatAI(model="
|
|
263
|
+
# Example usage
|
|
264
|
+
ai = MultiChatAI(model="Qwen/QwQ-32B-Preview")
|
|
327
265
|
try:
|
|
328
266
|
response = ai.chat("What is quantum computing?")
|
|
329
267
|
print(response)
|
webscout/exceptions.py
CHANGED
|
@@ -11,7 +11,7 @@ class WebscoutE(Exception):
|
|
|
11
11
|
pass
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
class APIConnectionError(
|
|
14
|
+
class APIConnectionError(WebscoutE):
|
|
15
15
|
"""
|
|
16
16
|
Exception raised when there are issues connecting to an API.
|
|
17
17
|
|
|
@@ -21,7 +21,17 @@ class APIConnectionError(Exception):
|
|
|
21
21
|
pass
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
class
|
|
24
|
+
class AuthenticationError(WebscoutE):
|
|
25
|
+
"""
|
|
26
|
+
Exception raised when authentication to a service fails.
|
|
27
|
+
|
|
28
|
+
This exception is raised when the provided credentials are invalid or expired.
|
|
29
|
+
It indicates that the application cannot authenticate with the service.
|
|
30
|
+
"""
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class RatelimitE(WebscoutE):
|
|
25
35
|
"""
|
|
26
36
|
Exception raised when an API rate limit is exceeded.
|
|
27
37
|
|
|
@@ -31,7 +41,7 @@ class RatelimitE(Exception):
|
|
|
31
41
|
pass
|
|
32
42
|
|
|
33
43
|
|
|
34
|
-
class ConversationLimitException(
|
|
44
|
+
class ConversationLimitException(WebscoutE):
|
|
35
45
|
"""
|
|
36
46
|
Exception raised when a conversation limit is exceeded.
|
|
37
47
|
|
|
@@ -41,7 +51,7 @@ class ConversationLimitException(Exception):
|
|
|
41
51
|
pass
|
|
42
52
|
|
|
43
53
|
|
|
44
|
-
class TimeoutE(
|
|
54
|
+
class TimeoutE(WebscoutE):
|
|
45
55
|
"""
|
|
46
56
|
Exception raised when a request to an API times out.
|
|
47
57
|
|
|
@@ -51,7 +61,7 @@ class TimeoutE(Exception):
|
|
|
51
61
|
pass
|
|
52
62
|
|
|
53
63
|
|
|
54
|
-
class FailedToGenerateResponseError(
|
|
64
|
+
class FailedToGenerateResponseError(WebscoutE):
|
|
55
65
|
"""
|
|
56
66
|
Exception raised when a provider fails to generate a response.
|
|
57
67
|
|
|
@@ -61,7 +71,7 @@ class FailedToGenerateResponseError(Exception):
|
|
|
61
71
|
pass
|
|
62
72
|
|
|
63
73
|
|
|
64
|
-
class AllProvidersFailure(
|
|
74
|
+
class AllProvidersFailure(WebscoutE):
|
|
65
75
|
"""
|
|
66
76
|
Exception raised when all providers fail to generate a response.
|
|
67
77
|
|
|
@@ -71,7 +81,7 @@ class AllProvidersFailure(Exception):
|
|
|
71
81
|
pass
|
|
72
82
|
|
|
73
83
|
|
|
74
|
-
class FacebookInvalidCredentialsException(
|
|
84
|
+
class FacebookInvalidCredentialsException(WebscoutE):
|
|
75
85
|
"""
|
|
76
86
|
Exception raised when Facebook credentials are invalid.
|
|
77
87
|
|
|
@@ -81,7 +91,7 @@ class FacebookInvalidCredentialsException(Exception):
|
|
|
81
91
|
pass
|
|
82
92
|
|
|
83
93
|
|
|
84
|
-
class FacebookRegionBlocked(
|
|
94
|
+
class FacebookRegionBlocked(WebscoutE):
|
|
85
95
|
"""
|
|
86
96
|
Exception raised when Facebook access is blocked due to region restrictions.
|
|
87
97
|
|
|
@@ -91,7 +101,7 @@ class FacebookRegionBlocked(Exception):
|
|
|
91
101
|
pass
|
|
92
102
|
|
|
93
103
|
|
|
94
|
-
class ModelUnloadedException(
|
|
104
|
+
class ModelUnloadedException(WebscoutE):
|
|
95
105
|
"""
|
|
96
106
|
Exception raised when a model is unloaded.
|
|
97
107
|
|
webscout/update_checker.py
CHANGED
|
@@ -1,43 +1,28 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
2
|
+
Webscout Update Checker
|
|
3
3
|
>>> from webscout import check_for_updates
|
|
4
|
-
>>> check_for_updates()
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
>>> result = check_for_updates()
|
|
5
|
+
>>> print(result)
|
|
6
|
+
'New Webscout version available: 2.0.0 - Update with: pip install --upgrade webscout'
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
import subprocess
|
|
10
9
|
import sys
|
|
11
10
|
import os
|
|
12
|
-
from typing import Optional
|
|
11
|
+
from typing import Optional, Tuple, Dict, Any, Literal, Union
|
|
13
12
|
|
|
14
13
|
import requests
|
|
15
14
|
from packaging import version
|
|
16
|
-
import re
|
|
17
|
-
|
|
18
|
-
from webscout.Litlogger import Logger
|
|
19
15
|
from importlib.metadata import version as get_package_version
|
|
20
16
|
from importlib.metadata import PackageNotFoundError
|
|
21
|
-
from importlib.metadata import metadata as get_package_metadata
|
|
22
|
-
|
|
23
|
-
# Setting up that clean logger format, no cap! 💯
|
|
24
|
-
CUSTOM_FORMAT = """{message}"""
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
format=CUSTOM_FORMAT,
|
|
29
|
-
)
|
|
18
|
+
# Version comparison result type
|
|
19
|
+
VersionCompareResult = Literal[-1, 0, 1]
|
|
30
20
|
|
|
31
21
|
def get_installed_version() -> Optional[str]:
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
What this function's all about:
|
|
35
|
-
- Checking your setup real quick 💨
|
|
36
|
-
- Getting them version deets 📱
|
|
37
|
-
- Handling any problems like a boss 💪
|
|
22
|
+
"""Get the currently installed version of webscout.
|
|
38
23
|
|
|
39
24
|
Returns:
|
|
40
|
-
Optional[str]:
|
|
25
|
+
Optional[str]: The installed version string or None if not found
|
|
41
26
|
|
|
42
27
|
Examples:
|
|
43
28
|
>>> version = get_installed_version()
|
|
@@ -48,19 +33,14 @@ def get_installed_version() -> Optional[str]:
|
|
|
48
33
|
return get_package_version('webscout')
|
|
49
34
|
except PackageNotFoundError:
|
|
50
35
|
return None
|
|
51
|
-
except Exception
|
|
36
|
+
except Exception:
|
|
52
37
|
return None
|
|
53
38
|
|
|
54
39
|
def get_pypi_version() -> Optional[str]:
|
|
55
|
-
"""
|
|
56
|
-
|
|
57
|
-
This function's vibe:
|
|
58
|
-
- Hitting up PyPI for the latest drop 🌐
|
|
59
|
-
- Keeping it smooth with timeout handling ⚡
|
|
60
|
-
- Making sure we get good data fr fr 💯
|
|
40
|
+
"""Get the latest version available on PyPI.
|
|
61
41
|
|
|
62
42
|
Returns:
|
|
63
|
-
Optional[str]:
|
|
43
|
+
Optional[str]: The latest version string or None if retrieval failed
|
|
64
44
|
|
|
65
45
|
Examples:
|
|
66
46
|
>>> latest = get_pypi_version()
|
|
@@ -73,24 +53,20 @@ def get_pypi_version() -> Optional[str]:
|
|
|
73
53
|
timeout=10
|
|
74
54
|
)
|
|
75
55
|
response.raise_for_status()
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
pass
|
|
81
|
-
except Exception as e:
|
|
82
|
-
pass
|
|
83
|
-
return None
|
|
56
|
+
data: Dict[str, Any] = response.json()
|
|
57
|
+
return data['info']['version']
|
|
58
|
+
except (requests.RequestException, KeyError, ValueError, Exception):
|
|
59
|
+
return None
|
|
84
60
|
|
|
85
|
-
def version_compare(v1: str, v2: str) ->
|
|
86
|
-
"""
|
|
61
|
+
def version_compare(v1: str, v2: str) -> VersionCompareResult:
|
|
62
|
+
"""Compare two version strings.
|
|
87
63
|
|
|
88
64
|
Args:
|
|
89
|
-
v1: First version
|
|
90
|
-
v2: Second version to compare with
|
|
65
|
+
v1: First version string
|
|
66
|
+
v2: Second version string to compare with
|
|
91
67
|
|
|
92
68
|
Returns:
|
|
93
|
-
|
|
69
|
+
VersionCompareResult: -1 if v1 < v2, 1 if v1 > v2, 0 if equal
|
|
94
70
|
|
|
95
71
|
Examples:
|
|
96
72
|
>>> version_compare('1.0.0', '2.0.0')
|
|
@@ -104,71 +80,57 @@ def version_compare(v1: str, v2: str) -> int:
|
|
|
104
80
|
if version1 > version2:
|
|
105
81
|
return 1
|
|
106
82
|
return 0
|
|
107
|
-
except version.InvalidVersion
|
|
108
|
-
pass
|
|
109
|
-
return 0
|
|
110
|
-
except Exception as e:
|
|
111
|
-
pass
|
|
83
|
+
except (version.InvalidVersion, Exception):
|
|
112
84
|
return 0
|
|
113
85
|
|
|
114
|
-
def
|
|
115
|
-
"""
|
|
116
|
-
|
|
117
|
-
What we doing here:
|
|
118
|
-
- Comparing your version with the latest drop 🔄
|
|
119
|
-
- Letting you know if you need to level up ⬆️
|
|
120
|
-
- Keeping you in the loop with style 💯
|
|
86
|
+
def get_update_message(installed: str, latest: str) -> Optional[str]:
|
|
87
|
+
"""Generate appropriate update message based on version comparison.
|
|
121
88
|
|
|
122
89
|
Args:
|
|
123
|
-
installed:
|
|
124
|
-
latest:
|
|
90
|
+
installed: Currently installed version
|
|
91
|
+
latest: Latest available version
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
Optional[str]: Update message if needed, None if already on latest version
|
|
125
95
|
|
|
126
96
|
Examples:
|
|
127
|
-
>>>
|
|
128
|
-
'
|
|
97
|
+
>>> get_update_message('1.0.0', '2.0.0')
|
|
98
|
+
'New Webscout version available: 2.0.0 - Update with: pip install --upgrade webscout'
|
|
129
99
|
"""
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def check_for_updates() -> None:
|
|
144
|
-
"""Time to check if you're running the latest! 🚀
|
|
145
|
-
|
|
146
|
-
What we doing:
|
|
147
|
-
- Peeking at your current setup 📱
|
|
148
|
-
- Checking what's new out there 🌐
|
|
149
|
-
- Keeping you updated fr fr ⚡
|
|
100
|
+
comparison_result = version_compare(installed, latest)
|
|
101
|
+
if comparison_result < 0:
|
|
102
|
+
return f"New Webscout version available: {latest} - Update with: pip install --upgrade webscout"
|
|
103
|
+
elif comparison_result > 0:
|
|
104
|
+
return f"You're running a development version ({installed}) ahead of latest release ({latest})"
|
|
105
|
+
return None # Already on the latest version
|
|
106
|
+
|
|
107
|
+
def check_for_updates() -> Optional[str]:
|
|
108
|
+
"""Check if a newer version of Webscout is available.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
Optional[str]: Update message if newer version exists, None otherwise
|
|
150
112
|
|
|
151
113
|
Examples:
|
|
152
|
-
>>> check_for_updates()
|
|
153
|
-
|
|
114
|
+
>>> result = check_for_updates()
|
|
115
|
+
>>> print(result)
|
|
116
|
+
'New Webscout version available: 2.0.0 - Update with: pip install --upgrade webscout'
|
|
154
117
|
"""
|
|
155
118
|
installed_version = get_installed_version()
|
|
156
|
-
latest_version = get_pypi_version()
|
|
157
|
-
|
|
158
119
|
if not installed_version:
|
|
159
|
-
|
|
160
|
-
return
|
|
120
|
+
return None
|
|
161
121
|
|
|
122
|
+
latest_version = get_pypi_version()
|
|
162
123
|
if not latest_version:
|
|
163
|
-
|
|
164
|
-
return
|
|
124
|
+
return None
|
|
165
125
|
|
|
166
|
-
|
|
126
|
+
return get_update_message(installed_version, latest_version)
|
|
167
127
|
|
|
168
128
|
if __name__ == "__main__":
|
|
169
129
|
try:
|
|
170
|
-
check_for_updates()
|
|
130
|
+
update_message = check_for_updates()
|
|
131
|
+
if update_message:
|
|
132
|
+
print(update_message)
|
|
171
133
|
except KeyboardInterrupt:
|
|
172
|
-
|
|
134
|
+
print("Update check canceled")
|
|
173
135
|
except Exception as e:
|
|
174
|
-
|
|
136
|
+
print(f"Update check failed: {str(e)}")
|
webscout/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "7.
|
|
1
|
+
__version__ = "7.5"
|
|
2
2
|
__prog__ = "webscout"
|