webscout 5.1__py3-none-any.whl → 5.3__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.

Files changed (40) hide show
  1. webscout/AIauto.py +83 -277
  2. webscout/AIbase.py +106 -4
  3. webscout/AIutel.py +41 -10
  4. webscout/Agents/Onlinesearcher.py +91 -104
  5. webscout/Agents/__init__.py +2 -1
  6. webscout/Agents/ai.py +186 -0
  7. webscout/Agents/functioncall.py +57 -27
  8. webscout/Bing_search.py +73 -43
  9. webscout/DWEBS.py +99 -77
  10. webscout/Local/_version.py +1 -1
  11. webscout/Provider/AI21.py +177 -0
  12. webscout/Provider/Chatify.py +174 -0
  13. webscout/Provider/Cloudflare.py +0 -4
  14. webscout/Provider/EDITEE.py +215 -0
  15. webscout/Provider/{Berlin4h.py → NetFly.py} +81 -82
  16. webscout/Provider/RUBIKSAI.py +11 -5
  17. webscout/Provider/TTI/PollinationsAI.py +138 -0
  18. webscout/Provider/TTI/__init__.py +2 -0
  19. webscout/Provider/TTI/deepinfra.py +148 -0
  20. webscout/Provider/TTS/__init__.py +2 -0
  21. webscout/Provider/TTS/streamElements.py +292 -0
  22. webscout/Provider/TTS/voicepod.py +118 -0
  23. webscout/Provider/{liaobots.py → TeachAnything.py} +31 -122
  24. webscout/Provider/__init__.py +14 -4
  25. webscout/Provider/ai4chat.py +14 -8
  26. webscout/Provider/cerebras.py +199 -0
  27. webscout/Provider/felo_search.py +28 -68
  28. webscout/Provider/x0gpt.py +181 -0
  29. webscout/__init__.py +4 -2
  30. webscout/exceptions.py +2 -1
  31. webscout/transcriber.py +195 -140
  32. webscout/version.py +1 -1
  33. {webscout-5.1.dist-info → webscout-5.3.dist-info}/METADATA +41 -82
  34. {webscout-5.1.dist-info → webscout-5.3.dist-info}/RECORD +38 -28
  35. webscout/async_providers.py +0 -21
  36. webscout/voice.py +0 -34
  37. {webscout-5.1.dist-info → webscout-5.3.dist-info}/LICENSE.md +0 -0
  38. {webscout-5.1.dist-info → webscout-5.3.dist-info}/WHEEL +0 -0
  39. {webscout-5.1.dist-info → webscout-5.3.dist-info}/entry_points.txt +0 -0
  40. {webscout-5.1.dist-info → webscout-5.3.dist-info}/top_level.txt +0 -0
@@ -41,19 +41,6 @@ class Felo(Provider):
41
41
  history_offset: int = 10250,
42
42
  act: str = None,
43
43
  ):
44
- """Instantiates Felo
45
-
46
- Args:
47
- is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
48
- max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
49
- timeout (int, optional): Http request timeout. Defaults to 30.
50
- intro (str, optional): Conversation introductory prompt. Defaults to None.
51
- filepath (str, optional): Path to file containing conversation history. Defaults to None.
52
- update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
53
- proxies (dict, optional): Http request proxies. Defaults to {}.
54
- history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
55
- act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
56
- """
57
44
  self.session = requests.Session()
58
45
  self.is_conversation = is_conversation
59
46
  self.max_tokens_to_sample = max_tokens
@@ -106,22 +93,6 @@ class Felo(Provider):
106
93
  optimizer: str = None,
107
94
  conversationally: bool = False,
108
95
  ) -> dict:
109
- """Chat with AI
110
-
111
- Args:
112
- prompt (str): Prompt to be send.
113
- stream (bool, optional): Flag for streaming response. Defaults to False.
114
- raw (bool, optional): Stream back raw response as received. Defaults to False.
115
- optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
116
- conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
117
- Returns:
118
- dict : {}
119
- ```json
120
- {
121
- "text" : "How may I assist you today?"
122
- }
123
- ```
124
- """
125
96
  conversation_prompt = self.conversation.gen_complete_prompt(prompt)
126
97
  if optimizer:
127
98
  if optimizer in self.__available_optimizers:
@@ -156,28 +127,31 @@ class Felo(Provider):
156
127
  )
157
128
 
158
129
  streaming_text = ""
159
- for value in response.iter_lines(
160
- decode_unicode=True,
161
- chunk_size=self.stream_chunk_size,
162
- delimiter="\n",
163
- ):
164
- try:
165
- if bool(value) and value.startswith('data:'):
166
- data = json.loads(value[len('data:'):].strip())
167
- if data['type'] == 'a':
168
- streaming_text += data['data']['k']
169
- resp = dict(text=streaming_text)
170
- self.last_response.update(resp)
171
- yield value if raw else resp
172
- except json.decoder.JSONDecodeError:
173
- pass
130
+ for line in response.iter_lines(decode_unicode=True):
131
+ if line.startswith('data:'):
132
+ try:
133
+ data = json.loads(line[5:].strip())
134
+ if data['type'] == 'answer' and 'text' in data['data']:
135
+ new_text = data['data']['text']
136
+ if len(new_text) > len(streaming_text):
137
+ delta = new_text[len(streaming_text):]
138
+ streaming_text = new_text
139
+ resp = dict(text=delta)
140
+ self.last_response.update(dict(text=streaming_text))
141
+ yield line if raw else resp
142
+ except json.JSONDecodeError:
143
+ pass
144
+
174
145
  self.conversation.update_chat_history(
175
146
  prompt, self.get_message(self.last_response)
176
147
  )
