webscout 5.5__py3-none-any.whl → 5.7__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 (46) hide show
  1. webscout/Agents/Onlinesearcher.py +3 -3
  2. webscout/Agents/__init__.py +0 -1
  3. webscout/Agents/functioncall.py +3 -3
  4. webscout/Provider/Bing.py +243 -0
  5. webscout/Provider/Chatify.py +1 -1
  6. webscout/Provider/Cloudflare.py +1 -1
  7. webscout/Provider/DARKAI.py +1 -1
  8. webscout/Provider/DiscordRocks.py +109 -246
  9. webscout/Provider/Farfalle.py +1 -1
  10. webscout/Provider/Free2GPT.py +234 -0
  11. webscout/{Agents/ai.py → Provider/GPTWeb.py} +40 -33
  12. webscout/Provider/Llama3.py +65 -62
  13. webscout/Provider/OLLAMA.py +1 -1
  14. webscout/Provider/PizzaGPT.py +1 -1
  15. webscout/Provider/RUBIKSAI.py +13 -3
  16. webscout/Provider/TTI/Nexra.py +120 -0
  17. webscout/Provider/TTI/__init__.py +3 -1
  18. webscout/Provider/TTI/blackboximage.py +153 -0
  19. webscout/Provider/TTI/deepinfra.py +2 -2
  20. webscout/Provider/TeachAnything.py +1 -1
  21. webscout/Provider/Youchat.py +1 -1
  22. webscout/Provider/__init__.py +11 -6
  23. webscout/Provider/{NetFly.py → aigames.py} +76 -79
  24. webscout/Provider/cleeai.py +1 -1
  25. webscout/Provider/elmo.py +1 -1
  26. webscout/Provider/felo_search.py +1 -1
  27. webscout/Provider/genspark.py +1 -1
  28. webscout/Provider/julius.py +7 -1
  29. webscout/Provider/lepton.py +1 -1
  30. webscout/Provider/meta.py +2 -2
  31. webscout/Provider/turboseek.py +1 -1
  32. webscout/Provider/upstage.py +230 -0
  33. webscout/Provider/x0gpt.py +1 -1
  34. webscout/Provider/xdash.py +1 -1
  35. webscout/Provider/yep.py +2 -2
  36. webscout/__init__.py +1 -0
  37. webscout/requestsHTMLfix.py +775 -0
  38. webscout/version.py +1 -1
  39. webscout/webai.py +1 -1
  40. {webscout-5.5.dist-info → webscout-5.7.dist-info}/METADATA +5 -29
  41. {webscout-5.5.dist-info → webscout-5.7.dist-info}/RECORD +45 -40
  42. webscout/Provider/ThinkAnyAI.py +0 -219
  43. {webscout-5.5.dist-info → webscout-5.7.dist-info}/LICENSE.md +0 -0
  44. {webscout-5.5.dist-info → webscout-5.7.dist-info}/WHEEL +0 -0
  45. {webscout-5.5.dist-info → webscout-5.7.dist-info}/entry_points.txt +0 -0
  46. {webscout-5.5.dist-info → webscout-5.7.dist-info}/top_level.txt +0 -0
webscout/Provider/meta.py CHANGED
@@ -8,7 +8,7 @@ from typing import Dict, Generator, Iterator, List, Union
8
8
  import random
9
9
 
10
10
 
11
- from requests_html import HTMLSession
11
+ from webscout.requestsHTMLfix import HTMLSession
12
12
  import requests
13
13
  from bs4 import BeautifulSoup
14
14
 
@@ -774,6 +774,6 @@ class Meta(Provider):
774
774
 
775
775
  if __name__ == "__main__":
776
776
  Meta = Meta()
777
- ai = Meta.chat(input(">>> "))
777
+ ai = Meta.chat("hi")
778
778
  for chunk in ai:
779
779
  print(chunk, end="", flush=True)
@@ -215,6 +215,6 @@ class TurboSeek(Provider):
215
215
  if __name__ == '__main__':
216
216
  from rich import print
217
217
  ai = TurboSeek()
218
- response = ai.chat(input(">>> "))
218
+ response = ai.chat("hi")
219
219
  for chunk in response:
220
220
  print(chunk, end="", flush=True)
