webscout 1.3.4__py3-none-any.whl → 1.3.5__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/AI.py CHANGED
@@ -25,6 +25,248 @@ from webscout.AIbase import Provider
25
25
  from Helpingai_T2 import Perplexity
26
26
  from typing import Any
27
27
  import logging
28
+ class GROQ(Provider):
29
+ def __init__(
30
+ self,
31
+ api_key: str,
32
+ is_conversation: bool = True,
33
+ max_tokens: int = 600,
34
+ temperature: float = 1,
35
+ presence_penalty: int = 0,
36
+ frequency_penalty: int = 0,
37
+ top_p: float = 1,
38
+ model: str = "mixtral-8x7b-32768",
39
+ timeout: int = 30,
40
+ intro: str = None,
41
+ filepath: str = None,
42
+ update_file: bool = True,
43
+ proxies: dict = {},
44
+ history_offset: int = 10250,
45
+ act: str = None,
46
+ ):
47
+ """Instantiates GROQ
48
+
49
+ Args:
50
+ api_key (key): GROQ's API key.
51
+ is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
52
+ max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
53
+ temperature (float, optional): Charge of the generated text's randomness. Defaults to 1.
54
+ presence_penalty (int, optional): Chances of topic being repeated. Defaults to 0.
55
+ frequency_penalty (int, optional): Chances of word being repeated. Defaults to 0.
56
+ top_p (float, optional): Sampling threshold during inference time. Defaults to 0.999.
57
+ model (str, optional): LLM model name. Defaults to "gpt-3.5-turbo".
58
+ timeout (int, optional): Http request timeout. Defaults to 30.
59
+ intro (str, optional): Conversation introductory prompt. Defaults to None.
60
+ filepath (str, optional): Path to file containing conversation history. Defaults to None.
61
+ update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
62
+ proxies (dict, optional): Http request proxies. Defaults to {}.
63
+ history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
64
+ act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
65
+ """
66
+ self.session = requests.Session()
67
+ self.is_conversation = is_conversation
68
+ self.max_tokens_to_sample = max_tokens
69
+ self.api_key = api_key
70
+ self.model = model
71
+ self.temperature = temperature
72
+ self.presence_penalty = presence_penalty
73
+ self.frequency_penalty = frequency_penalty
74
+ self.top_p = top_p
75
+ self.chat_endpoint = "https://api.groq.com/openai/v1/chat/completions"
76
+ self.stream_chunk_size = 64
77
+ self.timeout = timeout
78
+ self.last_response = {}
79
+ self.headers = {
80
+ "Content-Type": "application/json",
81
+ "Authorization": f"Bearer {self.api_key}",
82
+ }
83
+
84
+ self.__available_optimizers = (
85
+ method
86
+ for method in dir(Optimizers)
87
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
88
+ )
89
+ self.session.headers.update(self.headers)
90
+ Conversation.intro = (
91
+ AwesomePrompts().get_act(
92
+ act, raise_not_found=True, default=None, case_insensitive=True
93
+ )
94
+ if act
95
+ else intro or Conversation.intro
96
+ )
97
+ self.conversation = Conversation(
98
+ is_conversation, self.max_tokens_to_sample, filepath, update_file
99
+ )
100
+ self.conversation.history_offset = history_offset
101
+ self.session.proxies = proxies
102
+
103
+ def ask(
104
+ self,
105
+ prompt: str,
106
+ stream: bool = False,
107
+ raw: bool = False,
108
+ optimizer: str = None,
109
+ conversationally: bool = False,
110
+ ) -> dict:
111
+ """Chat with AI
112
+
113
+ Args:
114
+ prompt (str): Prompt to be send.
115
+ stream (bool, optional): Flag for streaming response. Defaults to False.
116
+ raw (bool, optional): Stream back raw response as received. Defaults to False.
117
+ optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
118
+ conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
119
+ Returns:
120
+ dict : {}
121
+ ```json
122
+ {
123
+ "id": "c0c8d139-d2b9-9909-8aa1-14948bc28404",
124
+ "object": "chat.completion",
125
+ "created": 1710852779,
126
+ "model": "mixtral-8x7b-32768",
127
+ "choices": [
128
+ {
129
+ "index": 0,
130
+ "message": {
131
+ "role": "assistant",
132
+ "content": "Hello! How can I assist you today? I'm here to help answer your questions and engage in conversation on a wide variety of topics. Feel free to ask me anything!"
133
+ },
134
+ "logprobs": null,
135
+ "finish_reason": "stop"
136
+ }
137
+ ],
138
+ "usage": {
139
+ "prompt_tokens": 47,
140
+ "prompt_time": 0.03,
141
+ "completion_tokens": 37,
142
+ "completion_time": 0.069,
143
+ "total_tokens": 84,
144
+ "total_time": 0.099
145
+ },
146
+ "system_fingerprint": null
147
+ }
148
+ ```
149
+ """
150
+ conversation_prompt = self.conversation.gen_complete_prompt(prompt)
151
+ if optimizer:
152
+ if optimizer in self.__available_optimizers:
153
+ conversation_prompt = getattr(Optimizers, optimizer)(
154
+ conversation_prompt if conversationally else prompt
155
+ )
156
+ else:
157
+ raise Exception(
158
+ f"Optimizer is not one of {self.__available_optimizers}"
159
+ )
160
+ self.session.headers.update(self.headers)
161
+ payload = {
162
+ "frequency_penalty": self.frequency_penalty,
163
+ "messages": [{"content": conversation_prompt, "role": "user"}],
164
+ "model": self.model,
165
+ "presence_penalty": self.presence_penalty,
166
+ "stream": stream,
167
+ "temperature": self.temperature,
168
+ "top_p": self.top_p,
169
+ }
170
+
171
+ def for_stream():
172
+ response = self.session.post(
173
+ self.chat_endpoint, json=payload, stream=True, timeout=self.timeout
174
+ )
175
+ if not response.ok:
176
+ raise Exception(
177
+ f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
178
+ )
179
+
180
+ message_load = ""
181
+ for value in response.iter_lines(
182
+ decode_unicode=True,
183
+ delimiter="" if raw else "data:",
184
+ chunk_size=self.stream_chunk_size,
185
+ ):
186
+ try:
187
+ resp = json.loads(value)
188
+ incomplete_message = self.get_message(resp)
189
+ if incomplete_message:
190
+ message_load += incomplete_message
191
+ resp["choices"][0]["delta"]["content"] = message_load
192
+ self.last_response.update(resp)
193
+ yield value if raw else resp
194
+ elif raw:
195
+ yield value
196
+ except json.decoder.JSONDecodeError:
197
+ pass
198
+ self.conversation.update_chat_history(
199
+ prompt, self.get_message(self.last_response)
200
+ )
201
+
202
+ def for_non_stream():
203
+ response = self.session.post(
204
+ self.chat_endpoint, json=payload, stream=False, timeout=self.timeout
205
+ )
206
+ if not response.ok:
207
+ raise Exception(
208
+ f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
209
+ )
210
+ resp = response.json()
211
+ self.last_response.update(resp)
212
+ self.conversation.update_chat_history(
213
+ prompt, self.get_message(self.last_response)
214
+ )
215
+ return resp
216
+
217
+ return for_stream() if stream else for_non_stream()
218
+
219
+ def chat(
220
+ self,
221
+ prompt: str,
222
+ stream: bool = False,
223
+ optimizer: str = None,
224
+ conversationally: bool = False,
225
+ ) -> str:
226
+ """Generate response `str`
227
+ Args:
228
+ prompt (str): Prompt to be send.
229
+ stream (bool, optional): Flag for streaming response. Defaults to False.
230
+ optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
231
+ conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
232
+ Returns:
233
+ str: Response generated
234
+ """
235
+
236
+ def for_stream():
237
+ for response in self.ask(
238
+ prompt, True, optimizer=optimizer, conversationally=conversationally
239
+ ):
240
+ yield self.get_message(response)
241
+
242
+ def for_non_stream():
243
+ return self.get_message(
244
+ self.ask(
245
+ prompt,
246
+ False,
247
+ optimizer=optimizer,
248
+ conversationally=conversationally,
249
+ )
250
+ )
251
+
252
+ return for_stream() if stream else for_non_stream()
253
+
254
+ def get_message(self, response: dict) -> str:
255
+ """Retrieves message only from response
256
+
257
+ Args:
258
+ response (dict): Response generated by `self.ask`
259
+
260
+ Returns:
261
+ str: Message extracted
262
+ """
263
+ assert isinstance(response, dict), "Response should be of dict data-type only"
264
+ try:
265
+ if response["choices"][0].get("delta"):
266
+ return response["choices"][0]["delta"]["content"]
267
+ return response["choices"][0]["message"]["content"]
268
+ except KeyError:
269
+ return ""
28
270
  #----------------------------------------------------------Sean-----------------------------------------------------------
