webscout 8.3.5__py3-none-any.whl → 8.3.6__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 +12 -6
- webscout/DWEBS.py +66 -57
- webscout/Provider/{UNFINISHED → AISEARCH}/PERPLEXED_search.py +34 -74
- webscout/Provider/AISEARCH/__init__.py +1 -1
- webscout/Provider/Deepinfra.py +6 -0
- webscout/Provider/Flowith.py +6 -1
- webscout/Provider/GithubChat.py +1 -0
- webscout/Provider/GptOss.py +207 -0
- webscout/Provider/Kimi.py +445 -0
- webscout/Provider/Netwrck.py +3 -6
- webscout/Provider/OPENAI/README.md +2 -1
- webscout/Provider/OPENAI/TogetherAI.py +50 -55
- webscout/Provider/OPENAI/__init__.py +4 -2
- webscout/Provider/OPENAI/copilot.py +20 -4
- webscout/Provider/OPENAI/deepinfra.py +6 -0
- webscout/Provider/OPENAI/e2b.py +60 -8
- webscout/Provider/OPENAI/flowith.py +4 -3
- webscout/Provider/OPENAI/generate_api_key.py +48 -0
- webscout/Provider/OPENAI/gptoss.py +288 -0
- webscout/Provider/OPENAI/kimi.py +469 -0
- webscout/Provider/OPENAI/netwrck.py +8 -12
- webscout/Provider/OPENAI/refact.py +274 -0
- webscout/Provider/OPENAI/textpollinations.py +3 -6
- webscout/Provider/OPENAI/toolbaz.py +1 -0
- webscout/Provider/TTI/bing.py +14 -2
- webscout/Provider/TTI/together.py +10 -9
- webscout/Provider/TTS/README.md +0 -1
- webscout/Provider/TTS/__init__.py +0 -1
- webscout/Provider/TTS/base.py +479 -159
- webscout/Provider/TTS/deepgram.py +409 -156
- webscout/Provider/TTS/elevenlabs.py +425 -111
- webscout/Provider/TTS/freetts.py +317 -140
- webscout/Provider/TTS/gesserit.py +192 -128
- webscout/Provider/TTS/murfai.py +248 -113
- webscout/Provider/TTS/openai_fm.py +347 -129
- webscout/Provider/TTS/speechma.py +620 -586
- webscout/Provider/TextPollinationsAI.py +3 -6
- webscout/Provider/TogetherAI.py +50 -55
- webscout/Provider/UNFINISHED/VercelAIGateway.py +339 -0
- webscout/Provider/__init__.py +2 -90
- webscout/Provider/cerebras.py +83 -33
- webscout/Provider/copilot.py +42 -23
- webscout/Provider/toolbaz.py +1 -0
- webscout/conversation.py +22 -20
- webscout/sanitize.py +14 -10
- webscout/scout/README.md +20 -23
- webscout/scout/core/crawler.py +125 -38
- webscout/scout/core/scout.py +26 -5
- webscout/version.py +1 -1
- webscout/webscout_search.py +13 -6
- webscout/webscout_search_async.py +10 -8
- webscout/yep_search.py +13 -5
- {webscout-8.3.5.dist-info → webscout-8.3.6.dist-info}/METADATA +2 -1
- {webscout-8.3.5.dist-info → webscout-8.3.6.dist-info}/RECORD +59 -56
- webscout/Provider/Glider.py +0 -225
- webscout/Provider/OPENAI/c4ai.py +0 -394
- webscout/Provider/OPENAI/glider.py +0 -330
- webscout/Provider/TTS/sthir.py +0 -94
- /webscout/Provider/{samurai.py → UNFINISHED/samurai.py} +0 -0
- {webscout-8.3.5.dist-info → webscout-8.3.6.dist-info}/WHEEL +0 -0
- {webscout-8.3.5.dist-info → webscout-8.3.6.dist-info}/entry_points.txt +0 -0
- {webscout-8.3.5.dist-info → webscout-8.3.6.dist-info}/licenses/LICENSE.md +0 -0
- {webscout-8.3.5.dist-info → webscout-8.3.6.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
import time
|
|
4
|
+
import uuid
|
|
5
|
+
from typing import List, Dict, Optional, Union, Generator, Any
|
|
6
|
+
|
|
7
|
+
from webscout.Provider.OPENAI.base import OpenAICompatibleProvider, BaseChat, BaseCompletions
|
|
8
|
+
from webscout.Provider.OPENAI.utils import (
|
|
9
|
+
ChatCompletionChunk, ChatCompletion, Choice, ChoiceDelta,
|
|
10
|
+
ChatCompletionMessage, CompletionUsage, format_prompt, count_tokens
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from webscout.litagent import LitAgent
|
|
15
|
+
except ImportError:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
class Completions(BaseCompletions):
|
|
19
|
+
def __init__(self, client: 'GptOss'):
|
|
20
|
+
self._client = client
|
|
21
|
+
|
|
22
|
+
def create(
|
|
23
|
+
self,
|
|
24
|
+
*,
|
|
25
|
+
model: str,
|
|
26
|
+
messages: List[Dict[str, str]],
|
|
27
|
+
max_tokens: Optional[int] = 600,
|
|
28
|
+
stream: bool = False,
|
|
29
|
+
temperature: Optional[float] = None,
|
|
30
|
+
top_p: Optional[float] = None,
|
|
31
|
+
timeout: Optional[int] = None,
|
|
32
|
+
proxies: Optional[Dict[str, str]] = None,
|
|
33
|
+
**kwargs: Any
|
|
34
|
+
) -> Union[ChatCompletion, Generator[ChatCompletionChunk, None, None]]:
|
|
35
|
+
# Format messages into conversation prompt
|
|
36
|
+
conversation_prompt = format_prompt(messages, add_special_tokens=False, do_continue=True)
|
|
37
|
+
|
|
38
|
+
# Count tokens for usage tracking
|
|
39
|
+
prompt_tokens = count_tokens(conversation_prompt)
|
|
40
|
+
|
|
41
|
+
payload = {
|
|
42
|
+
"op": "threads.create",
|
|
43
|
+
"params": {
|
|
44
|
+
"input": {
|
|
45
|
+
"text": conversation_prompt,
|
|
46
|
+
"content": [{"type": "input_text", "text": conversation_prompt}],
|
|
47
|
+
"quoted_text": "",
|
|
48
|
+
"attachments": []
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
54
|
+
created_time = int(time.time())
|
|
55
|
+
|
|
56
|
+
if stream:
|
|
57
|
+
return self._create_stream(request_id, created_time, model, payload, timeout, proxies, prompt_tokens)
|
|
58
|
+
else:
|
|
59
|
+
return self._create_non_stream(request_id, created_time, model, payload, timeout, proxies, prompt_tokens)
|
|
60
|
+
|
|
61
|
+
def _create_stream(
|
|
62
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any],
|
|
63
|
+
timeout: Optional[int] = None, proxies: Optional[Dict[str, str]] = None,
|
|
64
|
+
prompt_tokens: int = 0
|
|
65
|
+
) -> Generator[ChatCompletionChunk, None, None]:
|
|
66
|
+
try:
|
|
67
|
+
response = self._client.session.post(
|
|
68
|
+
self._client.base_url,
|
|
69
|
+
headers=self._client.headers,
|
|
70
|
+
json=payload,
|
|
71
|
+
stream=True,
|
|
72
|
+
timeout=timeout or self._client.timeout,
|
|
73
|
+
proxies=proxies
|
|
74
|
+
)
|
|
75
|
+
response.raise_for_status()
|
|
76
|
+
|
|
77
|
+
completion_tokens = 0
|
|
78
|
+
total_tokens = prompt_tokens
|
|
79
|
+
|
|
80
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
81
|
+
if line and line.startswith("data: "):
|
|
82
|
+
json_str = line[6:]
|
|
83
|
+
if json_str == "[DONE]":
|
|
84
|
+
break
|
|
85
|
+
try:
|
|
86
|
+
data = json.loads(json_str)
|
|
87
|
+
|
|
88
|
+
# Extract content from GptOss response format
|
|
89
|
+
content = None
|
|
90
|
+
if (data.get('type') == 'thread.item_updated' and
|
|
91
|
+
data.get('update', {}).get('type') == 'assistant_message.content_part.text_delta'):
|
|
92
|
+
content = data.get('update', {}).get('delta')
|
|
93
|
+
|
|
94
|
+
if content:
|
|
95
|
+
# Count tokens in the content chunk
|
|
96
|
+
chunk_tokens = count_tokens(content)
|
|
97
|
+
completion_tokens += chunk_tokens
|
|
98
|
+
total_tokens = prompt_tokens + completion_tokens
|
|
99
|
+
|
|
100
|
+
delta = ChoiceDelta(
|
|
101
|
+
content=content,
|
|
102
|
+
role="assistant"
|
|
103
|
+
)
|
|
104
|
+
choice = Choice(
|
|
105
|
+
index=0,
|
|
106
|
+
delta=delta,
|
|
107
|
+
finish_reason=None
|
|
108
|
+
)
|
|
109
|
+
chunk = ChatCompletionChunk(
|
|
110
|
+
id=request_id,
|
|
111
|
+
choices=[choice],
|
|
112
|
+
created=created_time,
|
|
113
|
+
model=model
|
|
114
|
+
)
|
|
115
|
+
chunk.usage = {
|
|
116
|
+
"prompt_tokens": prompt_tokens,
|
|
117
|
+
"completion_tokens": completion_tokens,
|
|
118
|
+
"total_tokens": total_tokens,
|
|
119
|
+
"estimated_cost": None
|
|
120
|
+
}
|
|
121
|
+
yield chunk
|
|
122
|
+
except json.JSONDecodeError:
|
|
123
|
+
continue
|
|
124
|
+
|
|
125
|
+
# Final chunk with finish_reason="stop"
|
|
126
|
+
delta = ChoiceDelta(content=None, role=None)
|
|
127
|
+
choice = Choice(index=0, delta=delta, finish_reason="stop")
|
|
128
|
+
chunk = ChatCompletionChunk(
|
|
129
|
+
id=request_id,
|
|
130
|
+
choices=[choice],
|
|
131
|
+
created=created_time,
|
|
132
|
+
model=model
|
|
133
|
+
)
|
|
134
|
+
chunk.usage = {
|
|
135
|
+
"prompt_tokens": prompt_tokens,
|
|
136
|
+
"completion_tokens": completion_tokens,
|
|
137
|
+
"total_tokens": total_tokens,
|
|
138
|
+
"estimated_cost": None
|
|
139
|
+
}
|
|
140
|
+
yield chunk
|
|
141
|
+
|
|
142
|
+
except Exception as e:
|
|
143
|
+
print(f"Error during GptOss stream request: {e}")
|
|
144
|
+
raise IOError(f"GptOss request failed: {e}") from e
|
|
145
|
+
|
|
146
|
+
def _create_non_stream(
|
|
147
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any],
|
|
148
|
+
timeout: Optional[int] = None, proxies: Optional[Dict[str, str]] = None,
|
|
149
|
+
prompt_tokens: int = 0
|
|
150
|
+
) -> ChatCompletion:
|
|
151
|
+
try:
|
|
152
|
+
response = self._client.session.post(
|
|
153
|
+
self._client.base_url,
|
|
154
|
+
headers=self._client.headers,
|
|
155
|
+
json=payload,
|
|
156
|
+
stream=True, # GptOss API is event-stream only
|
|
157
|
+
timeout=timeout or self._client.timeout,
|
|
158
|
+
proxies=proxies
|
|
159
|
+
)
|
|
160
|
+
response.raise_for_status()
|
|
161
|
+
|
|
162
|
+
# Collect all chunks to form complete response
|
|
163
|
+
full_content = ""
|
|
164
|
+
completion_tokens = 0
|
|
165
|
+
|
|
166
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
167
|
+
if line and line.startswith("data: "):
|
|
168
|
+
json_str = line[6:]
|
|
169
|
+
if json_str == "[DONE]":
|
|
170
|
+
break
|
|
171
|
+
try:
|
|
172
|
+
data = json.loads(json_str)
|
|
173
|
+
|
|
174
|
+
# Extract content from GptOss response format
|
|
175
|
+
if (data.get('type') == 'thread.item_updated' and
|
|
176
|
+
data.get('update', {}).get('type') == 'assistant_message.content_part.text_delta'):
|
|
177
|
+
content = data.get('update', {}).get('delta')
|
|
178
|
+
if content:
|
|
179
|
+
full_content += content
|
|
180
|
+
except json.JSONDecodeError:
|
|
181
|
+
continue
|
|
182
|
+
|
|
183
|
+
# Count tokens in the complete response
|
|
184
|
+
completion_tokens = count_tokens(full_content)
|
|
185
|
+
total_tokens = prompt_tokens + completion_tokens
|
|
186
|
+
|
|
187
|
+
message = ChatCompletionMessage(
|
|
188
|
+
role="assistant",
|
|
189
|
+
content=full_content
|
|
190
|
+
)
|
|
191
|
+
choice = Choice(
|
|
192
|
+
index=0,
|
|
193
|
+
message=message,
|
|
194
|
+
finish_reason="stop"
|
|
195
|
+
)
|
|
196
|
+
usage = CompletionUsage(
|
|
197
|
+
prompt_tokens=prompt_tokens,
|
|
198
|
+
completion_tokens=completion_tokens,
|
|
199
|
+
total_tokens=total_tokens
|
|
200
|
+
)
|
|
201
|
+
completion = ChatCompletion(
|
|
202
|
+
id=request_id,
|
|
203
|
+
choices=[choice],
|
|
204
|
+
created=created_time,
|
|
205
|
+
model=model,
|
|
206
|
+
usage=usage
|
|
207
|
+
)
|
|
208
|
+
return completion
|
|
209
|
+
|
|
210
|
+
except Exception as e:
|
|
211
|
+
print(f"Error during GptOss non-stream request: {e}")
|
|
212
|
+
raise IOError(f"GptOss request failed: {e}") from e
|
|
213
|
+
|
|
214
|
+
class Chat(BaseChat):
|
|
215
|
+
def __init__(self, client: 'GptOss'):
|
|
216
|
+
self.completions = Completions(client)
|
|
217
|
+
|
|
218
|
+
class GptOss(OpenAICompatibleProvider):
|
|
219
|
+
AVAILABLE_MODELS = ["gpt-oss-20b", "gpt-oss-120b"]
|
|
220
|
+
|
|
221
|
+
def __init__(
|
|
222
|
+
self,
|
|
223
|
+
browser: str = "chrome",
|
|
224
|
+
api_key: str = None,
|
|
225
|
+
model: str = "gpt-oss-120b",
|
|
226
|
+
reasoning_effort: str = "high",
|
|
227
|
+
timeout: int = 30,
|
|
228
|
+
**kwargs
|
|
229
|
+
):
|
|
230
|
+
super().__init__(api_key=api_key, **kwargs)
|
|
231
|
+
self.timeout = timeout
|
|
232
|
+
self.base_url = "https://api.gpt-oss.com/chatkit"
|
|
233
|
+
self.model = model if model in self.AVAILABLE_MODELS else self.AVAILABLE_MODELS[0]
|
|
234
|
+
self.reasoning_effort = reasoning_effort
|
|
235
|
+
self.session = requests.Session()
|
|
236
|
+
|
|
237
|
+
# Generate headers using LitAgent
|
|
238
|
+
try:
|
|
239
|
+
agent = LitAgent()
|
|
240
|
+
fingerprint = agent.generate_fingerprint(browser)
|
|
241
|
+
self.headers = {
|
|
242
|
+
"Accept": "text/event-stream",
|
|
243
|
+
"Accept-Encoding": fingerprint.get("accept_encoding", "gzip, deflate, br"),
|
|
244
|
+
"Accept-Language": fingerprint.get("accept_language", "en-US,en;q=0.9"),
|
|
245
|
+
"Content-Type": "application/json",
|
|
246
|
+
"Cache-Control": "no-cache",
|
|
247
|
+
"Connection": "keep-alive",
|
|
248
|
+
"Pragma": "no-cache",
|
|
249
|
+
"User-Agent": fingerprint.get("user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"),
|
|
250
|
+
"x-reasoning-effort": self.reasoning_effort,
|
|
251
|
+
"x-selected-model": self.model,
|
|
252
|
+
"x-show-reasoning": "true"
|
|
253
|
+
}
|
|
254
|
+
except:
|
|
255
|
+
# Fallback headers if LitAgent fails
|
|
256
|
+
self.headers = {
|
|
257
|
+
"Accept": "text/event-stream",
|
|
258
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
259
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
260
|
+
"Content-Type": "application/json",
|
|
261
|
+
"Cache-Control": "no-cache",
|
|
262
|
+
"Connection": "keep-alive",
|
|
263
|
+
"Pragma": "no-cache",
|
|
264
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
|
265
|
+
"x-reasoning-effort": self.reasoning_effort,
|
|
266
|
+
"x-selected-model": self.model,
|
|
267
|
+
"x-show-reasoning": "true"
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
self.session.headers.update(self.headers)
|
|
271
|
+
self.chat = Chat(self)
|
|
272
|
+
|
|
273
|
+
@property
|
|
274
|
+
def models(self):
|
|
275
|
+
class _ModelList:
|
|
276
|
+
def list(inner_self):
|
|
277
|
+
return type(self).AVAILABLE_MODELS
|
|
278
|
+
return _ModelList()
|
|
279
|
+
|
|
280
|
+
if __name__ == "__main__":
|
|
281
|
+
client = GptOss()
|
|
282
|
+
response = client.chat.completions.create(
|
|
283
|
+
model="gpt-oss-120b",
|
|
284
|
+
messages=[{"role": "user", "content": "Hello, how are you?"}],
|
|
285
|
+
max_tokens=100,
|
|
286
|
+
stream=False
|
|
287
|
+
)
|
|
288
|
+
print(response)
|