@@ -0,0 +1,230 @@
1
+ import requests
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 Upstage(Provider):
12
+ """
13
+ A class to interact with the Upstage API.
14
+ """
15
+
16
+ AVAILABLE_MODELS = [
17
+ "upstage/solar-1-mini-chat",
18
+ "upstage/solar-1-mini-chat-ja",
19
+ "solar-pro"
20
+ ]
21
+
22
+ def __init__(
23
+ self,
24
+ is_conversation: bool = True,
25
+ max_tokens: int = 600,
26
+ timeout: int = 30,
27
+ intro: str = None,
28
+ filepath: str = None,
29
+ update_file: bool = True,
30
+ proxies: dict = {},
31
+ history_offset: int = 10250,
32
+ act: str = None,
33
+ model: str = "upstage/solar-1-mini-chat",
34
+ ) -> None:
35
+ """
36
+ Initializes the Upstage 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 "upstage/solar-1-mini-chat".
51
+ Available models: "upstage/solar-1-mini-chat",
52
+ "upstage/solar-1-mini-chat-ja",
53
+ "solar-pro"
54
+ """
55
+ if model not in self.AVAILABLE_MODELS:
56
+ raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
57
+
58
+ self.session = requests.Session()
59
+ self.is_conversation = is_conversation
60
+ self.max_tokens_to_sample = max_tokens
61
+ self.api_endpoint = "https://ap-northeast-2.apistage.ai/v1/web/demo/chat/completions"
62
+ self.stream_chunk_size = 64
63
+ self.timeout = timeout
64
+ self.last_response = {}
65
+ self.model = model
66
+ self.headers = {
67
+ "Content-Type": "application/json",
68
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
69
+ "Origin": "https://console.upstage.ai",
70
+ "Referer": "https://console.upstage.ai/"
71
+ }
72
+
73
+ self.__available_optimizers = (
74
+ method
75
+ for method in dir(Optimizers)
76
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
77
+ )
78
+ self.session.headers.update(self.headers)
79
+ Conversation.intro = (
80
+ AwesomePrompts().get_act(
81
+ act, raise_not_found=True, default=None, case_insensitive=True
82
+ )
83
+ if act
84
+ else intro or Conversation.intro
85
+ )
86
+ self.conversation = Conversation(
87
+ is_conversation, self.max_tokens_to_sample, filepath, update_file
88
+ )
89
+ self.conversation.history_offset = history_offset
90
+ self.session.proxies = proxies
91
+
92
+ def ask(
93
+ self,
94
+ prompt: str,
95
+ stream: bool = False,
96
+ raw: bool = False,
97
+ optimizer: str = None,
98
+ conversationally: bool = False,
99
+ ) -> Dict[str, Any]:
100
+ """
101
+ Sends a prompt to the Upstage API and returns the response.
102
+
103
+ Args:
104
+ prompt: The text prompt to generate text from.
105
+ stream (bool, optional): Whether to stream the response. Defaults to False.
106
+ raw (bool, optional): Whether to return the raw response. Defaults to False.
107
+ optimizer (str, optional): The name of the optimizer to use. Defaults to None.
108
+ conversationally (bool, optional): Whether to chat conversationally. Defaults to False.
109
+
110
+ Returns:
111
+ The response from the API.
112
+ """
113
+ conversation_prompt = self.conversation.gen_complete_prompt(prompt)
114
+ if optimizer:
115
+ if optimizer in self.__available_optimizers:
116
+ conversation_prompt = getattr(Optimizers, optimizer)(
117
+ conversation_prompt if conversationally else prompt
118
+ )
119
+ else:
120
+ raise Exception(
121
+ f"Optimizer is not one of {self.__available_optimizers}"
122
+ )
123
+
124
+ payload = {
125
+ "stream": True,
126
+ "messages": [
127
+ {
128
+ "role": "user",
129
+ "content": conversation_prompt
130
+ }
131
+ ],
132
+ "model": self.model
133
+ }
134
+
135
+ def for_stream():
136
+ response = self.session.post(
137
+ self.api_endpoint, headers=self.headers, json=payload, stream=True, timeout=self.timeout
138
+ )
139
+
140
+ if not response.ok:
141
+ # If 'solar-pro' fails, try mini-chat model
142
+ if self.model == "solar-pro":
143
+ print("solar-pro failed. Trying 'upstage/solar-1-mini-chat'...")
144
+ self.model = "upstage/solar-1-mini-chat"
145
+ return self.ask(prompt, stream, raw, optimizer, conversationally) # Retry with mini-chat
146
+
147
+ raise exceptions.FailedToGenerateResponseError(
148
+ f"Failed to generate response - ({response.status_code}, {response.reason})"
149
+ )
150
+
151
+ streaming_response = ""
152
+ for line in response.iter_lines(decode_unicode=True):
153
+ if line:
154
+ if line.startswith("data: "):
155
+ data = line[6:] # Remove 'data: ' prefix
156
+ if data != "[DONE]":
157
+ try:
158
+ json_data = json.loads(data)
159
+ content = json_data['choices'][0]['delta'].get('content', '')
160
+ if content:
161
+ streaming_response += content
162
+ yield content if raw else dict(text=streaming_response)
163
+ except json.JSONDecodeError:
164
+ print(f"Error decoding JSON: {data}")
165
+
166
+
167
+ self.last_response.update(dict(text=streaming_response))
168
+ self.conversation.update_chat_history(
169
+ prompt, self.get_message(self.last_response)
170
+ )
171
+
172
+ def for_non_stream():
173
+ for _ in for_stream():
174
+ pass
175
+ return self.last_response
176
+
177
+ return for_stream() if stream else for_non_stream()
178
+
179
+ def chat(
180
+ self,
181
+ prompt: str,
182
+ stream: bool = False,
183
+ optimizer: str = None,
184
+ conversationally: bool = False,
185
+ ) -> str:
186
+ """Generate response `str`
187
+ Args:
188
+ prompt (str): Prompt to be send.
189
+ stream (bool, optional): Flag for streaming response. Defaults to False.
190
+ optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
191
+ conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
192
+ Returns:
193
+ str: Response generated
194
+ """
195
+
196
+ def for_stream():
197
+ for response in self.ask(
198
+ prompt, True, optimizer=optimizer, conversationally=conversationally
199
+ ):
200
+ yield self.get_message(response)
201
+
202
+ def for_non_stream():
203
+ return self.get_message(
204
+ self.ask(
205
+ prompt,
206
+ False,
207
+ optimizer=optimizer,
208
+ conversationally=conversationally,
209
+ )
210
+ )
211
+
212
+ return for_stream() if stream else for_non_stream()
213
+
214
+ def get_message(self, response: dict) -> str:
215
+ """Retrieves message only from response
216
+
217
+ Args:
218
+ response (dict): Response generated by `self.ask`
219
+
220
+ Returns:
221
+ str: Message extracted
222
+ """
223
+ assert isinstance(response, dict), "Response should be of dict data-type only"
224
+ return response["text"]
225
+ if __name__ == '__main__':
226
+ from rich import print
227
+ ai = Upstage()
228
+ response = ai.chat("hi")
229
+ for chunk in response:
230
+ print(chunk, end="", flush=True)
@@ -177,6 +177,6 @@ class X0GPT(Provider):
177
177
  if __name__ == "__main__":