29
271
  class Sean:
30
272
  def __init__(
@@ -294,6 +536,7 @@ class OPENAI(Provider):
294
536
  history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
295
537
  act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
296
538
  """
539
+ self.session = requests.Session()
297
540
  self.is_conversation = is_conversation
298
541
  self.max_tokens_to_sample = max_tokens
299
542
  self.api_key = api_key
@@ -498,9 +741,9 @@ class OPENAI(Provider):
498
741
  #--------------------------------------LEO-----------------------------------------
499
742
  class LEO(Provider):
500
743
 
501
- model = "llama-2-13b-chat"
744
+ # model = "llama-2-13b-chat"
502
745
 
503
- key = "qztbjzBqJueQZLFkwTTJrieu8Vw3789u"
746
+ # key = "qztbjzBqJueQZLFkwTTJrieu8Vw3789u"
504
747
  def __init__(
505
748
  self,
506
749
  is_conversation: bool = True,
@@ -508,8 +751,8 @@ class LEO(Provider):
508
751
  temperature: float = 0.2,
509
752
  top_k: int = -1,
510
753
  top_p: float = 0.999,
511
- model: str = model,
512
- brave_key: str = key,
754
+ model: str = "llama-2-13b-chat",
755
+ brave_key: str = "qztbjzBqJueQZLFkwTTJrieu8Vw3789u",
513
756
  timeout: int = 30,
514
757
  intro: str = None,
515
758
  filepath: str = None,
@@ -536,6 +779,7 @@ class LEO(Provider):
536
779
  history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
537
780
  act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
538
781
  """
782
+ self.session = requests.Session()
539
783
  self.is_conversation = is_conversation
540
784
  self.max_tokens_to_sample = max_tokens
541
785
  self.model = model
@@ -559,7 +803,7 @@ class LEO(Provider):
559
803
  for method in dir(Optimizers)
560
804
  if callable(getattr(Optimizers, method)) and not method.startswith("__")
561
805
  )
