webscout 6.9__py3-none-any.whl → 7.1__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/AIbase.py +12 -2
- webscout/DWEBS.py +38 -22
- webscout/Extra/autocoder/autocoder_utiles.py +68 -7
- webscout/Extra/autollama.py +0 -16
- webscout/Extra/gguf.py +0 -13
- webscout/LLM.py +1 -1
- webscout/Provider/AISEARCH/DeepFind.py +251 -0
- webscout/Provider/AISEARCH/__init__.py +2 -2
- webscout/Provider/AISEARCH/felo_search.py +167 -118
- webscout/Provider/Blackboxai.py +136 -137
- webscout/Provider/Cloudflare.py +92 -78
- webscout/Provider/Deepinfra.py +59 -35
- webscout/Provider/Glider.py +222 -0
- webscout/Provider/Groq.py +26 -18
- webscout/Provider/HF_space/__init__.py +0 -0
- webscout/Provider/HF_space/qwen_qwen2.py +206 -0
- webscout/Provider/Jadve.py +108 -77
- webscout/Provider/Llama3.py +117 -94
- webscout/Provider/Marcus.py +65 -10
- webscout/Provider/Netwrck.py +61 -49
- webscout/Provider/PI.py +77 -122
- webscout/Provider/PizzaGPT.py +129 -82
- webscout/Provider/TextPollinationsAI.py +229 -0
- webscout/Provider/Youchat.py +28 -22
- webscout/Provider/__init__.py +12 -4
- webscout/Provider/askmyai.py +2 -2
- webscout/Provider/chatglm.py +205 -0
- webscout/Provider/dgaf.py +215 -0
- webscout/Provider/gaurish.py +106 -66
- webscout/Provider/hermes.py +219 -0
- webscout/Provider/llamatutor.py +72 -62
- webscout/Provider/llmchat.py +62 -35
- webscout/Provider/meta.py +6 -6
- webscout/Provider/multichat.py +205 -104
- webscout/Provider/typegpt.py +26 -23
- webscout/Provider/yep.py +3 -3
- webscout/litagent/__init__.py +3 -146
- webscout/litagent/agent.py +120 -0
- webscout/litagent/constants.py +31 -0
- webscout/tempid.py +0 -4
- webscout/version.py +1 -1
- webscout/webscout_search.py +1141 -1140
- webscout/webscout_search_async.py +635 -635
- {webscout-6.9.dist-info → webscout-7.1.dist-info}/METADATA +37 -33
- {webscout-6.9.dist-info → webscout-7.1.dist-info}/RECORD +49 -41
- {webscout-6.9.dist-info → webscout-7.1.dist-info}/WHEEL +1 -1
- webscout/Provider/AISEARCH/ooai.py +0 -155
- webscout/Provider/RUBIKSAI.py +0 -272
- {webscout-6.9.dist-info → webscout-7.1.dist-info}/LICENSE.md +0 -0
- {webscout-6.9.dist-info → webscout-7.1.dist-info}/entry_points.txt +0 -0
- {webscout-6.9.dist-info → webscout-7.1.dist-info}/top_level.txt +0 -0
webscout/Provider/RUBIKSAI.py
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import cloudscraper
|
|
2
|
-
import json
|
|
3
|
-
from typing import Any, Dict, Optional
|
|
4
|
-
|
|
5
|
-
from webscout.AIutel import Optimizers
|
|
6
|
-
from webscout.AIutel import Conversation
|
|
7
|
-
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
8
|
-
from webscout.AIbase import Provider
|
|
9
|
-
from webscout import exceptions
|
|
10
|
-
|
|
11
|
-
class RUBIKSAI(Provider):
|
|
12
|
-
"""
|
|
13
|
-
A class to interact with the Rubiks.ai API.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
AVAILABLE_MODELS = [
|
|
17
|
-
"gpt-4o-mini",
|
|
18
|
-
"gemini-1.5-pro"
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
def __init__(
|
|
22
|
-
self,
|
|
23
|
-
is_conversation: bool = True,
|
|
24
|
-
max_tokens: int = 600,
|
|
25
|
-
timeout: int = 30,
|
|
26
|
-
intro: str = None,
|
|
27
|
-
filepath: str = None,
|
|
28
|
-
update_file: bool = True,
|
|
29
|
-
proxies: dict = {},
|
|
30
|
-
history_offset: int = 10250,
|
|
31
|
-
act: str = None,
|
|
32
|
-
model: str = "gpt-4o-mini",
|
|
33
|
-
temperature: float = 0.6,
|
|
34
|
-
) -> None:
|
|
35
|
-
"""
|
|
36
|
-
Initializes the RUBIKSAI API with given parameters.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
40
|
-
max_tokens (int, optional): Maximum number of tokens to be generated upon completion.
|
|
41
|
-
Defaults to 600.
|
|
42
|
-
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
43
|
-
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
44
|
-
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
45
|
-
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
46
|
-
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
47
|
-
history_offset (int, optional): Limit conversation history to this number of last texts.
|
|
48
|
-
Defaults to 10250.
|
|
49
|
-
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
50
|
-
model (str, optional): AI model to use. Defaults to "gpt-4o-mini".
|
|
51
|
-
Available models: "gpt-4o-mini", "gemini-1.5-pro"
|
|
52
|
-
temperature (float, optional): Sampling temperature. Defaults to 0.6.
|
|
53
|
-
"""
|
|
54
|
-
if model not in self.AVAILABLE_MODELS:
|
|
55
|
-
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
|
|
56
|
-
|
|
57
|
-
self.temperature = temperature
|
|
58
|
-
self.session = cloudscraper.create_scraper()
|
|
59
|
-
self.api_endpoint = "https://rubiks.ai/search/api/"
|
|
60
|
-
|
|
61
|
-
# Updated headers with all necessary fields
|
|
62
|
-
self.headers = {
|
|
63
|
-
"authority": "rubiks.ai",
|
|
64
|
-
"accept": "*/*",
|
|
65
|
-
"accept-encoding": "gzip, deflate, br, zstd",
|
|
66
|
-
"accept-language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
67
|
-
"content-type": "application/json",
|
|
68
|
-
"dnt": "1",
|
|
69
|
-
"origin": "https://rubiks.ai",
|
|
70
|
-
"referer": f"https://rubiks.ai/search/?q=&model={model}",
|
|
71
|
-
"sec-ch-ua": '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
|
|
72
|
-
"sec-ch-ua-mobile": "?0",
|
|
73
|
-
"sec-ch-ua-platform": '"Windows"',
|
|
74
|
-
"sec-fetch-dest": "empty",
|
|
75
|
-
"sec-fetch-mode": "cors",
|
|
76
|
-
"sec-fetch-site": "same-origin",
|
|
77
|
-
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
# Get initial cookies
|
|
81
|
-
init_response = self.session.get("https://rubiks.ai/search/")
|
|
82
|
-
if not init_response.ok:
|
|
83
|
-
raise exceptions.FailedToGenerateResponseError("Failed to initialize session")
|
|
84
|
-
|
|
85
|
-
# Extract cf_clearance and other cookies
|
|
86
|
-
self.cookies = {
|
|
87
|
-
'cf_clearance': init_response.cookies.get('cf_clearance', ''),
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
# Update session with cookies and headers
|
|
91
|
-
self.session.headers.update(self.headers)
|
|
92
|
-
self.session.cookies.update(self.cookies)
|
|
93
|
-
|
|
94
|
-
self.is_conversation = is_conversation
|
|
95
|
-
self.max_tokens_to_sample = max_tokens
|
|
96
|
-
self.stream_chunk_size = 64
|
|
97
|
-
self.timeout = timeout
|
|
98
|
-
self.last_response = {}
|
|
99
|
-
self.model = model
|
|
100
|
-
|
|
101
|
-
self.__available_optimizers = (
|
|
102
|
-
method
|
|
103
|
-
for method in dir(Optimizers)
|
|
104
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
105
|
-
)
|
|
106
|
-
self.session.headers.update(self.headers)
|
|
107
|
-
Conversation.intro = (
|
|
108
|
-
AwesomePrompts().get_act(
|
|
109
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
110
|
-
)
|
|
111
|
-
if act
|
|
112
|
-
else intro or Conversation.intro
|
|
113
|
-
)
|
|
114
|
-
self.conversation = Conversation(
|
|
115
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
116
|
-
)
|
|
117
|
-
self.conversation.history_offset = history_offset
|
|
118
|
-
self.session.proxies = proxies
|
|
119
|
-
|
|
120
|
-
def ask(
|
|
121
|
-
self,
|
|
122
|
-
prompt: str,
|
|
123
|
-
stream: bool = False,
|
|
124
|
-
raw: bool = False,
|
|
125
|
-
optimizer: str = None,
|
|
126
|
-
conversationally: bool = False,
|
|
127
|
-
) -> Dict[str, Any]:
|
|
128
|
-
"""
|
|
129
|
-
Sends a prompt to the Rubiks.ai API and returns the response.
|
|
130
|
-
|
|
131
|
-
Args:
|
|
132
|
-
prompt: The text prompt to generate text from.
|
|
133
|
-
stream (bool, optional): Whether to stream the response. Defaults to False.
|
|
134
|
-
raw (bool, optional): Whether to return the raw response. Defaults to False.
|
|
135
|
-
optimizer (str, optional): The name of the optimizer to use. Defaults to None.
|
|
136
|
-
conversationally (bool, optional): Whether to chat conversationally. Defaults to False.
|
|
137
|
-
|
|
138
|
-
Returns:
|
|
139
|
-
The response from the API.
|
|
140
|
-
"""
|
|
141
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
142
|
-
if optimizer:
|
|
143
|
-
if optimizer in self.__available_optimizers:
|
|
144
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
145
|
-
conversation_prompt if conversationally else prompt
|
|
146
|
-
)
|
|
147
|
-
else:
|
|
148
|
-
raise Exception(
|
|
149
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
payload = {
|
|
153
|
-
"model": self.model,
|
|
154
|
-
"stream": True,
|
|
155
|
-
"messages": [{"role": "user", "content": conversation_prompt}],
|
|
156
|
-
"temperature": self.temperature,
|
|
157
|
-
"search": ""
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
def for_stream():
|
|
161
|
-
try:
|
|
162
|
-
response = self.session.post(
|
|
163
|
-
self.api_endpoint,
|
|
164
|
-
json=payload,
|
|
165
|
-
stream=True,
|
|
166
|
-
timeout=self.timeout
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
if response.status_code == 403:
|
|
170
|
-
# Try to refresh the session
|
|
171
|
-
init_response = self.session.get("https://rubiks.ai/search/")
|
|
172
|
-
self.cookies['cf_clearance'] = init_response.cookies.get('cf_clearance', '')
|
|
173
|
-
self.session.cookies.update(self.cookies)
|
|
174
|
-
|
|
175
|
-
# Retry the request
|
|
176
|
-
response = self.session.post(
|
|
177
|
-
self.api_endpoint,
|
|
178
|
-
json=payload,
|
|
179
|
-
stream=True,
|
|
180
|
-
timeout=self.timeout
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
if not response.ok:
|
|
184
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
185
|
-
f"Failed to generate response - ({response.status_code}, {response.reason})"
|
|
186
|
-
)
|
|
187
|
-
|
|
188
|
-
# ...rest of the streaming code...
|
|
189
|
-
streaming_response = ""
|
|
190
|
-
for line in response.iter_lines(decode_unicode=True):
|
|
191
|
-
if line:
|
|
192
|
-
if line.startswith("data: "):
|
|
193
|
-
json_data = line[6:]
|
|
194
|
-
if json_data == "[DONE]":
|
|
195
|
-
break
|
|
196
|
-
try:
|
|
197
|
-
data = json.loads(json_data)
|
|
198
|
-
if "choices" in data and len(data["choices"]) > 0:
|
|
199
|
-
content = data["choices"][0]["delta"].get("content", "")
|
|
200
|
-
streaming_response += content
|
|
201
|
-
yield content if raw else dict(text=content)
|
|
202
|
-
except json.decoder.JSONDecodeError:
|
|
203
|
-
continue
|
|
204
|
-
|
|
205
|
-
self.last_response.update(dict(text=streaming_response))
|
|
206
|
-
self.conversation.update_chat_history(
|
|
207
|
-
prompt, self.get_message(self.last_response)
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
except Exception as e:
|
|
211
|
-
raise exceptions.FailedToGenerateResponseError(f"Request failed: {str(e)}")
|
|
212
|
-
|
|
213
|
-
def for_non_stream():
|
|
214
|
-
for _ in for_stream():
|
|
215
|
-
pass
|
|
216
|
-
return self.last_response
|
|
217
|
-
|
|
218
|
-
return for_stream() if stream else for_non_stream()
|
|
219
|
-
|
|
220
|
-
def chat(
|
|
221
|
-
self,
|
|
222
|
-
prompt: str,
|
|
223
|
-
stream: bool = False,
|
|
224
|
-
optimizer: str = None,
|
|
225
|
-
conversationally: bool = False,
|
|
226
|
-
) -> str:
|
|
227
|
-
"""Generate response `str`
|
|
228
|
-
Args:
|
|
229
|
-
prompt (str): Prompt to be send.
|
|
230
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
231
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
232
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
233
|
-
Returns:
|
|
234
|
-
str: Response generated
|
|
235
|
-
"""
|
|
236
|
-
|
|
237
|
-
def for_stream():
|
|
238
|
-
for response in self.ask(
|
|
239
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
240
|
-
):
|
|
241
|
-
yield self.get_message(response)
|
|
242
|
-
|
|
243
|
-
def for_non_stream():
|
|
244
|
-
return self.get_message(
|
|
245
|
-
self.ask(
|
|
246
|
-
prompt,
|
|
247
|
-
False,
|
|
248
|
-
optimizer=optimizer,
|
|
249
|
-
conversationally=conversationally,
|
|
250
|
-
)
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
return for_stream() if stream else for_non_stream()
|
|
254
|
-
|
|
255
|
-
def get_message(self, response: dict) -> str:
|
|
256
|
-
"""Retrieves message only from response
|
|
257
|
-
|
|
258
|
-
Args:
|
|
259
|
-
response (dict): Response generated by `self.ask`
|
|
260
|
-
|
|
261
|
-
Returns:
|
|
262
|
-
str: Message extracted
|
|
263
|
-
"""
|
|
264
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
265
|
-
return response["text"]
|
|
266
|
-
if __name__ == '__main__':
|
|
267
|
-
|
|
268
|
-
from rich import print
|
|
269
|
-
ai = RUBIKSAI(timeout=5000)
|
|
270
|
-
response = ai.chat("write a poem about AI", stream=True)
|
|
271
|
-
for chunk in response:
|
|
272
|
-
print(chunk, end="", flush=True)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|