178
178
  from rich import print
179
179
  ai = X0GPT()
180
- response = ai.chat(input(">>> "))
180
+ response = ai.chat("hi")
181
181
  for chunk in response:
182
182
  print(chunk, end="", flush=True)
@@ -177,6 +177,6 @@ class XDASH(Provider):
177
177
  if __name__ == '__main__':
178
178
  from rich import print
179
179
  ai = XDASH()
180
- response = ai.chat(input(">>> "))
180
+ response = ai.chat("hi")
181
181
  for chunk in response:
182
182
  print(chunk, end="", flush=True)
webscout/Provider/yep.py CHANGED
@@ -467,7 +467,7 @@ if __name__ == "__main__":
467
467
  else:
468
468
  return "No results found for your query."
469
469
 
470
- ai = YEPCHAT(Tools=True)
470
+ ai = YEPCHAT(Tools=False)
471
471
 
472
472
  ai.tool_registry.register_tool("get_current_time", get_current_time, "Gets the current time.")
473
473
  ai.tool_registry.register_tool(
@@ -495,6 +495,6 @@ if __name__ == "__main__":
495
495
  },
496
496
  )
497
497
 
498
- response = ai.chat(input(">>> "))
498
+ response = ai.chat("hi")
499
499
  for chunk in response:
500
500
  print(chunk, end="", flush=True)
webscout/__init__.py CHANGED
@@ -3,6 +3,7 @@ from .webscout_search_async import AsyncWEBS
3
3
  from .version import __version__
4
4
  from .DWEBS import *
5
5
  from .transcriber import *
6
+ from .requestsHTMLfix import *
6
7
  from .tempid import *
7
8
  from .websx_search import WEBSX
8
9
  from .LLM import VLM, LLM