webscout 7.6__py3-none-any.whl → 7.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.

Files changed (124) hide show
  1. webscout/AIutel.py +2 -1
  2. webscout/Bard.py +14 -11
  3. webscout/DWEBS.py +431 -415
  4. webscout/Extra/autocoder/autocoder_utiles.py +183 -47
  5. webscout/Extra/autocoder/rawdog.py +848 -649
  6. webscout/Extra/gguf.py +682 -652
  7. webscout/Provider/AI21.py +1 -1
  8. webscout/Provider/AISEARCH/DeepFind.py +2 -2
  9. webscout/Provider/AISEARCH/ISou.py +2 -23
  10. webscout/Provider/AISEARCH/felo_search.py +6 -6
  11. webscout/Provider/AISEARCH/genspark_search.py +1 -1
  12. webscout/Provider/Aitopia.py +292 -0
  13. webscout/Provider/AllenAI.py +5 -22
  14. webscout/Provider/Andi.py +3 -3
  15. webscout/Provider/C4ai.py +1 -1
  16. webscout/Provider/ChatGPTClone.py +226 -0
  17. webscout/Provider/ChatGPTES.py +3 -5
  18. webscout/Provider/ChatGPTGratis.py +4 -4
  19. webscout/Provider/Chatify.py +2 -2
  20. webscout/Provider/Cloudflare.py +3 -2
  21. webscout/Provider/DARKAI.py +3 -2
  22. webscout/Provider/DeepSeek.py +2 -2
  23. webscout/Provider/Deepinfra.py +1 -1
  24. webscout/Provider/EDITEE.py +1 -1
  25. webscout/Provider/ElectronHub.py +178 -96
  26. webscout/Provider/ExaChat.py +310 -0
  27. webscout/Provider/Free2GPT.py +2 -2
  28. webscout/Provider/Gemini.py +5 -19
  29. webscout/Provider/GithubChat.py +1 -1
  30. webscout/Provider/Glider.py +12 -8
  31. webscout/Provider/Groq.py +3 -3
  32. webscout/Provider/HF_space/qwen_qwen2.py +1 -1
  33. webscout/Provider/HeckAI.py +1 -1
  34. webscout/Provider/HuggingFaceChat.py +1 -1
  35. webscout/Provider/Hunyuan.py +272 -0
  36. webscout/Provider/Jadve.py +3 -3
  37. webscout/Provider/Koboldai.py +3 -3
  38. webscout/Provider/LambdaChat.py +391 -0
  39. webscout/Provider/Llama.py +3 -5
  40. webscout/Provider/Llama3.py +4 -12
  41. webscout/Provider/Marcus.py +3 -3
  42. webscout/Provider/OLLAMA.py +260 -36
  43. webscout/Provider/Openai.py +7 -3
  44. webscout/Provider/PI.py +1 -1
  45. webscout/Provider/Perplexitylabs.py +1 -1
  46. webscout/Provider/Phind.py +1 -1
  47. webscout/Provider/PizzaGPT.py +1 -1
  48. webscout/Provider/QwenLM.py +4 -7
  49. webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +21 -46
  50. webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +37 -49
  51. webscout/Provider/TTI/ImgSys/__init__.py +23 -0
  52. webscout/Provider/TTI/ImgSys/async_imgsys.py +202 -0
  53. webscout/Provider/TTI/ImgSys/sync_imgsys.py +195 -0
  54. webscout/Provider/TTI/__init__.py +3 -1
  55. webscout/Provider/TTI/artbit/async_artbit.py +4 -33
  56. webscout/Provider/TTI/artbit/sync_artbit.py +4 -32
  57. webscout/Provider/TTI/fastflux/async_fastflux.py +6 -2
  58. webscout/Provider/TTI/fastflux/sync_fastflux.py +7 -2
  59. webscout/Provider/TTI/huggingface/async_huggingface.py +1 -1
  60. webscout/Provider/TTI/huggingface/sync_huggingface.py +1 -1
  61. webscout/Provider/TTI/pixelmuse/__init__.py +4 -0
  62. webscout/Provider/TTI/pixelmuse/async_pixelmuse.py +249 -0
  63. webscout/Provider/TTI/pixelmuse/sync_pixelmuse.py +182 -0
  64. webscout/Provider/TTI/talkai/sync_talkai.py +1 -1
  65. webscout/Provider/TTS/utils.py +1 -1
  66. webscout/Provider/TeachAnything.py +1 -1
  67. webscout/Provider/TextPollinationsAI.py +4 -4
  68. webscout/Provider/TwoAI.py +1 -2
  69. webscout/Provider/Venice.py +4 -2
  70. webscout/Provider/VercelAI.py +234 -0
  71. webscout/Provider/WebSim.py +228 -0
  72. webscout/Provider/WiseCat.py +10 -12
  73. webscout/Provider/Youchat.py +1 -1
  74. webscout/Provider/__init__.py +22 -1
  75. webscout/Provider/ai4chat.py +1 -1
  76. webscout/Provider/aimathgpt.py +2 -6
  77. webscout/Provider/akashgpt.py +1 -1
  78. webscout/Provider/askmyai.py +4 -4
  79. webscout/Provider/asksteve.py +203 -0
  80. webscout/Provider/bagoodex.py +2 -2
  81. webscout/Provider/cerebras.py +1 -1
  82. webscout/Provider/chatglm.py +4 -4
  83. webscout/Provider/cleeai.py +1 -0
  84. webscout/Provider/copilot.py +427 -415
  85. webscout/Provider/elmo.py +1 -1
  86. webscout/Provider/flowith.py +14 -3
  87. webscout/Provider/freeaichat.py +57 -31
  88. webscout/Provider/gaurish.py +3 -5
  89. webscout/Provider/geminiprorealtime.py +1 -1
  90. webscout/Provider/granite.py +4 -4
  91. webscout/Provider/hermes.py +5 -5
  92. webscout/Provider/julius.py +1 -1
  93. webscout/Provider/koala.py +1 -1
  94. webscout/Provider/labyrinth.py +239 -0
  95. webscout/Provider/learnfastai.py +28 -15
  96. webscout/Provider/lepton.py +1 -1
  97. webscout/Provider/llama3mitril.py +4 -4
  98. webscout/Provider/llamatutor.py +1 -1
  99. webscout/Provider/llmchat.py +3 -3
  100. webscout/Provider/meta.py +1 -1
  101. webscout/Provider/multichat.py +10 -10
  102. webscout/Provider/promptrefine.py +1 -1
  103. webscout/Provider/searchchat.py +293 -0
  104. webscout/Provider/sonus.py +208 -0
  105. webscout/Provider/talkai.py +2 -2
  106. webscout/Provider/turboseek.py +1 -1
  107. webscout/Provider/tutorai.py +1 -1
  108. webscout/Provider/typegpt.py +6 -43
  109. webscout/Provider/uncovr.py +299 -0
  110. webscout/Provider/x0gpt.py +1 -1
  111. webscout/__init__.py +36 -36
  112. webscout/cli.py +293 -283
  113. webscout/litagent/agent.py +14 -9
  114. webscout/tempid.py +11 -11
  115. webscout/utils.py +2 -2
  116. webscout/version.py +1 -1
  117. webscout/webscout_search.py +1282 -1223
  118. webscout/webscout_search_async.py +813 -692
  119. {webscout-7.6.dist-info → webscout-7.8.dist-info}/METADATA +76 -44
  120. {webscout-7.6.dist-info → webscout-7.8.dist-info}/RECORD +124 -106
  121. {webscout-7.6.dist-info → webscout-7.8.dist-info}/LICENSE.md +0 -0
  122. {webscout-7.6.dist-info → webscout-7.8.dist-info}/WHEEL +0 -0
  123. {webscout-7.6.dist-info → webscout-7.8.dist-info}/entry_points.txt +0 -0
  124. {webscout-7.6.dist-info → webscout-7.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,228 @@
1
+ import requests
2
+ import json
3
+ import string
4
+ import random
5
+ from typing import Any, Dict, Union
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
+ from webscout.litagent import LitAgent
13
+
14
+ class WebSim(Provider):
15
+ """
16
+ A class to interact with the WebSim API.
17
+ """
18
+
19
+ url = "https://websim.ai"
20
+ chat_api_endpoint = "https://websim.ai/api/v1/inference/run_chat_completion"
21
+ image_api_endpoint = "https://websim.ai/api/v1/inference/run_image_generation"
22
+
23
+ image_models = ['flux']
24
+ AVAILABLE_MODELS = ['gemini-1.5-flash', 'gemini-1.5-pro', 'gemini-flash', 'gemini-pro', 'gemini-flash-thinking'] + image_models
25
+
26
+ @staticmethod
27
+ def generate_project_id(for_image=False):
28
+ """
29
+ Generate a project ID in the appropriate format
30
+
31
+ For chat: format like 'ke3_xh5gai3gjkmruomu'
32
+ For image: format like 'kx0m131_rzz66qb2xoy7'
33
+ """
34
+ chars = string.ascii_lowercase + string.digits
35
+
36
+ if for_image:
37
+ first_part = ''.join(random.choices(chars, k=7))
38
+ second_part = ''.join(random.choices(chars, k=12))
39
+ return f"{first_part}_{second_part}"
40
+ else:
41
+ prefix = ''.join(random.choices(chars, k=3))
42
+ suffix = ''.join(random.choices(chars, k=15))
43
+ return f"{prefix}_{suffix}"
44
+
45
+ def __init__(
46
+ self,
47
+ is_conversation: bool = True,
48
+ max_tokens: int = 2049,
49
+ timeout: int = 30,
50
+ intro: str = None,
51
+ filepath: str = None,
52
+ update_file: bool = True,
53
+ proxies: dict = {},
54
+ history_offset: int = 10250,
55
+ act: str = None,
56
+ model: str = 'gemini-1.5-pro',
57
+ aspect_ratio: str = "1:1"
58
+ ):
59
+ """Initializes the WebSim API client."""
60
+ if model not in self.AVAILABLE_MODELS:
61
+ raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
62
+ self.agent = LitAgent()
63
+ self.headers = {
64
+ 'accept': '*/*',
65
+ 'accept-language': 'en-US,en;q=0.9',
66
+ 'content-type': 'text/plain;charset=UTF-8',
67
+ 'origin': 'https://websim.ai',
68
+ 'user-agent': self.agent.random(),
69
+ 'websim-flags;': ''
70
+ }
71
+
72
+ self.session = requests.Session()
73
+ self.session.headers.update(self.headers)
74
+ self.session.proxies.update(proxies)
75
+
76
+ self.is_conversation = is_conversation
77
+ self.max_tokens_to_sample = max_tokens
78
+ self.timeout = timeout
79
+ self.last_response = {}
80
+ self.model = model
81
+ self.aspect_ratio = aspect_ratio
82
+
83
+ self.__available_optimizers = (
84
+ method
85
+ for method in dir(Optimizers)
86
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
87
+ )
88
+ Conversation.intro = (
89
+ AwesomePrompts().get_act(
90
+ act, raise_not_found=True, default=None, case_insensitive=True
91
+ )
92
+ if act
93
+ else intro or Conversation.intro
94
+ )
95
+
96
+ self.conversation = Conversation(
97
+ is_conversation, self.max_tokens_to_sample, filepath, update_file
98
+ )
99
+ self.conversation.history_offset = history_offset
100
+
101
+ def ask(
102
+ self,
103
+ prompt: str,
104
+ stream: bool = False,
105
+ raw: bool = False,
106
+ optimizer: str = None,
107
+ conversationally: bool = False,
108
+ ) -> Dict[str, Any]:
109
+ conversation_prompt = self.conversation.gen_complete_prompt(prompt)
110
+ if optimizer:
111
+ if optimizer in self.__available_optimizers:
112
+ conversation_prompt = getattr(Optimizers, optimizer)(
113
+ conversation_prompt if conversationally else prompt
114
+ )
115
+ else:
116
+ raise Exception(f"Optimizer is not one of {self.__available_optimizers}")
117
+
118
+ is_image_request = self.model in self.image_models
119
+ project_id = self.generate_project_id(for_image=is_image_request)
120
+
121
+ if is_image_request:
122
+ self.headers['referer'] = 'https://websim.ai/@ISWEARIAMNOTADDICTEDTOPILLOW/ai-image-prompt-generator'
123
+ return self._handle_image_request(project_id, conversation_prompt)
124
+ else:
125
+ self.headers['referer'] = 'https://websim.ai/@ISWEARIAMNOTADDICTEDTOPILLOW/zelos-ai-assistant'
126
+ return self._handle_chat_request(project_id, conversation_prompt)
127
+
128
+ def _handle_image_request(self, project_id: str, prompt: str) -> Dict[str, Any]:
129
+ try:
130
+ data = {
131
+ "project_id": project_id,
132
+ "prompt": prompt,
133
+ "aspect_ratio": self.aspect_ratio
134
+ }
135
+ response = self.session.post(
136
+ self.image_api_endpoint,
137
+ json=data,
138
+ timeout=self.timeout
139
+ )
140
+ response.raise_for_status()
141
+ response_json = response.json()
142
+ image_url = response_json.get("url")
143
+ if image_url:
144
+ self.last_response = {"text": image_url}
145
+ self.conversation.update_chat_history(prompt, image_url)
146
+ return {"text": image_url}
147
+ raise exceptions.FailedToGenerateResponseError("No image URL found in response")
148
+ except requests.RequestException as e:
149
+ raise exceptions.FailedToGenerateResponseError(f"Request failed: {str(e)}")
150
+
151
+ def _handle_chat_request(self, project_id: str, prompt: str) -> Dict[str, Any]:
152
+ max_retries = 3
153
+ retry_count = 0
154
+ last_error = None
155
+
156
+ while retry_count < max_retries:
157
+ try:
158
+ data = {
159
+ "project_id": project_id,
160
+ "messages": [{"role": "user", "content": prompt}]
161
+ }
162
+ response = self.session.post(
163
+ self.chat_api_endpoint,
164
+ json=data,
165
+ timeout=self.timeout
166
+ )
167
+
168
+ if response.status_code == 429:
169
+ last_error = exceptions.FailedToGenerateResponseError(
170
+ f"Rate limit exceeded: {response.text}"
171
+ )
172
+ retry_count += 1
173
+ if retry_count < max_retries:
174
+ continue
175
+ raise last_error
176
+
177
+ response.raise_for_status()
178
+ response_json = response.json()
179
+ content = response_json.get("content", "")
180
+
181
+ self.last_response = {"text": content}
182
+ self.conversation.update_chat_history(prompt, content)
183
+ return {"text": content.strip()}
184
+
185
+ except requests.RequestException as e:
186
+ if "Rate limit exceeded" in str(e) and retry_count < max_retries:
187
+ retry_count += 1
188
+ else:
189
+ raise exceptions.FailedToGenerateResponseError(f"Request failed: {str(e)}")
190
+
191
+ raise last_error or exceptions.FailedToGenerateResponseError("Max retries exceeded")
192
+
193
+ def chat(
194
+ self,
195
+ prompt: str,
196
+ stream: bool = False,
197
+ optimizer: str = None,
198
+ conversationally: bool = False,
199
+ ) -> str:
200
+ return self.get_message(
201
+ self.ask(prompt, False, optimizer=optimizer, conversationally=conversationally)
202
+ )
203
+
204
+ def get_message(self, response: dict) -> str:
205
+ assert isinstance(response, dict), "Response should be of dict data-type only"
206
+ return response["text"]
207
+
208
+ if __name__ == "__main__":
209
+ print("-" * 80)
210
+ print(f"{'Model':<50} {'Status':<10} {'Response'}")
211
+ print("-" * 80)
212
+
213
+ for model in WebSim.AVAILABLE_MODELS:
214
+ try:
215
+ test_ai = WebSim(model=model, timeout=60)
216
+ response = test_ai.chat("Say 'Hello' in one word")
217
+
218
+ if response and len(response.strip()) > 0:
219
+ status = "✓"
220
+ # Clean and truncate response
221
+ clean_text = response.strip().encode('utf-8', errors='ignore').decode('utf-8')
222
+ display_text = clean_text[:50] + "..." if len(clean_text) > 50 else clean_text
223
+ else:
224
+ status = "✗"
225
+ display_text = "Empty or invalid response"
226
+ print(f"\r{model:<50} {status:<10} {display_text}")
227
+ except Exception as e:
228
+ print(f"\r{model:<50} {'✗':<10} {str(e)}")
@@ -1,13 +1,14 @@
1
+ import re
1
2
  import requests
2
3
  import json
3
- from typing import Any, Dict, Generator, Optional
4
+ from typing import Union, Any, Dict, Generator, Optional
4
5
 
5
6
  from webscout.AIutel import Optimizers
6
7
  from webscout.AIutel import Conversation
7
8
  from webscout.AIutel import AwesomePrompts
8
9
  from webscout.AIbase import Provider
9
10
  from webscout import exceptions
10
- from webscout import LitAgent
11
+ from webscout.litagent import LitAgent
11
12
 
12
13
 
13
14
  class WiseCat(Provider):
@@ -49,11 +50,8 @@ class WiseCat(Provider):
49
50
  self.last_response = {}
50
51
  self.model = model
51
52
  self.system_prompt = system_prompt
52
- self.headers = {
53
- "Content-Type": "application/json",
54
- "Accept": "*/*",
55
- "User-Agent": LitAgent().random()
56
- }
53
+ self.litagent = LitAgent()
54
+ self.headers = self.litagent.generate_fingerprint()
57
55
  self.session.headers.update(self.headers)
58
56
  self.session.proxies = proxies
59
57
 
@@ -81,7 +79,7 @@ class WiseCat(Provider):
81
79
  raw: bool = False,
82
80
  optimizer: str = None,
83
81
  conversationally: bool = False,
84
- ) -> Dict[str, Any] | Generator[Dict[str, Any], None, None]:
82
+ ) -> Union[Dict[str, Any], Generator[Any, None, None]]:
85
83
  """Chat with AI"""
