webscout 3.0b0__py3-none-any.whl → 3.1b0__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.

@@ -1,221 +1,221 @@
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"
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
221
  return response["text"]
@@ -1,62 +1,62 @@
1
- # webscout/providers/__init__.py
2
-
3
- from .ThinkAnyAI import ThinkAnyAI
4
- from .Xjai import Xjai
5
- from .Llama2 import LLAMA2
6
- from .Llama2 import AsyncLLAMA2
7
- from .Cohere import Cohere
8
- from .Reka import REKA
9
- from .Groq import GROQ
10
- from .Groq import AsyncGROQ
11
- from .Openai import OPENAI
12
- from .Openai import AsyncOPENAI
13
- from .Leo import LEO
14
- from .Leo import AsyncLEO
15
- from .Koboldai import KOBOLDAI
16
- from .Koboldai import AsyncKOBOLDAI
17
- from .OpenGPT import OPENGPT
18
- from .OpenGPT import AsyncOPENGPT
19
- from .Perplexity import PERPLEXITY
20
- from .Blackboxai import BLACKBOXAI
21
- from .Blackboxai import AsyncBLACKBOXAI
22
- from .Phind import PhindSearch
23
- from .Phind import AsyncPhindSearch
24
- from .Yepchat import YEPCHAT
25
- from .Yepchat import AsyncYEPCHAT
26
- from .Youchat import YouChat
27
- from .Gemini import GEMINI
28
- from .Berlin4h import Berlin4h
29
- from .ChatGPTUK import ChatGPTUK
30
- from .Poe import POE
31
- from .BasedGPT import BasedGPT
32
- __all__ = [
33
- 'ThinkAnyAI',
34
- 'Xjai',
35
- 'LLAMA2',
36
- 'AsyncLLAMA2',
37
- 'Cohere',
38
- 'REKA',
39
- 'GROQ',
40
- 'AsyncGROQ',
41
- 'OPENAI',
42
- 'AsyncOPENAI',
43
- 'LEO',
44
- 'AsyncLEO',
45
- 'KOBOLDAI',
46
- 'AsyncKOBOLDAI',
47
- 'OPENGPT',
48
- 'AsyncOPENGPT',
49
- 'PERPLEXITY',
50
- 'BLACKBOXAI',
51
- 'AsyncBLACKBOXAI',
52
- 'PhindSearch',
53
- 'AsyncPhindSearch',
54
- 'YEPCHAT',
55
- 'AsyncYEPCHAT',
56
- 'YouChat',
57
- 'GEMINI',
58
- 'Berlin4h',
59
- 'ChatGPTUK',
60
- 'POE',
61
- 'BasedGPT',
1
+ # webscout/providers/__init__.py
2
+
3
+ from .ThinkAnyAI import ThinkAnyAI
4
+ from .Xjai import Xjai
5
+ from .Llama2 import LLAMA2
6
+ from .Llama2 import AsyncLLAMA2
7
+ from .Cohere import Cohere
8
+ from .Reka import REKA
9
+ from .Groq import GROQ
10
+ from .Groq import AsyncGROQ
11
+ from .Openai import OPENAI
12
+ from .Openai import AsyncOPENAI
13
+ from .Leo import LEO
14
+ from .Leo import AsyncLEO
15
+ from .Koboldai import KOBOLDAI
16
+ from .Koboldai import AsyncKOBOLDAI
17
+ from .OpenGPT import OPENGPT
18
+ from .OpenGPT import AsyncOPENGPT
19
+ from .Perplexity import PERPLEXITY
20
+ from .Blackboxai import BLACKBOXAI
21
+ from .Blackboxai import AsyncBLACKBOXAI
22
+ from .Phind import PhindSearch
23
+ from .Phind import AsyncPhindSearch
24
+ from .Yepchat import YEPCHAT
25
+ from .Yepchat import AsyncYEPCHAT
26
+ from .Youchat import YouChat
27
+ from .Gemini import GEMINI
28
+ from .Berlin4h import Berlin4h
29
+ from .ChatGPTUK import ChatGPTUK
30
+ from .Poe import POE
31
+ from .BasedGPT import BasedGPT
32
+ __all__ = [
33
+ 'ThinkAnyAI',
34
+ 'Xjai',
35
+ 'LLAMA2',
36
+ 'AsyncLLAMA2',
37
+ 'Cohere',
38
+ 'REKA',
39
+ 'GROQ',
40
+ 'AsyncGROQ',
41
+ 'OPENAI',
42
+ 'AsyncOPENAI',
43
+ 'LEO',
44
+ 'AsyncLEO',
45
+ 'KOBOLDAI',
46
+ 'AsyncKOBOLDAI',
47
+ 'OPENGPT',
48
+ 'AsyncOPENGPT',
49
+ 'PERPLEXITY',
50
+ 'BLACKBOXAI',
51
+ 'AsyncBLACKBOXAI',
52
+ 'PhindSearch',
53
+ 'AsyncPhindSearch',
54
+ 'YEPCHAT',
55
+ 'AsyncYEPCHAT',
56
+ 'YouChat',
57
+ 'GEMINI',
58
+ 'Berlin4h',
59
+ 'ChatGPTUK',
60
+ 'POE',
61
+ 'BasedGPT',
62
62
  ]