177
148
 
178
149
  def for_non_stream():
179
- for _ in for_stream():
180
- pass
150
+ full_response = ""
151
+ for chunk in for_stream():
152
+ if not raw:
153
+ full_response += chunk['text']
154
+ self.last_response = dict(text=full_response)
181
155
  return self.last_response
182
156
 
183
157
  return for_stream() if stream else for_non_stream()
@@ -189,16 +163,6 @@ class Felo(Provider):
189
163
  optimizer: str = None,
190
164
  conversationally: bool = False,
191
165
  ) -> str:
192
- """Generate response `str`
193
- Args:
194
- prompt (str): Prompt to be send.
195
- stream (bool, optional): Flag for streaming response. Defaults to False.
196
- optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
197
- conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
198
- Returns:
199
- str: Response generated
200
- """
201
-
202
166
  def for_stream():
203
167
  for response in self.ask(
204
168
  prompt, True, optimizer=optimizer, conversationally=conversationally
@@ -218,21 +182,17 @@ class Felo(Provider):
218
182
  return for_stream() if stream else for_non_stream()
219
183
 
220
184
  def get_message(self, response: dict) -> str:
221
- """Retrieves message only from response
222
-
223
- Args:
224
- response (dict): Response generated by `self.ask`
225
-
226
- Returns:
227
- str: Message extracted
228
- """
229
185
  assert isinstance(response, dict), "Response should be of dict data-type only"
230
186
 
231
- text = re.sub(r'\[\[\d+\]\]', '', response["text"])
232
- return text
187
+ if "text" in response:
188
+ text = re.sub(r'\[\[\d+\]\]', '', response["text"])
189
+ return text
190
+ else:
191
+ return "" # Return an empty string if no text is found
192
+
233
193
  if __name__ == '__main__':
234
194
  from rich import print
235
195
  ai = Felo()
236
- response = ai.chat(input(">>> "))
196
+ response = ai.chat(input(">>> "), stream=True)
237
197
  for chunk in response:
238
- print(chunk, end="", flush=True)
198
+ print(chunk, end="", flush=True)
@@ -0,0 +1,181 @@
1
+ from typing import Any, Dict
2
+ from uuid import uuid4
3
+ import requests
4
+ import json
5
+ import re
6
+
7
+ from webscout.AIutel import Optimizers
8
+ from webscout.AIutel import Conversation
9
+ from webscout.AIutel import AwesomePrompts
10
+ from webscout.AIbase import Provider
11
+ from webscout import exceptions
12
+
13
+ class X0GPT(Provider):
14
+ """
15
+ A class to interact with the x0-gpt.devwtf.in API.
16
+ """
17
+
18
+ def __init__(
19
+ self,
20
+ is_conversation: bool = True,
21
+ max_tokens: int = 600,
22
+ timeout: int = 30,
23
+ intro: str = None,
24
+ filepath: str = None,
25
+ update_file: bool = True,
26
+ proxies: dict = {},
27
+ history_offset: int = 10250,
28
+ act: str = None,
29
+ ):
30
+ """
31
+ Initializes the X0GPT API with given parameters.
32
+ """
33
+ self.session = requests.Session()
34
+ self.is_conversation = is_conversation
35
+ self.max_tokens_to_sample = max_tokens
36
+ self.api_endpoint = "https://x0-gpt.devwtf.in/api/stream/reply"
37
+ self.timeout = timeout
38
+ self.last_response = {}
39
+ self.headers = {
40
+ "authority": "x0-gpt.devwtf.in",
41
+ "method": "POST",
42
+ "path": "/api/stream/reply",
43
+ "scheme": "https",
44
+ "accept": "*/*",
45
+ "accept-encoding": "gzip, deflate, br, zstd",
46
+ "accept-language": "en-US,en;q=0.9,en-IN;q=0.8",
47
+ "content-length": "114",
48
+ "content-type": "application/json",
49
+ "dnt": "1",
50
+ "origin": "https://x0-gpt.devwtf.in",
51
+ "priority": "u=1, i",
52
+ "referer": "https://x0-gpt.devwtf.in/chat",
53
+ "sec-ch-ua": '"Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127"',
54
+ "sec-ch-ua-mobile": "?0",
55
+ "sec-ch-ua-platform": '"Windows"',
56
+ "sec-fetch-dest": "empty",
57
+ "sec-fetch-mode": "cors",
58
+ "sec-fetch-site": "same-origin",
59
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0"
60
+ }
61
+
62
+ self.__available_optimizers = (
63
+ method
64
+ for method in dir(Optimizers)
65
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
66
+ )
67
+ self.session.headers.update(self.headers)
68
+ Conversation.intro = (
69
+ AwesomePrompts().get_act(
70
+ act, raise_not_found=True, default=None, case_insensitive=True
71
+ )
72
+ if act
73
+ else intro or Conversation.intro
74
+ )
75
+ self.conversation = Conversation(
76
+ is_conversation, self.max_tokens_to_sample, filepath, update_file
77
+ )
78
+ self.conversation.history_offset = history_offset
79
+ self.session.proxies = proxies
80
+
81
+ def ask(
82
+ self,
83
+ prompt: str,
84
+ stream: bool = False,
85
+ raw: bool = False,
86
+ optimizer: str = None,
87
+ conversationally: bool = False,
88
+ ) -> Dict[str, Any]:
89
+ """
90
+ Sends a prompt to the x0-gpt.devwtf.in API and returns the response.
91
+ """
92
+ conversation_prompt = self.conversation.gen_complete_prompt(prompt)
93
+ if optimizer:
94
+ if optimizer in self.__available_optimizers:
95
+ conversation_prompt = getattr(Optimizers, optimizer)(
96
+ conversation_prompt if conversationally else prompt
97
+ )
98
+ else:
99
+ raise Exception(
100
+ f"Optimizer is not one of {self.__available_optimizers}"
101
+ )
102
+
103
+ payload = {
104
+ "messages": [
105
+ {
106
+ "role": "user",
107
+ "content": conversation_prompt
108
+ }
109
+ ],
110
+ "chatId": uuid4().hex,
111
+ "namespace": None
112
+ }
113
+
114
+ def for_stream():
115
+ response = self.session.post(self.api_endpoint, headers=self.headers, json=payload, stream=True, timeout=self.timeout)
116
+ if not response.ok:
117
+ raise exceptions.FailedToGenerateResponseError(
118
+ f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
119
+ )
120
+ streaming_response = ""
121
+ for line in response.iter_lines(decode_unicode=True, chunk_size=64):
122
+ if line:
123
+ match = re.search(r'0:"(.*?)"', line)
124
+ if match:
125
+ content = match.group(1)
126
+ streaming_response += content
127
+ yield content if raw else dict(text=streaming_response)
128
+ self.last_response.update(dict(text=streaming_response))
129
+ self.conversation.update_chat_history(
130
+ prompt, self.get_message(self.last_response)
131
+ )
132
+
133
+ def for_non_stream():
134
+ for _ in for_stream():
135
+ pass
136
+ return self.last_response
137
+
138
+ return for_stream() if stream else for_non_stream()
139
+
140
+ def chat(
141
+ self,
142
+ prompt: str,
143
+ stream: bool = False,
144
+ optimizer: str = None,
145
+ conversationally: bool = False,
146
+ ) -> str:
147
+ """
148
+ Generates a response from the X0GPT API.
149
+ """
150
+
151
+ def for_stream():
152
+ for response in self.ask(
153
+ prompt, True, optimizer=optimizer, conversationally=conversationally
154
+ ):
155
+ yield self.get_message(response).replace("\n", "\n\n")
156
+
157
+ def for_non_stream():
158
+ return self.get_message(
159
+ self.ask(
160
+ prompt,
161
+ False,
162
+ optimizer=optimizer,
163
+ conversationally=conversationally,
164
+ )
165
+ ).replace("\n", "\n\n")
166
+
167
+ return for_stream() if stream else for_non_stream()
168
+
169
+ def get_message(self, response: dict) -> str:
170
+ """
171
+ Extracts the message from the API response.
172
+ """
173
+ assert isinstance(response, dict), "Response should be of dict data-type only"
174
+ return response["text"]
175
+
176
+ if __name__ == "__main__":
177
+ from rich import print
178
+ ai = X0GPT()
179
+ response = ai.chat(input(">>> "))
180
+ for chunk in response:
181
+ print(chunk, end="", flush=True)
webscout/__init__.py CHANGED
@@ -2,8 +2,8 @@ from .webscout_search import WEBS
2
2
  from .webscout_search_async import AsyncWEBS
3
3
  from .version import __version__
4
4
  from .DWEBS import *
5
- from .transcriber import transcriber
6
- from .voice import play_audio
5
+ from .transcriber import *
6
+ from .tempid import *
7
7
  from .websx_search import WEBSX
8
8
  from .LLM import VLM, LLM
9
9
  from .YTdownloader import *
@@ -11,6 +11,8 @@ from .Bing_search import *
11
11
  import g4f
12
12
  from .YTdownloader import *
13
13
  from .Provider import *
14
+ from .Provider.TTI import *
15
+ from .Provider.TTS import *
14
16
  from .Extra import gguf
15
17
  from .Extra import autollama
16
18
  from .Extra import weather_ascii, weather
webscout/exceptions.py CHANGED
@@ -21,4 +21,5 @@ class FacebookInvalidCredentialsException(Exception):
21
21
 
22
22
 
23
23
  class FacebookRegionBlocked(Exception):
24
- pass
24
+ pass
25
+