562
- self.ession.headers.update(self.headers)
806
+ self.session.headers.update(self.headers)
563
807
  Conversation.intro = (
564
808
  AwesomePrompts().get_act(
565
809
  act, raise_not_found=True, default=None, case_insensitive=True
@@ -1932,9 +2176,7 @@ from os import path
1932
2176
  from json import load
1933
2177
  from json import dumps
1934
2178
  import warnings
1935
-
1936
2179
  logging.getLogger("httpx").setLevel(logging.ERROR)
1937
-
1938
2180
  warnings.simplefilter("ignore", category=UserWarning)
1939
2181
  class GEMINI(Provider):
1940
2182
  def __init__(
webscout/AIutel.py CHANGED
@@ -28,6 +28,7 @@ webai = [
28
28
  "g4fauto",
29
29
  "perplexity",
30
30
  "sean",
31
+ "groq",
31
32
  ]
32
33
 
33
34
  gpt4free_providers = [
webscout/__init__.py CHANGED
@@ -25,6 +25,7 @@ webai = [
25
25
  "g4fauto",
26
26
  "perplexity",
27
27
  "sean",
28
+ "groq",
28
29
  ]
29
30
 
30
31
  gpt4free_providers = [
webscout/version.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "1.3.4"
1
+ __version__ = "1.3.5"
2
2
 
webscout/webai.py CHANGED
@@ -416,14 +416,14 @@ class Main(cmd.Cmd):
416
416
  elif provider == "leo":
417
417
  from webscout.AI import LEO
418
418
 
419
- self.bot = LEO.LEO(
419
+ self.bot = LEO(
420
420
  is_conversation=disable_conversation,
421
421
  max_tokens=max_tokens,
422
422
  temperature=temperature,
423
423
  top_k=top_k,
424
424
  top_p=top_p,
425
- model=getOr(model, LEO.model),
426
- brave_key=getOr(auth, LEO.key),
425
+ model=getOr(model, "llama-2-13b-chat"),
426
+ brave_key=getOr(auth, "qztbjzBqJueQZLFkwTTJrieu8Vw3789u"),
427
427
  timeout=timeout,
428
428
  intro=intro,
429
429
  filepath=filepath,
@@ -471,6 +471,30 @@ class Main(cmd.Cmd):
471
471
  history_offset=history_offset,
472
472
  act=awesome_prompt,
473
473
  )
474
+ elif provider == "groq":
475
+ assert auth, (
476
+ "GROQ's API-key is required. " "Use the flag `--key` or `-k`"
477
+ )
478
+ from webscout.AI import GROQ
479
+
480
+
481
+ self.bot = GROQ(
482
+ api_key=auth,
483
+ is_conversation=disable_conversation,
484
+ max_tokens=max_tokens,
485
+ temperature=temperature,
486
+ presence_penalty=top_p,
487
+ frequency_penalty=top_k,
488
+ top_p=top_p,
489
+ model=getOr(model, "mixtral-8x7b-32768"),
490
+ timeout=timeout,
491
+ intro=intro,
492
+ filepath=filepath,
493
+ update_file=update_file,
494
+ proxies=proxies,
495
+ history_offset=history_offset,
496
+ act=awesome_prompt,
497
+ )
474
498
  elif provider == "sean":
475
499
  from webscout.AI import Sean
476
500
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: webscout
3
- Version: 1.3.4
3
+ Version: 1.3.5
4
4
  Summary: Search for anything using the Google, DuckDuckGo.com, yep.com, phind.com, you.com, etc Also containes AI models, can transcribe yt videos, have TTS support and now has webai(terminal gpt and open interpeter) support
5
5
  Author: OEvortex
6
6
  Author-email: helpingai5@gmail.com
@@ -10,13 +10,13 @@ DeepWEBS/networks/webpage_fetcher.py,sha256=vRB9T3o-nMgrMkG2NPHTDctNeXaPSKCmBXqu
10
10
  DeepWEBS/utilsdw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  DeepWEBS/utilsdw/enver.py,sha256=vpI7s4_o_VL9govSryOv-z1zYK3pTEW3-H9QNN8JYtc,2472
12
12
  DeepWEBS/utilsdw/logger.py,sha256=Z0nFUcEGyU8r28yKiIyvEtO26xxpmJgbvNToTfwZecc,8174
13
- webscout/AI.py,sha256=9ZEctvGx558mmCva6c9lB5c0pbU-of5azle2F4Mpqhg,93054
13
+ webscout/AI.py,sha256=iuNRGcRY-StwH0PwwUYNC_JhUKG_yAk8RYOh4-t67Gs,103168
14
14
  webscout/AIbase.py,sha256=vQi2ougu5bG-QdmoYmxCQsOg7KTEgG7EF6nZh5qqUGw,2343
15
- webscout/AIutel.py,sha256=rVbQwPSqrsUc0vZDMn2bXO6n0w479QUOljBYFRNH76Q,24413
15
+ webscout/AIutel.py,sha256=1C2HA-xgpW3OalFrI8r6md-uJwzCPvnUG0dBWYOV2KI,24426
16
16
  webscout/DWEBS.py,sha256=QT-7-dUgWhQ_H7EVZD53AVyXxyskoPMKCkFIpzkN56Q,7332
17
17
  webscout/HelpingAI.py,sha256=YeZw0zYVHMcBFFPNdd3_Ghpm9ebt_EScQjHO_IIs4lg,8103
18
18
  webscout/LLM.py,sha256=CiDz0okZNEoXuxMwadZnwRGSLpqk2zg0vzvXSxQZjcE,1910
19
- webscout/__init__.py,sha256=0RRjdP5ZM25pFJW8RslilZyQOLZtUUIjL-NqTJjePZA,1002
19
+ webscout/__init__.py,sha256=6l3n5S_nDg1uhoG6eBW7C7Bhb7B23uBqQwNN35E7P3E,1015
20
20
  webscout/__main__.py,sha256=ZtTRgsRjUi2JOvYFLF1ZCh55Sdoz94I-BS-TlJC7WDU,126
21
21
  webscout/cli.py,sha256=F888fdrFUQgczMBN4yMOSf6Nh-IbvkqpPhDsbnA2FtQ,17059
22
22
  webscout/exceptions.py,sha256=4AOO5wexeL96nvUS-badcckcwrPS7UpZyAgB9vknHZE,276
@@ -24,14 +24,14 @@ webscout/g4f.py,sha256=NEZbXOoVfmHiKcSjVpBMNKZzHgbTJLsd8xOXjtn4js4,16358
24
24
  webscout/models.py,sha256=5iQIdtedT18YuTZ3npoG7kLMwcrKwhQ7928dl_7qZW0,692
25
25
  webscout/transcriber.py,sha256=EddvTSq7dPJ42V3pQVnGuEiYQ7WjJ9uyeR9kMSxN7uY,20622
26
26
  webscout/utils.py,sha256=c_98M4oqpb54pUun3fpGGlCerFD6ZHUbghyp5b7Mwgo,2605
27
- webscout/version.py,sha256=Bw-PmcKUlfRVmyOF25uf1CLYn5NfqviwtSLQ0KmE2W8,25
27
+ webscout/version.py,sha256=84L_BIC4IlYF8PSO3raVy2A4eNETbCETloSoLV9OffA,25
28
28
  webscout/voice.py,sha256=1Ids_2ToPBMX0cH_UyPMkY_6eSE9H4Gazrl0ujPmFag,941
29
- webscout/webai.py,sha256=ApxRQ6Us7-u_6kBACb1RSXbBFNEPHQhVdQobvns1Qkw,73868
29
+ webscout/webai.py,sha256=ogbIOgLUwGtXg2zdYgJq7H46l8mzfyncWLR-g0vXLcU,74812
30
30
  webscout/webscout_search.py,sha256=3_lli-hDb8_kCGwscK29xuUcOS833ROgpNhDzrxh0dk,3085
31
31
  webscout/webscout_search_async.py,sha256=Y5frH0k3hLqBCR-8dn7a_b7EvxdYxn6wHiKl3jWosE0,40670
32
- webscout-1.3.4.dist-info/LICENSE.md,sha256=mRVwJuT4SXC5O93BFdsfWBjlXjGn2Np90Zm5SocUzM0,3150
33
- webscout-1.3.4.dist-info/METADATA,sha256=t6lU_0POPrMQnuCKyA04SjkhxKS0cMtHr0-oYW-2cPg,31961
34
- webscout-1.3.4.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
35
- webscout-1.3.4.dist-info/entry_points.txt,sha256=8-93eRslYrzTHs5E-6yFRJrve00C9q-SkXJD113jzRY,197
36
- webscout-1.3.4.dist-info/top_level.txt,sha256=OD5YKy6Y3hldL7SmuxsiEDxAG4LgdSSWwzYk22MF9fk,18
37
- webscout-1.3.4.dist-info/RECORD,,
32
+ webscout-1.3.5.dist-info/LICENSE.md,sha256=mRVwJuT4SXC5O93BFdsfWBjlXjGn2Np90Zm5SocUzM0,3150
33
+ webscout-1.3.5.dist-info/METADATA,sha256=piJwnW1M9ZmLGx7als7tWJyY9X5vZXnBahqapGK3Ju0,31961
34
+ webscout-1.3.5.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
35
+ webscout-1.3.5.dist-info/entry_points.txt,sha256=8-93eRslYrzTHs5E-6yFRJrve00C9q-SkXJD113jzRY,197
36
+ webscout-1.3.5.dist-info/top_level.txt,sha256=OD5YKy6Y3hldL7SmuxsiEDxAG4LgdSSWwzYk22MF9fk,18
37
+ webscout-1.3.5.dist-info/RECORD,,