webscout 7.9__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/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/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 +17 -9
- webscout/Provider/ExaAI.py +261 -0
- webscout/Provider/ExaChat.py +8 -1
- webscout/Provider/GithubChat.py +2 -1
- webscout/Provider/Netwrck.py +3 -2
- webscout/Provider/OpenGPT.py +199 -0
- webscout/Provider/PI.py +39 -24
- webscout/Provider/Youchat.py +326 -296
- webscout/Provider/__init__.py +10 -0
- webscout/Provider/ai4chat.py +58 -56
- webscout/Provider/akashgpt.py +34 -22
- webscout/Provider/freeaichat.py +1 -1
- 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/version.py +1 -1
- webscout/webscout_search.py +118 -54
- webscout/webscout_search_async.py +109 -45
- {webscout-7.9.dist-info → webscout-8.0.dist-info}/METADATA +2 -2
- {webscout-7.9.dist-info → webscout-8.0.dist-info}/RECORD +38 -24
- {webscout-7.9.dist-info → webscout-8.0.dist-info}/LICENSE.md +0 -0
- {webscout-7.9.dist-info → webscout-8.0.dist-info}/WHEEL +0 -0
- {webscout-7.9.dist-info → webscout-8.0.dist-info}/entry_points.txt +0 -0
- {webscout-7.9.dist-info → webscout-8.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
import re
|
|
4
|
+
from typing import Dict, Optional, Generator, Union, Any
|
|
5
|
+
|
|
6
|
+
from webscout.AIbase import AISearch
|
|
7
|
+
from webscout import exceptions
|
|
8
|
+
from webscout import LitAgent
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Response:
|
|
12
|
+
"""A wrapper class for webpilotai API responses.
|
|
13
|
+
|
|
14
|
+
This class automatically converts response objects to their text representation
|
|
15
|
+
when printed or converted to string.
|
|
16
|
+
|
|
17
|
+
Attributes:
|
|
18
|
+
text (str): The text content of the response
|
|
19
|
+
|
|
20
|
+
Example:
|
|
21
|
+
>>> response = Response("Hello, world!")
|
|
22
|
+
>>> print(response)
|
|
23
|
+
Hello, world!
|
|
24
|
+
>>> str(response)
|
|
25
|
+
'Hello, world!'
|
|
26
|
+
"""
|
|
27
|
+
def __init__(self, text: str):
|
|
28
|
+
self.text = text
|
|
29
|
+
|
|
30
|
+
def __str__(self):
|
|
31
|
+
return self.text
|
|
32
|
+
|
|
33
|
+
def __repr__(self):
|
|
34
|
+
return self.text
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class webpilotai(AISearch):
|
|
38
|
+
"""A class to interact with the webpilotai (WebPilot) AI search API.
|
|
39
|
+
|
|
40
|
+
webpilotai provides a web-based comprehensive search response interface that returns AI-generated
|
|
41
|
+
responses with source references and related questions. It supports both streaming and
|
|
42
|
+
non-streaming responses.
|
|
43
|
+
|
|
44
|
+
Basic Usage:
|
|
45
|
+
>>> from webscout import webpilotai
|
|
46
|
+
>>> ai = webpilotai()
|
|
47
|
+
>>> # Non-streaming example
|
|
48
|
+
>>> response = ai.search("What is Python?")
|
|
49
|
+
>>> print(response)
|
|
50
|
+
Python is a high-level programming language...
|
|
51
|
+
|
|
52
|
+
>>> # Streaming example
|
|
53
|
+
>>> for chunk in ai.search("Tell me about AI", stream=True):
|
|
54
|
+
... print(chunk, end="", flush=True)
|
|
55
|
+
Artificial Intelligence is...
|
|
56
|
+
|
|
57
|
+
>>> # Raw response format
|
|
58
|
+
>>> for chunk in ai.search("Hello", stream=True, raw=True):
|
|
59
|
+
... print(chunk)
|
|
60
|
+
{'text': 'Hello'}
|
|
61
|
+
{'text': ' there!'}
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
timeout (int, optional): Request timeout in seconds. Defaults to 90.
|
|
65
|
+
proxies (dict, optional): Proxy configuration for requests. Defaults to None.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(
|
|
69
|
+
self,
|
|
70
|
+
timeout: int = 90,
|
|
71
|
+
proxies: Optional[dict] = None,
|
|
72
|
+
):
|
|
73
|
+
"""Initialize the webpilotai API client.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
timeout (int, optional): Request timeout in seconds. Defaults to 90.
|
|
77
|
+
proxies (dict, optional): Proxy configuration for requests. Defaults to None.
|
|
78
|
+
|
|
79
|
+
Example:
|
|
80
|
+
>>> ai = webpilotai(timeout=120) # Longer timeout
|
|
81
|
+
>>> ai = webpilotai(proxies={'http': 'http://proxy.com:8080'}) # With proxy
|
|
82
|
+
"""
|
|
83
|
+
self.session = requests.Session()
|
|
84
|
+
self.api_endpoint = "https://api.webpilotai.com/rupee/v1/search"
|
|
85
|
+
self.timeout = timeout
|
|
86
|
+
self.last_response = {}
|
|
87
|
+
|
|
88
|
+
# The 'Bearer null' is part of the API's expected headers
|
|
89
|
+
self.headers = {
|
|
90
|
+
'Accept': 'application/json, text/plain, */*, text/event-stream',
|
|
91
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
92
|
+
'Authorization': 'Bearer null',
|
|
93
|
+
'Origin': 'https://www.webpilot.ai',
|
|
94
|
+
'Referer': 'https://www.webpilot.ai/',
|
|
95
|
+
'User-Agent': LitAgent().random(),
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
self.session.headers.update(self.headers)
|
|
99
|
+
self.proxies = proxies
|
|
100
|
+
|
|
101
|
+
def search(
|
|
102
|
+
self,
|
|
103
|
+
prompt: str,
|
|
104
|
+
stream: bool = False,
|
|
105
|
+
raw: bool = False,
|
|
106
|
+
) -> Union[Response, Generator[Union[Dict[str, str], Response], None, None]]:
|
|
107
|
+
"""Search using the webpilotai API and get AI-generated responses.
|
|
108
|
+
|
|
109
|
+
This method sends a search query to webpilotai and returns the AI-generated response.
|
|
110
|
+
It supports both streaming and non-streaming modes, as well as raw response format.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
prompt (str): The search query or prompt to send to the API.
|
|
114
|
+
stream (bool, optional): If True, yields response chunks as they arrive.
|
|
115
|
+
If False, returns complete response. Defaults to False.
|
|
116
|
+
raw (bool, optional): If True, returns raw response dictionaries with 'text' key.
|
|
117
|
+
If False, returns Response objects that convert to text automatically.
|
|
118
|
+
Defaults to False.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
Union[Response, Generator[Union[Dict[str, str], Response], None, None]]:
|
|
122
|
+
- If stream=False: Returns complete response as Response object
|
|
123
|
+
- If stream=True: Yields response chunks as either Dict or Response objects
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
APIConnectionError: If the API request fails
|
|
127
|
+
|
|
128
|
+
Examples:
|
|
129
|
+
Basic search:
|
|
130
|
+
>>> ai = webpilotai()
|
|
131
|
+
>>> response = ai.search("What is Python?")
|
|
132
|
+
>>> print(response)
|
|
133
|
+
Python is a programming language...
|
|
134
|
+
|
|
135
|
+
Streaming response:
|
|
136
|
+
>>> for chunk in ai.search("Tell me about AI", stream=True):
|
|
137
|
+
... print(chunk, end="")
|
|
138
|
+
Artificial Intelligence...
|
|
139
|
+
|
|
140
|
+
Raw response format:
|
|
141
|
+
>>> for chunk in ai.search("Hello", stream=True, raw=True):
|
|
142
|
+
... print(chunk)
|
|
143
|
+
{'text': 'Hello'}
|
|
144
|
+
{'text': ' there!'}
|
|
145
|
+
"""
|
|
146
|
+
payload = {
|
|
147
|
+
"q": prompt,
|
|
148
|
+
"threadId": "" # Empty for new search
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
def for_stream():
|
|
152
|
+
full_response_content = ""
|
|
153
|
+
current_event_name = None
|
|
154
|
+
current_data_buffer = []
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
with self.session.post(
|
|
158
|
+
self.api_endpoint,
|
|
159
|
+
json=payload,
|
|
160
|
+
stream=True,
|
|
161
|
+
timeout=self.timeout,
|
|
162
|
+
proxies=self.proxies
|
|
163
|
+
) as response:
|
|
164
|
+
if not response.ok:
|
|
165
|
+
raise exceptions.APIConnectionError(
|
|
166
|
+
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# Process the stream line by line
|
|
170
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
171
|
+
if not line: # Empty line indicates end of an event
|
|
172
|
+
if current_data_buffer:
|
|
173
|
+
# Process the completed event
|
|
174
|
+
full_data = "\n".join(current_data_buffer)
|
|
175
|
+
if current_event_name == "message":
|
|
176
|
+
try:
|
|
177
|
+
data_payload = json.loads(full_data)
|
|
178
|
+
# Check structure based on the API response
|
|
179
|
+
if data_payload.get('type') == 'data':
|
|
180
|
+
content_chunk = data_payload.get('data', {}).get('content', "")
|
|
181
|
+
if content_chunk:
|
|
182
|
+
full_response_content += content_chunk
|
|
183
|
+
|
|
184
|
+
# Yield the new content chunk
|
|
185
|
+
if raw:
|
|
186
|
+
yield {"text": content_chunk}
|
|
187
|
+
else:
|
|
188
|
+
yield Response(content_chunk)
|
|
189
|
+
except json.JSONDecodeError:
|
|
190
|
+
pass
|
|
191
|
+
except Exception as e:
|
|
192
|
+
# Handle exceptions gracefully in stream processing
|
|
193
|
+
pass
|
|
194
|
+
|
|
195
|
+
# Reset for the next event
|
|
196
|
+
current_event_name = None
|
|
197
|
+
current_data_buffer = []
|
|
198
|
+
continue
|
|
199
|
+
|
|
200
|
+
# Parse SSE fields
|
|
201
|
+
if line.startswith('event:'):
|
|
202
|
+
current_event_name = line[len('event:'):].strip()
|
|
203
|
+
elif line.startswith('data:'):
|
|
204
|
+
data_part = line[len('data:'):]
|
|
205
|
+
# Remove leading space if present (common in SSE)
|
|
206
|
+
if data_part.startswith(' '):
|
|
207
|
+
data_part = data_part[1:]
|
|
208
|
+
current_data_buffer.append(data_part)
|
|
209
|
+
|
|
210
|
+
# Process any remaining data in buffer if stream ended without blank line
|
|
211
|
+
if current_data_buffer and current_event_name == "message":
|
|
212
|
+
try:
|
|
213
|
+
full_data = "\n".join(current_data_buffer)
|
|
214
|
+
data_payload = json.loads(full_data)
|
|
215
|
+
if data_payload.get('type') == 'data':
|
|
216
|
+
content_chunk = data_payload.get('data', {}).get('content', "")
|
|
217
|
+
if content_chunk and len(content_chunk) > len(full_response_content):
|
|
218
|
+
delta = content_chunk[len(full_response_content):]
|
|
219
|
+
full_response_content += delta
|
|
220
|
+
|
|
221
|
+
if raw:
|
|
222
|
+
yield {"text": delta}
|
|
223
|
+
else:
|
|
224
|
+
yield Response(delta)
|
|
225
|
+
except (json.JSONDecodeError, Exception):
|
|
226
|
+
pass
|
|
227
|
+
|
|
228
|
+
except requests.exceptions.Timeout:
|
|
229
|
+
raise exceptions.APIConnectionError("Request timed out")
|
|
230
|
+
except requests.exceptions.RequestException as e:
|
|
231
|
+
raise exceptions.APIConnectionError(f"Request failed: {e}")
|
|
232
|
+
|
|
233
|
+
def for_non_stream():
|
|
234
|
+
full_response = ""
|
|
235
|
+
for chunk in for_stream():
|
|
236
|
+
if raw:
|
|
237
|
+
yield chunk
|
|
238
|
+
else:
|
|
239
|
+
full_response += str(chunk)
|
|
240
|
+
|
|
241
|
+
if not raw:
|
|
242
|
+
# Format the response for better readability
|
|
243
|
+
formatted_response = self.format_response(full_response)
|
|
244
|
+
self.last_response = Response(formatted_response)
|
|
245
|
+
return self.last_response
|
|
246
|
+
|
|
247
|
+
return for_stream() if stream else for_non_stream()
|
|
248
|
+
|
|
249
|
+
@staticmethod
|
|
250
|
+
def format_response(text: str) -> str:
|
|
251
|
+
"""Format the response text for better readability.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
text (str): The raw response text
|
|
255
|
+
|
|
256
|
+
Returns:
|
|
257
|
+
str: Formatted text with improved structure
|
|
258
|
+
"""
|
|
259
|
+
# Clean up formatting
|
|
260
|
+
# Remove excessive newlines
|
|
261
|
+
clean_text = re.sub(r'\n{3,}', '\n\n', text)
|
|
262
|
+
|
|
263
|
+
# Ensure consistent spacing around sections
|
|
264
|
+
clean_text = re.sub(r'([.!?])\s*\n\s*([A-Z])', r'\1\n\n\2', clean_text)
|
|
265
|
+
|
|
266
|
+
# Clean up any leftover HTML or markdown artifacts
|
|
267
|
+
clean_text = re.sub(r'<[^>]*>', '', clean_text)
|
|
268
|
+
|
|
269
|
+
# Remove trailing whitespace on each line
|
|
270
|
+
clean_text = '\n'.join(line.rstrip() for line in clean_text.split('\n'))
|
|
271
|
+
|
|
272
|
+
return clean_text.strip()
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
if __name__ == "__main__":
|
|
276
|
+
from rich import print
|
|
277
|
+
|
|
278
|
+
ai = webpilotai()
|
|
279
|
+
response = ai.search(input(">>> "), stream=True, raw=False)
|
|
280
|
+
for chunk in response:
|
|
281
|
+
print(chunk, end="", flush=True)
|