webscout 4.6__py3-none-any.whl → 4.8__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/Agents/functioncall.py +97 -37
- webscout/Bard.py +365 -0
- webscout/Local/_version.py +1 -1
- webscout/Provider/Andi.py +7 -1
- webscout/Provider/BasedGPT.py +11 -5
- webscout/Provider/Berlin4h.py +11 -5
- webscout/Provider/Blackboxai.py +10 -4
- webscout/Provider/Cohere.py +11 -5
- webscout/Provider/DARKAI.py +25 -7
- webscout/Provider/Deepinfra.py +2 -1
- webscout/Provider/Deepseek.py +25 -9
- webscout/Provider/DiscordRocks.py +389 -0
- webscout/Provider/{ChatGPTUK.py → Farfalle.py} +80 -67
- webscout/Provider/Gemini.py +1 -1
- webscout/Provider/Groq.py +244 -110
- webscout/Provider/Llama.py +13 -5
- webscout/Provider/Llama3.py +15 -2
- webscout/Provider/OLLAMA.py +8 -7
- webscout/Provider/Perplexity.py +422 -52
- webscout/Provider/Phind.py +6 -5
- webscout/Provider/PizzaGPT.py +7 -1
- webscout/Provider/__init__.py +15 -31
- webscout/Provider/ai4chat.py +193 -0
- webscout/Provider/koala.py +11 -5
- webscout/Provider/{VTLchat.py → liaobots.py} +120 -104
- webscout/Provider/meta.py +779 -0
- webscout/exceptions.py +6 -0
- webscout/version.py +1 -1
- webscout/webai.py +2 -64
- webscout/webscout_search.py +1 -1
- {webscout-4.6.dist-info → webscout-4.8.dist-info}/METADATA +254 -297
- {webscout-4.6.dist-info → webscout-4.8.dist-info}/RECORD +36 -40
- webscout/Provider/FreeGemini.py +0 -169
- webscout/Provider/Geminiflash.py +0 -152
- webscout/Provider/Geminipro.py +0 -152
- webscout/Provider/Leo.py +0 -469
- webscout/Provider/OpenGPT.py +0 -867
- webscout/Provider/Xjai.py +0 -230
- webscout/Provider/Yepchat.py +0 -478
- webscout/Provider/Youchat.py +0 -225
- {webscout-4.6.dist-info → webscout-4.8.dist-info}/LICENSE.md +0 -0
- {webscout-4.6.dist-info → webscout-4.8.dist-info}/WHEEL +0 -0
- {webscout-4.6.dist-info → webscout-4.8.dist-info}/entry_points.txt +0 -0
- {webscout-4.6.dist-info → webscout-4.8.dist-info}/top_level.txt +0 -0
webscout/Provider/Yepchat.py
DELETED
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
import uuid
|
|
3
|
-
from selenium import webdriver
|
|
4
|
-
from selenium.webdriver.chrome.options import Options
|
|
5
|
-
from selenium.webdriver.common.by import By
|
|
6
|
-
from selenium.webdriver.support import expected_conditions as EC
|
|
7
|
-
from selenium.webdriver.support.ui import WebDriverWait
|
|
8
|
-
import click
|
|
9
|
-
import requests
|
|
10
|
-
from requests import get
|
|
11
|
-
from uuid import uuid4
|
|
12
|
-
from re import findall
|
|
13
|
-
from requests.exceptions import RequestException
|
|
14
|
-
from curl_cffi.requests import get, RequestsError
|
|
15
|
-
import g4f
|
|
16
|
-
from random import randint
|
|
17
|
-
from PIL import Image
|
|
18
|
-
import io
|
|
19
|
-
import re
|
|
20
|
-
import json
|
|
21
|
-
import yaml
|
|
22
|
-
from ..AIutel import Optimizers
|
|
23
|
-
from ..AIutel import Conversation
|
|
24
|
-
from ..AIutel import AwesomePrompts, sanitize_stream
|
|
25
|
-
from ..AIbase import Provider, AsyncProvider
|
|
26
|
-
from Helpingai_T2 import Perplexity
|
|
27
|
-
from webscout import exceptions
|
|
28
|
-
from typing import Any, AsyncGenerator, Dict
|
|
29
|
-
import logging
|
|
30
|
-
import httpx
|
|
31
|
-
|
|
32
|
-
#-------------------------------------------------------yep.com--------------------------------------------------------
|
|
33
|
-
class YEPCHAT(Provider):
|
|
34
|
-
def __init__(
|
|
35
|
-
self,
|
|
36
|
-
is_conversation: bool = True,
|
|
37
|
-
max_tokens: int = 600,
|
|
38
|
-
temperature: float = 0.6,
|
|
39
|
-
presence_penalty: int = 0,
|
|
40
|
-
frequency_penalty: int = 0,
|
|
41
|
-
top_p: float = 0.7,
|
|
42
|
-
model: str = "Mixtral-8x7B-Instruct-v0.1",
|
|
43
|
-
timeout: int = 30,
|
|
44
|
-
intro: str = None,
|
|
45
|
-
filepath: str = None,
|
|
46
|
-
update_file: bool = True,
|
|
47
|
-
proxies: dict = {},
|
|
48
|
-
history_offset: int = 10250,
|
|
49
|
-
act: str = None,
|
|
50
|
-
):
|
|
51
|
-
"""Instantiates YEPCHAT
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
55
|
-
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
56
|
-
temperature (float, optional): Charge of the generated text's randomness. Defaults to 0.6.
|
|
57
|
-
presence_penalty (int, optional): Chances of topic being repeated. Defaults to 0.
|
|
58
|
-
frequency_penalty (int, optional): Chances of word being repeated. Defaults to 0.
|
|
59
|
-
top_p (float, optional): Sampling threshold during inference time. Defaults to 0.7.
|
|
60
|
-
model (str, optional): LLM model name. Defaults to "gpt-3.5-turbo".
|
|
61
|
-
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
62
|
-
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
63
|
-
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
64
|
-
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
65
|
-
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
66
|
-
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
67
|
-
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
68
|
-
"""
|
|
69
|
-
self.session = requests.Session()
|
|
70
|
-
self.is_conversation = is_conversation
|
|
71
|
-
self.max_tokens_to_sample = max_tokens
|
|
72
|
-
self.model = model
|
|
73
|
-
self.temperature = temperature
|
|
74
|
-
self.presence_penalty = presence_penalty
|
|
75
|
-
self.frequency_penalty = frequency_penalty
|
|
76
|
-
self.top_p = top_p
|
|
77
|
-
self.chat_endpoint = "https://api.yep.com/v1/chat/completions"
|
|
78
|
-
self.stream_chunk_size = 64
|
|
79
|
-
self.timeout = timeout
|
|
80
|
-
self.last_response = {}
|
|
81
|
-
self.headers = {
|
|
82
|
-
"Accept": "*/*",
|
|
83
|
-
"Accept-Encoding": "gzip, deflate",
|
|
84
|
-
"Accept-Language": "en-US,en;q=0.9",
|
|
85
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
86
|
-
"Origin": "https://yep.com",
|
|
87
|
-
"Referer": "https://yep.com/",
|
|
88
|
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
self.__available_optimizers = (
|
|
92
|
-
method
|
|
93
|
-
for method in dir(Optimizers)
|
|
94
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
95
|
-
)
|
|
96
|
-
self.session.headers.update(self.headers)
|
|
97
|
-
Conversation.intro = (
|
|
98
|
-
AwesomePrompts().get_act(
|
|
99
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
100
|
-
)
|
|
101
|
-
if act
|
|
102
|
-
else intro or Conversation.intro
|
|
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
|
-
self.session.proxies = proxies
|
|
109
|
-
|
|
110
|
-
def ask(
|
|
111
|
-
self,
|
|
112
|
-
prompt: str,
|
|
113
|
-
stream: bool = False,
|
|
114
|
-
raw: bool = False,
|
|
115
|
-
optimizer: str = None,
|
|
116
|
-
conversationally: bool = False,
|
|
117
|
-
) -> dict:
|
|
118
|
-
"""Chat with AI
|
|
119
|
-
|
|
120
|
-
Args:
|
|
121
|
-
prompt (str): Prompt to be send.
|
|
122
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
123
|
-
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
124
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
125
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
126
|
-
Returns:
|
|
127
|
-
dict : {}
|
|
128
|
-
```json
|
|
129
|
-
{
|
|
130
|
-
"id": "cmpl-c61c1c88de4e4ad3a79134775d17ea0c",
|
|
131
|
-
"object": "chat.completion.chunk",
|
|
132
|
-
"created": 1713876886,
|
|
133
|
-
"model": "Mixtral-8x7B-Instruct-v0.1",
|
|
134
|
-
"choices": [
|
|
135
|
-
{
|
|
136
|
-
"index": 0,
|
|
137
|
-
"delta": {
|
|
138
|
-
"role": null,
|
|
139
|
-
"content": " Sure, I can help with that. Are you looking for information on how to start coding, or do you need help with a specific coding problem? We can discuss various programming languages like Python, JavaScript, Java, C++, or others. Please provide more details so I can assist you better."
|
|
140
|
-
},
|
|
141
|
-
"finish_reason": null
|
|
142
|
-
}
|
|
143
|
-
]
|
|
144
|
-
}
|
|
145
|
-
```
|
|
146
|
-
"""
|
|
147
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
148
|
-
if optimizer:
|
|
149
|
-
if optimizer in self.__available_optimizers:
|
|
150
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
151
|
-
conversation_prompt if conversationally else prompt
|
|
152
|
-
)
|
|
153
|
-
else:
|
|
154
|
-
raise Exception(
|
|
155
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
156
|
-
)
|
|
157
|
-
self.session.headers.update(self.headers)
|
|
158
|
-
payload = {
|
|
159
|
-
"stream": True,
|
|
160
|
-
"max_tokens": 1280,
|
|
161
|
-
"top_p": self.top_p,
|
|
162
|
-
"temperature": self.temperature,
|
|
163
|
-
"messages": [{"content": conversation_prompt, "role": "user"}],
|
|
164
|
-
"model": self.model,
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
def for_stream():
|
|
168
|
-
response = self.session.post(
|
|
169
|
-
self.chat_endpoint, json=payload, stream=True, timeout=self.timeout
|
|
170
|
-
)
|
|
171
|
-
if not response.ok:
|
|
172
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
173
|
-
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
message_load = ""
|
|
177
|
-
for value in response.iter_lines(
|
|
178
|
-
decode_unicode=True,
|
|
179
|
-
delimiter="" if raw else "data:",
|
|
180
|
-
chunk_size=self.stream_chunk_size,
|
|
181
|
-
):
|
|
182
|
-
try:
|
|
183
|
-
resp = json.loads(value)
|
|
184
|
-
incomplete_message = self.get_message(resp)
|
|
185
|
-
if incomplete_message:
|
|
186
|
-
message_load += incomplete_message
|
|
187
|
-
resp["choices"][0]["delta"]["content"] = message_load
|
|
188
|
-
self.last_response.update(resp)
|
|
189
|
-
yield value if raw else resp
|
|
190
|
-
elif raw:
|
|
191
|
-
yield value
|
|
192
|
-
except json.decoder.JSONDecodeError:
|
|
193
|
-
pass
|
|
194
|
-
self.conversation.update_chat_history(
|
|
195
|
-
prompt, self.get_message(self.last_response)
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
def for_non_stream():
|
|
199
|
-
for _ in for_stream():
|
|
200
|
-
pass
|
|
201
|
-
return self.last_response
|
|
202
|
-
|
|
203
|
-
return for_stream() if stream else for_non_stream()
|
|
204
|
-
|
|
205
|
-
def chat(
|
|
206
|
-
self,
|
|
207
|
-
prompt: str,
|
|
208
|
-
stream: bool = False,
|
|
209
|
-
optimizer: str = None,
|
|
210
|
-
conversationally: bool = False,
|
|
211
|
-
) -> str:
|
|
212
|
-
"""Generate response `str`
|
|
213
|
-
Args:
|
|
214
|
-
prompt (str): Prompt to be send.
|
|
215
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
216
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
217
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
218
|
-
Returns:
|
|
219
|
-
str: Response generated
|
|
220
|
-
"""
|
|
221
|
-
|
|
222
|
-
def for_stream():
|
|
223
|
-
for response in self.ask(
|
|
224
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
225
|
-
):
|
|
226
|
-
yield self.get_message(response)
|
|
227
|
-
|
|
228
|
-
def for_non_stream():
|
|
229
|
-
return self.get_message(
|
|
230
|
-
self.ask(
|
|
231
|
-
prompt,
|
|
232
|
-
False,
|
|
233
|
-
optimizer=optimizer,
|
|
234
|
-
conversationally=conversationally,
|
|
235
|
-
)
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
return for_stream() if stream else for_non_stream()
|
|
239
|
-
|
|
240
|
-
def get_message(self, response: dict) -> str:
|
|
241
|
-
"""Retrieves message only from response
|
|
242
|
-
|
|
243
|
-
Args:
|
|
244
|
-
response (dict): Response generated by `self.ask`
|
|
245
|
-
|
|
246
|
-
Returns:
|
|
247
|
-
str: Message extracted
|
|
248
|
-
"""
|
|
249
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
250
|
-
try:
|
|
251
|
-
if response["choices"][0].get("delta"):
|
|
252
|
-
return response["choices"][0]["delta"]["content"]
|
|
253
|
-
return response["choices"][0]["message"]["content"]
|
|
254
|
-
except KeyError:
|
|
255
|
-
return ""
|
|
256
|
-
class AsyncYEPCHAT(AsyncProvider):
|
|
257
|
-
def __init__(
|
|
258
|
-
self,
|
|
259
|
-
is_conversation: bool = True,
|
|
260
|
-
max_tokens: int = 600,
|
|
261
|
-
temperature: float = 0.6,
|
|
262
|
-
presence_penalty: int = 0,
|
|
263
|
-
frequency_penalty: int = 0,
|
|
264
|
-
top_p: float = 0.7,
|
|
265
|
-
model: str = "Mixtral-8x7B-Instruct-v0.1",
|
|
266
|
-
timeout: int = 30,
|
|
267
|
-
intro: str = None,
|
|
268
|
-
filepath: str = None,
|
|
269
|
-
update_file: bool = True,
|
|
270
|
-
proxies: dict = {},
|
|
271
|
-
history_offset: int = 10250,
|
|
272
|
-
act: str = None,
|
|
273
|
-
):
|
|
274
|
-
"""Instantiates YEPCHAT
|
|
275
|
-
|
|
276
|
-
Args:
|
|
277
|
-
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
278
|
-
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
279
|
-
temperature (float, optional): Charge of the generated text's randomness. Defaults to 0.6.
|
|
280
|
-
presence_penalty (int, optional): Chances of topic being repeated. Defaults to 0.
|
|
281
|
-
frequency_penalty (int, optional): Chances of word being repeated. Defaults to 0.
|
|
282
|
-
top_p (float, optional): Sampling threshold during inference time. Defaults to 0.7.
|
|
283
|
-
model (str, optional): LLM model name. Defaults to "gpt-3.5-turbo".
|
|
284
|
-
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
285
|
-
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
286
|
-
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
287
|
-
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
288
|
-
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
289
|
-
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
290
|
-
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
291
|
-
"""
|
|
292
|
-
self.session = requests.Session()
|
|
293
|
-
self.is_conversation = is_conversation
|
|
294
|
-
self.max_tokens_to_sample = max_tokens
|
|
295
|
-
self.model = model
|
|
296
|
-
self.temperature = temperature
|
|
297
|
-
self.presence_penalty = presence_penalty
|
|
298
|
-
self.frequency_penalty = frequency_penalty
|
|
299
|
-
self.top_p = top_p
|
|
300
|
-
self.chat_endpoint = "https://api.yep.com/v1/chat/completions"
|
|
301
|
-
self.stream_chunk_size = 64
|
|
302
|
-
self.timeout = timeout
|
|
303
|
-
self.last_response = {}
|
|
304
|
-
self.headers = {
|
|
305
|
-
"Accept": "*/*",
|
|
306
|
-
"Accept-Encoding": "gzip, deflate",
|
|
307
|
-
"Accept-Language": "en-US,en;q=0.9",
|
|
308
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
309
|
-
"Origin": "https://yep.com",
|
|
310
|
-
"Referer": "https://yep.com/",
|
|
311
|
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
self.__available_optimizers = (
|
|
315
|
-
method
|
|
316
|
-
for method in dir(Optimizers)
|
|
317
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
318
|
-
)
|
|
319
|
-
Conversation.intro = (
|
|
320
|
-
AwesomePrompts().get_act(
|
|
321
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
322
|
-
)
|
|
323
|
-
if act
|
|
324
|
-
else intro or Conversation.intro
|
|
325
|
-
)
|
|
326
|
-
self.conversation = Conversation(
|
|
327
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
328
|
-
)
|
|
329
|
-
self.conversation.history_offset = history_offset
|
|
330
|
-
self.session = httpx.AsyncClient(
|
|
331
|
-
headers=self.headers,
|
|
332
|
-
proxies=proxies,
|
|
333
|
-
)
|
|
334
|
-
|
|
335
|
-
async def ask(
|
|
336
|
-
self,
|
|
337
|
-
prompt: str,
|
|
338
|
-
stream: bool = False,
|
|
339
|
-
raw: bool = False,
|
|
340
|
-
optimizer: str = None,
|
|
341
|
-
conversationally: bool = False,
|
|
342
|
-
) -> dict:
|
|
343
|
-
"""Chat with AI asynchronously.
|
|
344
|
-
|
|
345
|
-
Args:
|
|
346
|
-
prompt (str): Prompt to be send.
|
|
347
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
348
|
-
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
349
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
350
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
351
|
-
Returns:
|
|
352
|
-
dict : {}
|
|
353
|
-
```json
|
|
354
|
-
{
|
|
355
|
-
"id": "cmpl-c61c1c88de4e4ad3a79134775d17ea0c",
|
|
356
|
-
"object": "chat.completion.chunk",
|
|
357
|
-
"created": 1713876886,
|
|
358
|
-
"model": "Mixtral-8x7B-Instruct-v0.1",
|
|
359
|
-
"choices": [
|
|
360
|
-
{
|
|
361
|
-
"index": 0,
|
|
362
|
-
"delta": {
|
|
363
|
-
"role": null,
|
|
364
|
-
"content": " Sure, I can help with that. Are you looking for information on how to start coding, or do you need help with a specific coding problem? We can discuss various programming languages like Python, JavaScript, Java, C++, or others. Please provide more details so I can assist you better."
|
|
365
|
-
},
|
|
366
|
-
"finish_reason": null
|
|
367
|
-
}
|
|
368
|
-
]
|
|
369
|
-
}
|
|
370
|
-
```
|
|
371
|
-
"""
|
|
372
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
373
|
-
if optimizer:
|
|
374
|
-
if optimizer in self.__available_optimizers:
|
|
375
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
376
|
-
conversation_prompt if conversationally else prompt
|
|
377
|
-
)
|
|
378
|
-
else:
|
|
379
|
-
raise Exception(
|
|
380
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
381
|
-
)
|
|
382
|
-
payload = {
|
|
383
|
-
"stream": True,
|
|
384
|
-
"max_tokens": 1280,
|
|
385
|
-
"top_p": self.top_p,
|
|
386
|
-
"temperature": self.temperature,
|
|
387
|
-
"messages": [{"content": conversation_prompt, "role": "user"}],
|
|
388
|
-
"model": self.model,
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
async def for_stream():
|
|
392
|
-
async with self.session.stream(
|
|
393
|
-
"POST", self.chat_endpoint, json=payload, timeout=self.timeout
|
|
394
|
-
) as response:
|
|
395
|
-
if not response.is_success:
|
|
396
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
397
|
-
f"Failed to generate response - ({response.status_code}, {response.reason_phrase}) - {response.text}"
|
|
398
|
-
)
|
|
399
|
-
|
|
400
|
-
message_load = ""
|
|
401
|
-
async for value in response.aiter_lines():
|
|
402
|
-
try:
|
|
403
|
-
resp = sanitize_stream(value)
|
|
404
|
-
incomplete_message = await self.get_message(resp)
|
|
405
|
-
if incomplete_message:
|
|
406
|
-
message_load += incomplete_message
|
|
407
|
-
resp["choices"][0]["delta"]["content"] = message_load
|
|
408
|
-
self.last_response.update(resp)
|
|
409
|
-
yield value if raw else resp
|
|
410
|
-
elif raw:
|
|
411
|
-
yield value
|
|
412
|
-
except json.decoder.JSONDecodeError:
|
|
413
|
-
pass
|
|
414
|
-
|
|
415
|
-
self.conversation.update_chat_history(
|
|
416
|
-
prompt, await self.get_message(self.last_response)
|
|
417
|
-
)
|
|
418
|
-
|
|
419
|
-
async def for_non_stream():
|
|
420
|
-
async for _ in for_stream():
|
|
421
|
-
pass
|
|
422
|
-
return self.last_response
|
|
423
|
-
|
|
424
|
-
return for_stream() if stream else await for_non_stream()
|
|
425
|
-
|
|
426
|
-
async def chat(
|
|
427
|
-
self,
|
|
428
|
-
prompt: str,
|
|
429
|
-
stream: bool = False,
|
|
430
|
-
optimizer: str = None,
|
|
431
|
-
conversationally: bool = False,
|
|
432
|
-
) -> str:
|
|
433
|
-
"""Generate response `str` asynchronously.
|
|
434
|
-
Args:
|
|
435
|
-
prompt (str): Prompt to be send.
|
|
436
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
437
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
438
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
439
|
-
Returns:
|
|
440
|
-
str: Response generated
|
|
441
|
-
"""
|
|
442
|
-
|
|
443
|
-
async def for_stream():
|
|
444
|
-
async_ask = await self.ask(
|
|
445
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
446
|
-
)
|
|
447
|
-
|
|
448
|
-
async for response in async_ask:
|
|
449
|
-
yield await self.get_message(response)
|
|
450
|
-
|
|
451
|
-
async def for_non_stream():
|
|
452
|
-
return await self.get_message(
|
|
453
|
-
await self.ask(
|
|
454
|
-
prompt,
|
|
455
|
-
False,
|
|
456
|
-
optimizer=optimizer,
|
|
457
|
-
conversationally=conversationally,
|
|
458
|
-
)
|
|
459
|
-
)
|
|
460
|
-
|
|
461
|
-
return for_stream() if stream else await for_non_stream()
|
|
462
|
-
|
|
463
|
-
async def get_message(self, response: dict) -> str:
|
|
464
|
-
"""Retrieves message only from response
|
|
465
|
-
|
|
466
|
-
Args:
|
|
467
|
-
response (dict): Response generated by `self.ask`
|
|
468
|
-
|
|
469
|
-
Returns:
|
|
470
|
-
str: Message extracted
|
|
471
|
-
"""
|
|
472
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
473
|
-
try:
|
|
474
|
-
if response["choices"][0].get("delta"):
|
|
475
|
-
return response["choices"][0]["delta"]["content"]
|
|
476
|
-
return response["choices"][0]["message"]["content"]
|
|
477
|
-
except KeyError:
|
|
478
|
-
return ""
|
webscout/Provider/Youchat.py
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
import uuid
|
|
3
|
-
from selenium import webdriver
|
|
4
|
-
from selenium.webdriver.chrome.options import Options
|
|
5
|
-
from selenium.webdriver.common.by import By
|
|
6
|
-
from selenium.webdriver.support import expected_conditions as EC
|
|
7
|
-
from selenium.webdriver.support.ui import WebDriverWait
|
|
8
|
-
import click
|
|
9
|
-
import requests
|
|
10
|
-
from requests import get
|
|
11
|
-
from uuid import uuid4
|
|
12
|
-
from re import findall
|
|
13
|
-
from requests.exceptions import RequestException
|
|
14
|
-
from curl_cffi.requests import get, RequestsError
|
|
15
|
-
import g4f
|
|
16
|
-
from random import randint
|
|
17
|
-
from PIL import Image
|
|
18
|
-
import io
|
|
19
|
-
import re
|
|
20
|
-
import json
|
|
21
|
-
import yaml
|
|
22
|
-
from ..AIutel import Optimizers
|
|
23
|
-
from ..AIutel import Conversation
|
|
24
|
-
from ..AIutel import AwesomePrompts, sanitize_stream
|
|
25
|
-
from ..AIbase import Provider, AsyncProvider
|
|
26
|
-
from Helpingai_T2 import Perplexity
|
|
27
|
-
from webscout import exceptions
|
|
28
|
-
from typing import Any, AsyncGenerator, Dict
|
|
29
|
-
import logging
|
|
30
|
-
import httpx
|
|
31
|
-
|
|
32
|
-
#-------------------------------------------------------youchat--------------------------------------------------------
|
|
33
|
-
class YouChat(Provider):
|
|
34
|
-
def __init__(
|
|
35
|
-
self,
|
|
36
|
-
is_conversation: bool = True,
|
|
37
|
-
max_tokens: int = 600,
|
|
38
|
-
timeout: int = 30,
|
|
39
|
-
intro: str = None,
|
|
40
|
-
filepath: str = None,
|
|
41
|
-
update_file: bool = True,
|
|
42
|
-
proxies: dict = {},
|
|
43
|
-
history_offset: int = 10250,
|
|
44
|
-
act: str = None,
|
|
45
|
-
):
|
|
46
|
-
self.session = requests.Session()
|
|
47
|
-
self.is_conversation = is_conversation
|
|
48
|
-
self.max_tokens_to_sample = max_tokens
|
|
49
|
-
self.chat_endpoint = "https://you.com/api/streamingSearch"
|
|
50
|
-
self.stream_chunk_size = 64
|
|
51
|
-
self.timeout = timeout
|
|
52
|
-
self.last_response = {}
|
|
53
|
-
|
|
54
|
-
self.payload = {
|
|
55
|
-
"q": "",
|
|
56
|
-
"page": 1,
|
|
57
|
-
"count": 10,
|
|
58
|
-
"safeSearch": "Off",
|
|
59
|
-
"onShoppingPage": False,
|
|
60
|
-
"mkt": "",
|
|
61
|
-
"responseFilter": "WebPages,Translations,TimeZone,Computation,RelatedSearches",
|
|
62
|
-
"domain": "youchat",
|
|
63
|
-
"queryTraceId": uuid.uuid4(),
|
|
64
|
-
"conversationTurnId": uuid.uuid4(),
|
|
65
|
-
"pastChatLength": 0,
|
|
66
|
-
"selectedChatMode": "default",
|
|
67
|
-
"chat": "[]",
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
self.headers = {
|
|
71
|
-
"cache-control": "no-cache",
|
|
72
|
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
|
|
73
|
-
'Referer': f'https://you.com/search?q={self.payload["q"]}&fromSearchBar=true&tbm=youchat&chatMode=default'
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
self.__available_optimizers = (
|
|
77
|
-
method
|
|
78
|
-
for method in dir(Optimizers)
|
|
79
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
80
|
-
)
|
|
81
|
-
self.session.headers.update(self.headers)
|
|
82
|
-
Conversation.intro = (
|
|
83
|
-
AwesomePrompts().get_act(
|
|
84
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
85
|
-
)
|
|
86
|
-
if act
|
|
87
|
-
else intro or Conversation.intro
|
|
88
|
-
)
|
|
89
|
-
self.conversation = Conversation(
|
|
90
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
91
|
-
)
|
|
92
|
-
self.conversation.history_offset = history_offset
|
|
93
|
-
self.session.proxies = proxies
|
|
94
|
-
|
|
95
|
-
def ask(
|
|
96
|
-
self,
|
|
97
|
-
prompt: str,
|
|
98
|
-
stream: bool = False,
|
|
99
|
-
raw: bool = False,
|
|
100
|
-
optimizer: str = None,
|
|
101
|
-
conversationally: bool = False,
|
|
102
|
-
) -> dict:
|
|
103
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
104
|
-
if optimizer:
|
|
105
|
-
if optimizer in self.__available_optimizers:
|
|
106
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
107
|
-
conversation_prompt if conversationally else prompt
|
|
108
|
-
)
|
|
109
|
-
else:
|
|
110
|
-
raise Exception(
|
|
111
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
112
|
-
)
|
|
113
|
-
self.session.headers.update(self.headers)
|
|
114
|
-
self.session.headers.update(
|
|
115
|
-
dict(
|
|
116
|
-
cookie=f"safesearch_guest=Off; uuid_guest={str(uuid4())}",
|
|
117
|
-
)
|
|
118
|
-
)
|
|
119
|
-
self.payload["q"] = prompt
|
|
120
|
-
|
|
121
|
-
def for_stream():
|
|
122
|
-
response = self.session.get(
|
|
123
|
-
self.chat_endpoint,
|
|
124
|
-
params=self.payload,
|
|
125
|
-
stream=True,
|
|
126
|
-
timeout=self.timeout,
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
if not response.ok:
|
|
130
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
131
|
-
f"Failed to generate response - ({response.status_code}, {response.reason})"
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
streaming_response = ""
|
|
135
|
-
for line in response.iter_lines(decode_unicode=True, chunk_size=64):
|
|
136
|
-
if line:
|
|
137
|
-
modified_value = re.sub("data:", "", line)
|
|
138
|
-
try:
|
|
139
|
-
json_modified_value = json.loads(modified_value)
|
|
140
|
-
if "youChatToken" in json_modified_value:
|
|
141
|
-
streaming_response += json_modified_value["youChatToken"]
|
|
142
|
-
if print:
|
|
143
|
-
print(json_modified_value["youChatToken"], end="")
|
|
144
|
-
except:
|
|
145
|
-
continue
|
|
146
|
-
self.last_response.update(dict(text=streaming_response))
|
|
147
|
-
self.conversation.update_chat_history(
|
|
148
|
-
prompt, self.get_message(self.last_response)
|
|
149
|
-
)
|
|
150
|
-
return streaming_response
|
|
151
|
-
|
|
152
|
-
def for_non_stream():
|
|
153
|
-
for _ in for_stream():
|
|
154
|
-
pass
|
|
155
|
-
return self.last_response
|
|
156
|
-
|
|
157
|
-
return for_stream() if stream else for_non_stream()
|
|
158
|
-
|
|
159
|
-
def chat(
|
|
160
|
-
self,
|
|
161
|
-
prompt: str,
|
|
162
|
-
stream: bool = False,
|
|
163
|
-
optimizer: str = None,
|
|
164
|
-
conversationally: bool = False,
|
|
165
|
-
) -> str:
|
|
166
|
-
"""Generate response `str`
|
|
167
|
-
Args:
|
|
168
|
-
prompt (str): Prompt to be send.
|
|
169
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
170
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
171
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
172
|
-
Returns:
|
|
173
|
-
str: Response generated
|
|
174
|
-
"""
|
|
175
|
-
|
|
176
|
-
def chat(
|
|
177
|
-
self,
|
|
178
|
-
prompt: str,
|
|
179
|
-
stream: bool = False,
|
|
180
|
-
optimizer: str = None,
|
|
181
|
-
conversationally: bool = False,
|
|
182
|
-
) -> str:
|
|
183
|
-
"""Generate response `str`
|
|
184
|
-
Args:
|
|
185
|
-
prompt (str): Prompt to be send.
|
|
186
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
187
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
188
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
189
|
-
Returns:
|
|
190
|
-
str: Response generated
|
|
191
|
-
"""
|
|
192
|
-
|
|
193
|
-
def for_stream():
|
|
194
|
-
for response in self.ask(
|
|
195
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
196
|
-
):
|
|
197
|
-
yield self.get_message(response)
|
|
198
|
-
|
|
199
|
-
def for_non_stream():
|
|
200
|
-
return self.get_message(
|
|
201
|
-
self.ask(
|
|
202
|
-
prompt,
|
|
203
|
-
False,
|
|
204
|
-
optimizer=optimizer,
|
|
205
|
-
conversationally=conversationally,
|
|
206
|
-
)
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
return for_stream() if stream else for_non_stream()
|
|
210
|
-
|
|
211
|
-
def get_message(self, response: dict) -> str:
|
|
212
|
-
"""Retrieves message only from response
|
|
213
|
-
|
|
214
|
-
Args:
|
|
215
|
-
response (dict): Response generated by `self.ask`
|
|
216
|
-
|
|
217
|
-
Returns:
|
|
218
|
-
str: Message extracted
|
|
219
|
-
"""
|
|
220
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
221
|
-
return response["text"]
|
|
222
|
-
|
|
223
|
-
if __name__ == "__main__":
|
|
224
|
-
YouChat = YouChat()
|
|
225
|
-
print(YouChat.chat("hello"))
|