86
84
  conversation_prompt = self.conversation.gen_complete_prompt(prompt)
87
85
  if optimizer:
@@ -120,11 +118,11 @@ class WiseCat(Provider):
120
118
  streaming_response = ""
121
119
  for line in response.iter_lines(decode_unicode=True):
122
120
  if line:
123
- if line.startswith("0:"):
124
- content = line[2:].strip('"')
121
+ match = re.search(r'0:"(.*?)"', line)
122
+ if match:
123
+ content = match.group(1)
125
124
  streaming_response += content
126
125
  yield content if raw else dict(text=content)
127
-
128
126
  self.last_response.update(dict(text=streaming_response))
129
127
  self.conversation.update_chat_history(
130
128
  prompt, self.get_message(self.last_response)
@@ -166,7 +164,7 @@ class WiseCat(Provider):
166
164
  def get_message(self, response: dict) -> str:
167
165
  """Retrieves message only from response"""
168
166
  assert isinstance(response, dict), "Response should be of dict data-type only"
169
- return response["text"]
167
+ return response["text"].replace('\\n', '\n').replace('\\n\\n', '\n\n')
170
168
 
171
169
  if __name__ == "__main__":
172
170
  print("-" * 80)
@@ -8,7 +8,7 @@ from webscout.AIutel import Conversation
8
8
  from webscout.AIutel import AwesomePrompts, sanitize_stream
9
9
  from webscout.AIbase import Provider, AsyncProvider
10
10
  from webscout import exceptions
11
- from typing import Any, AsyncGenerator, Dict
11
+ from typing import Union, Any, AsyncGenerator, Dict
12
12
 
13
13
  import cloudscraper
14
14
 
@@ -78,8 +78,20 @@ from .GithubChat import *
78
78
  from .copilot import *
79
79
  from .C4ai import *
80
80
  from .flowith import *
81
+ from .sonus import *
82
+ from .uncovr import *
83
+ from .labyrinth import *
84
+ from .WebSim import *
85
+ from .LambdaChat import *
86
+ from .ChatGPTClone import *
87
+ from .VercelAI import *
88
+ from .ExaChat import *
89
+ from .asksteve import *
90
+ from .Aitopia import *
91
+ from .searchchat import *
81
92
  __all__ = [
82
93
  'LLAMA',
94
+ 'LabyrinthAI',
83
95
  'Flowith',
84
96
  'C4ai',
85
97
  'Venice',
@@ -95,7 +107,7 @@ __all__ = [
95
107
  'IBMGranite',
96
108
  'QwenLM',
97
109
  'ChatGPTGratis',
98
-
110
+ 'LambdaChat',
99
111
  'TextPollinationsAI',
100
112
  'GliderAI',
101
113
  'Cohere',
@@ -134,8 +146,10 @@ __all__ = [
134
146
  'Cerebras',
135
147
  'Lepton',
136
148
  'GEMINIAPI',
149
+ 'SonusAI',
137
150
  'Cleeai',
138
151
  'Elmo',
152
+ 'ChatGPTClone',
139
153
  'Free2GPT',
140
154
  'GPTWeb',
141
155
  'Netwrck',
@@ -160,4 +174,11 @@ __all__ = [
160
174
  'FreeAIChat',
161
175
  'ElectronHub',
162
176
  'GithubChat',
177
+ 'UncovrAI',
178
+ 'WebSim',
179
+ 'VercelAI',
180
+ 'ExaChat',
181
+ 'AskSteve',
182
+ 'Aitopia',
183
+ 'SearchChatAI',
163
184
  ]
@@ -2,7 +2,7 @@ import requests
2
2
  import json
3
3
  import html
4
4
  import re
5
- from typing import Any, Dict
5
+ from typing import Union, Any, Dict
6
6
 
7
7
  from webscout.AIutel import Optimizers
8
8
  from webscout.AIutel import Conversation
@@ -8,7 +8,7 @@ from webscout.AIutel import Conversation
8
8
  from webscout.AIutel import AwesomePrompts, sanitize_stream
9
9
  from webscout.AIbase import Provider, AsyncProvider
10
10
  from webscout import exceptions
11
-
11
+ from webscout.litagent import LitAgent
12
12
 
13
13
  class AIMathGPT(Provider):
14
14
  """
@@ -58,11 +58,7 @@ class AIMathGPT(Provider):
58
58
  "sec-fetch-dest": "empty",
59
59
  "sec-fetch-mode": "cors",
60
60
  "sec-fetch-site": "same-origin",
61
- "user-agent": (
62
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
63
- "AppleWebKit/537.36 (KHTML, like Gecko) "
64
- "Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"
65
- ),
61
+ "user-agent": LitAgent().random(),
66
62
  }
67
63
  self.session = requests.Session()
68
64
  self.session.headers.update(self.headers)
@@ -1,4 +1,4 @@
1
- from typing import Any, Dict, Generator
1
+ from typing import Union, Any, Dict, Generator
2
2
  from uuid import uuid4
3
3
  import requests
4
4
  import re
@@ -1,14 +1,14 @@
1
1
  import requests
2
2
  import json
3
3
  import re
4
- from typing import Any, Dict, Optional, Generator
4
+ from typing import Union, Any, Dict, Optional, Generator
5
5
 
6
6
  from webscout.AIutel import Optimizers
7
7
  from webscout.AIutel import Conversation
8
8
  from webscout.AIutel import AwesomePrompts
9
9
  from webscout.AIbase import Provider
10
10
  from webscout import exceptions
11
- from webscout import LitAgent as UserAgent
11
+ from webscout.litagent import LitAgent as UserAgent
12
12
 
13
13
  class AskMyAI(Provider):
14
14
  """
@@ -68,7 +68,7 @@ class AskMyAI(Provider):
68
68
  raw: bool = False,
69
69
  optimizer: str = None,
70
70
  conversationally: bool = False,
71
- ) -> Dict[str, Any] | Generator[Dict[str, Any], None, None]:
71
+ ) -> Union[Dict[str, Any], Generator[Any, None, None]]:
72
72
  """Sends a prompt to the askmyai.chat API and returns the response."""
73
73
  conversation_prompt = self.conversation.gen_complete_prompt(prompt)
74
74
  if optimizer:
@@ -125,7 +125,7 @@ class AskMyAI(Provider):
125
125
  stream: bool = False,
126
126
  optimizer: str = None,
127
127
  conversationally: bool = False,
128
- ) -> str | Generator[str, None, None]:
128
+ ) -> Union[str, Generator[str, None, None]]:
129
129
  """Generates a response from the AskMyAI API."""
130
130
 
131
131
  def for_stream():
@@ -0,0 +1,203 @@
1
+ import requests
2
+ from webscout.AIutel import Optimizers
3
+ from webscout.AIutel import Conversation
4
+ from webscout.AIutel import AwesomePrompts
5
+ from webscout.AIbase import Provider
6
+ from webscout.litagent import LitAgent
7
+
8
+ class AskSteve(Provider):
9
+ """
10
+ A class to interact with the AskSteve API.
11
+ """
12
+ AVAILABLE_MODELS = ["Gemini"]
13
+ def __init__(
14
+ self,
15
+ is_conversation: bool = True,
16
+ max_tokens: int = 600,
17
+ timeout: int = 30,
18
+ intro: str = None,
19
+ filepath: str = None,
20
+ update_file: bool = True,
21
+ proxies: dict = {},
22
+ history_offset: int = 10250,
23
+ act: str = None,
24
+ ) -> None:
25
+ """Instantiates AskSteve
26
+
27
+ Args:
28
+ is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
29
+ max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
30
+ timeout (int, optional): Http request timeout. Defaults to 30.
31
+ intro (str, optional): Conversation introductory prompt. Defaults to None.
32
+ filepath (str, optional): Path to file containing conversation history. Defaults to None.
33
+ update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
34
+ proxies (dict, optional): Http request proxies. Defaults to {}.
35
+ history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
36
+ act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
37
+ system_prompt (str, optional): System prompt for AskSteve. Defaults to the provided string.
38
+ """
39
+ self.session = requests.Session()
40
+ self.is_conversation = is_conversation
41
+ self.max_tokens_to_sample = max_tokens
42
+ self.api_endpoint = "https://quickstart.asksteve.to/quickStartRequest"
43
+ self.timeout = timeout
44
+ self.last_response = {}
45
+ self.headers = {
46
+ "accept": "*/*",
47
+ "accept-encoding": "gzip, deflate, br, zstd",
48
+ "accept-language": "en-US,en;q=0.9",
49
+ "content-type": "text/plain;charset=UTF-8",
50
+ "origin": "chrome-extension://gldebcpkoojijledacjeboaehblhfbjg",
51
+ "priority": "u=1, i",
52
+ "sec-fetch-dest": "empty",
53
+ "sec-fetch-mode": "cors",
54
+ "sec-fetch-site": "none",
55
+ "sec-fetch-storage-access": "active",
56
+ "user-agent": LitAgent().random(),
57
+ }
58
+
59
+ self.__available_optimizers = (
60
+ method
61
+ for method in dir(Optimizers)
62
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
63
+ )
64
+ self.session.headers.update(self.headers)
65
+ Conversation.intro = (
66
+ AwesomePrompts().get_act(
67
+ act, raise_not_found=True, default=None, case_insensitive=True
68
+ )
69
+ if act
70
+ else intro or Conversation.intro
71
+ )
72
+ self.conversation = Conversation(
73
+ is_conversation, self.max_tokens_to_sample, filepath, update_file
74
+ )
75
+ self.conversation.history_offset = history_offset
76
+ self.session.proxies = proxies
77
+
78
+ def ask(
79
+ self,
80
+ prompt: str,
81
+ stream: bool = False,
82
+ raw: bool = False,
83
+ optimizer: str = None,
84
+ conversationally: bool = False,
85
+ ) -> dict:
86
+ """Chat with AI
87
+
88
+ Args:
89
+ prompt (str): Prompt to be send.
90
+ stream (bool, optional): Flag for streaming response. Defaults to False.
91
+ raw (bool, optional): Stream back raw response as received. Defaults to False.
92
+ optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
93
+ conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
94
+ Returns:
95
+ dict : {}
96
+ ```json
97
+ {
98
+ "text" : "How may I assist you today?"
99
+ }
100
+ ```
101
+ """
102
+ conversation_prompt = self.conversation.gen_complete_prompt(prompt)
103
+ if optimizer:
104
+ if optimizer in self.__available_optimizers:
105
+ conversation_prompt = getattr(Optimizers, optimizer)(
106
+ conversation_prompt if conversationally else prompt
107
+ )
108
+ else:
109
+ raise Exception(
110
+ f"Optimizer is not one of {self.__available_optimizers}"
111
+ )
112
+
113
+ payload = {
114
+ "key": "asksteve",
115
+ "prompt": conversation_prompt
116
+ }
117
+
118
+ def for_stream():
119
+ response = self.session.post(
120
+ self.api_endpoint,
121
+ headers=self.headers,
122
+ json=payload,
123
+ stream=True,
124
+ timeout=self.timeout,
125
+ )
126
+ if not response.ok:
127
+ raise Exception(
128
+ f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
129
+ )
130
+
131
+ response_data = response.json()
132
+ if "candidates" in response_data and len(response_data["candidates"]) > 0:
133
+ text = response_data["candidates"][0]["content"]["parts"][0]["text"]
134
+ self.last_response.update(dict(text=text))
135
+ yield dict(text=text) if not raw else text
136
+ else:
137
+ raise Exception("No response generated")
138
+
139
+ self.conversation.update_chat_history(
140
+ prompt, self.get_message(self.last_response)
141
+ )
142
+
143
+ def for_non_stream():
144
+ for _ in for_stream():
145
+ pass
146
+ return self.last_response
147
+
148
+ return for_stream() if stream else for_non_stream()
149
+
150
+ def chat(
151
+ self,
152
+ prompt: str,
153
+ stream: bool = False,
154
+ optimizer: str = None,
155
+ conversationally: bool = False,
156
+ ) -> str:
157
+ """Generate response `str`
158
+ Args:
159
+ prompt (str): Prompt to be send.
160
+ stream (bool, optional): Flag for streaming response. Defaults to False.
161
+ optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
162
+ conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
163
+ Returns:
164
+ str: Response generated
165
+ """
166
+
167
+ def for_stream():
168
+ for response in self.ask(
169
+ prompt, True, optimizer=optimizer, conversationally=conversationally
170
+ ):
171
+ yield self.get_message(response)
172
+
173
+ def for_non_stream():
174
+ return self.get_message(
175
+ self.ask(
176
+ prompt,
177
+ False,
178
+ optimizer=optimizer,
179
+ conversationally=conversationally,
180
+ )
181
+ )
182
+
183
+ return for_stream() if stream else for_non_stream()
184
+
185
+ def get_message(self, response: dict) -> str:
186
+ """Retrieves message only from response
187
+
188
+ Args:
189
+ response (dict): Response generated by `self.ask`
190
+
191
+ Returns:
192
+ str: Message extracted
193
+ """
194
+ assert isinstance(response, dict), "Response should be of dict data-type only"
195
+ return response["text"]
196
+
197
+
198
+ if __name__ == "__main__":
199
+ from rich import print
200
+ ai = AskSteve()
201
+ response = ai.chat("hi", stream=True)
202
+ for chunk in response:
203
+ print(chunk, end="", flush=True)
@@ -61,7 +61,7 @@ class Bagoodex(Provider):
61
61
  raw: bool = False,
62
62
  optimizer: str = None,
63
63
  conversationally: bool = False,
64
- ) -> Dict[str, Any] | Generator:
64
+ ) -> Union[Dict[str, Any], Generator[Any, None, None]]:
65
65
  """Sends a chat completion request to the Bagoodex API."""
66
66
 
67
67
  conversation_prompt = self.conversation.gen_complete_prompt(prompt)
@@ -113,7 +113,7 @@ class Bagoodex(Provider):
113
113
  stream: bool = False,
114
114
  optimizer: str = None,
115
115
  conversationally: bool = False,
116
- ) -> Union[str, Generator]:
116
+ ) -> Union[str, Generator[str, None, None]]:
117
117
 
118
118
 
119
119
  def for_stream():
@@ -7,7 +7,7 @@ from typing import Any, Dict, Optional, Generator, List, Union
7
7
  from webscout.AIutel import Optimizers, Conversation, AwesomePrompts
8
8
  from webscout.AIbase import Provider
9
9
  from webscout import exceptions
10
- from webscout import LitAgent as UserAgent
10
+ from webscout.litagent import LitAgent as UserAgent
11
11
 
12
12
  class Cerebras(Provider):
13
13
  """
@@ -7,8 +7,8 @@ from webscout.AIutel import Optimizers
7
7
  from webscout.AIutel import Conversation
8
8
  from webscout.AIutel import AwesomePrompts
9
9
  from webscout.AIbase import Provider
10
- from webscout import exceptions, LitAgent
11
-
10
+ from webscout import exceptions
11
+ from webscout.litagent import LitAgent
12
12
 
13
13
  class ChatGLM(Provider):
14
14
  """
@@ -75,7 +75,7 @@ class ChatGLM(Provider):
75
75
  raw: bool = False,
76
76
  optimizer: str = None,
77
77
  conversationally: bool = False,
78
- ) -> Dict[str, Any] | Generator[Dict[str, Any], None, None]:
78
+ ) -> Union[Dict[str, Any], Generator[Any, None, None]]:
79
79
  """Chat with AI
80
80
  Args:
81
81
  prompt (str): Prompt to be sent.
@@ -170,7 +170,7 @@ class ChatGLM(Provider):
170
170
  stream: bool = False,
171
171
  optimizer: str = None,
172
172
  conversationally: bool = False,
173
- ) -> str | Generator[str, None, None]:
173
+ ) -> Union[str, Generator[str, None, None]]:
174
174
  """Generate response `str`"""
175
175
 
176
176
  def for_stream():