webscout 8.2.2__py3-none-any.whl → 8.2.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 (306) hide show
  1. webscout/AIauto.py +112 -22
  2. webscout/AIbase.py +144 -7
  3. webscout/AIutel.py +249 -131
  4. webscout/Bard.py +579 -206
  5. webscout/DWEBS.py +78 -35
  6. webscout/__init__.py +0 -1
  7. webscout/cli.py +256 -0
  8. webscout/conversation.py +307 -436
  9. webscout/exceptions.py +23 -0
  10. webscout/prompt_manager.py +56 -42
  11. webscout/version.py +1 -1
  12. webscout/webscout_search.py +65 -47
  13. webscout/webscout_search_async.py +81 -126
  14. webscout/yep_search.py +93 -43
  15. {webscout-8.2.2.dist-info → webscout-8.2.7.dist-info}/METADATA +172 -52
  16. webscout-8.2.7.dist-info/RECORD +26 -0
  17. {webscout-8.2.2.dist-info → webscout-8.2.7.dist-info}/WHEEL +1 -1
  18. webscout-8.2.7.dist-info/entry_points.txt +3 -0
  19. webscout-8.2.7.dist-info/top_level.txt +1 -0
  20. inferno/__init__.py +0 -6
  21. inferno/__main__.py +0 -9
  22. inferno/cli.py +0 -6
  23. webscout/Extra/GitToolkit/__init__.py +0 -10
  24. webscout/Extra/GitToolkit/gitapi/__init__.py +0 -12
  25. webscout/Extra/GitToolkit/gitapi/repository.py +0 -195
  26. webscout/Extra/GitToolkit/gitapi/user.py +0 -96
  27. webscout/Extra/GitToolkit/gitapi/utils.py +0 -62
  28. webscout/Extra/YTToolkit/YTdownloader.py +0 -957
  29. webscout/Extra/YTToolkit/__init__.py +0 -3
  30. webscout/Extra/YTToolkit/transcriber.py +0 -476
  31. webscout/Extra/YTToolkit/ytapi/__init__.py +0 -6
  32. webscout/Extra/YTToolkit/ytapi/channel.py +0 -307
  33. webscout/Extra/YTToolkit/ytapi/errors.py +0 -13
  34. webscout/Extra/YTToolkit/ytapi/extras.py +0 -45
  35. webscout/Extra/YTToolkit/ytapi/https.py +0 -88
  36. webscout/Extra/YTToolkit/ytapi/patterns.py +0 -61
  37. webscout/Extra/YTToolkit/ytapi/playlist.py +0 -59
  38. webscout/Extra/YTToolkit/ytapi/pool.py +0 -8
  39. webscout/Extra/YTToolkit/ytapi/query.py +0 -40
  40. webscout/Extra/YTToolkit/ytapi/stream.py +0 -63
  41. webscout/Extra/YTToolkit/ytapi/utils.py +0 -62
  42. webscout/Extra/YTToolkit/ytapi/video.py +0 -232
  43. webscout/Extra/__init__.py +0 -7
  44. webscout/Extra/autocoder/__init__.py +0 -9
  45. webscout/Extra/autocoder/autocoder.py +0 -849
  46. webscout/Extra/autocoder/autocoder_utiles.py +0 -332
  47. webscout/Extra/gguf.py +0 -682
  48. webscout/Extra/tempmail/__init__.py +0 -28
  49. webscout/Extra/tempmail/async_utils.py +0 -141
  50. webscout/Extra/tempmail/base.py +0 -161
  51. webscout/Extra/tempmail/cli.py +0 -187
  52. webscout/Extra/tempmail/emailnator.py +0 -84
  53. webscout/Extra/tempmail/mail_tm.py +0 -361
  54. webscout/Extra/tempmail/temp_mail_io.py +0 -292
  55. webscout/Extra/weather.py +0 -194
  56. webscout/Extra/weather_ascii.py +0 -76
  57. webscout/LLM.py +0 -442
  58. webscout/Litlogger/__init__.py +0 -67
  59. webscout/Litlogger/core/__init__.py +0 -6
  60. webscout/Litlogger/core/level.py +0 -23
  61. webscout/Litlogger/core/logger.py +0 -165
  62. webscout/Litlogger/handlers/__init__.py +0 -12
  63. webscout/Litlogger/handlers/console.py +0 -33
  64. webscout/Litlogger/handlers/file.py +0 -143
  65. webscout/Litlogger/handlers/network.py +0 -173
  66. webscout/Litlogger/styles/__init__.py +0 -7
  67. webscout/Litlogger/styles/colors.py +0 -249
  68. webscout/Litlogger/styles/formats.py +0 -458
  69. webscout/Litlogger/styles/text.py +0 -87
  70. webscout/Litlogger/utils/__init__.py +0 -6
  71. webscout/Litlogger/utils/detectors.py +0 -153
  72. webscout/Litlogger/utils/formatters.py +0 -200
  73. webscout/Local/__init__.py +0 -12
  74. webscout/Local/__main__.py +0 -9
  75. webscout/Local/api.py +0 -576
  76. webscout/Local/cli.py +0 -516
  77. webscout/Local/config.py +0 -75
  78. webscout/Local/llm.py +0 -287
  79. webscout/Local/model_manager.py +0 -253
  80. webscout/Local/server.py +0 -721
  81. webscout/Local/utils.py +0 -93
  82. webscout/Provider/AI21.py +0 -177
  83. webscout/Provider/AISEARCH/DeepFind.py +0 -250
  84. webscout/Provider/AISEARCH/ISou.py +0 -256
  85. webscout/Provider/AISEARCH/Perplexity.py +0 -359
  86. webscout/Provider/AISEARCH/__init__.py +0 -10
  87. webscout/Provider/AISEARCH/felo_search.py +0 -228
  88. webscout/Provider/AISEARCH/genspark_search.py +0 -208
  89. webscout/Provider/AISEARCH/hika_search.py +0 -194
  90. webscout/Provider/AISEARCH/iask_search.py +0 -436
  91. webscout/Provider/AISEARCH/monica_search.py +0 -246
  92. webscout/Provider/AISEARCH/scira_search.py +0 -324
  93. webscout/Provider/AISEARCH/webpilotai_search.py +0 -281
  94. webscout/Provider/Aitopia.py +0 -292
  95. webscout/Provider/AllenAI.py +0 -413
  96. webscout/Provider/Andi.py +0 -228
  97. webscout/Provider/Blackboxai.py +0 -229
  98. webscout/Provider/C4ai.py +0 -432
  99. webscout/Provider/ChatGPTClone.py +0 -226
  100. webscout/Provider/ChatGPTES.py +0 -237
  101. webscout/Provider/ChatGPTGratis.py +0 -194
  102. webscout/Provider/Chatify.py +0 -175
  103. webscout/Provider/Cloudflare.py +0 -273
  104. webscout/Provider/Cohere.py +0 -208
  105. webscout/Provider/DeepSeek.py +0 -196
  106. webscout/Provider/Deepinfra.py +0 -297
  107. webscout/Provider/ElectronHub.py +0 -709
  108. webscout/Provider/ExaAI.py +0 -261
  109. webscout/Provider/ExaChat.py +0 -342
  110. webscout/Provider/Free2GPT.py +0 -241
  111. webscout/Provider/GPTWeb.py +0 -193
  112. webscout/Provider/Gemini.py +0 -169
  113. webscout/Provider/GithubChat.py +0 -367
  114. webscout/Provider/Glider.py +0 -211
  115. webscout/Provider/Groq.py +0 -670
  116. webscout/Provider/HF_space/__init__.py +0 -0
  117. webscout/Provider/HF_space/qwen_qwen2.py +0 -206
  118. webscout/Provider/HeckAI.py +0 -233
  119. webscout/Provider/HuggingFaceChat.py +0 -462
  120. webscout/Provider/Hunyuan.py +0 -272
  121. webscout/Provider/Jadve.py +0 -266
  122. webscout/Provider/Koboldai.py +0 -381
  123. webscout/Provider/LambdaChat.py +0 -392
  124. webscout/Provider/Llama.py +0 -200
  125. webscout/Provider/Llama3.py +0 -204
  126. webscout/Provider/Marcus.py +0 -148
  127. webscout/Provider/Netwrck.py +0 -228
  128. webscout/Provider/OLLAMA.py +0 -396
  129. webscout/Provider/OPENAI/__init__.py +0 -25
  130. webscout/Provider/OPENAI/base.py +0 -46
  131. webscout/Provider/OPENAI/c4ai.py +0 -367
  132. webscout/Provider/OPENAI/chatgpt.py +0 -549
  133. webscout/Provider/OPENAI/chatgptclone.py +0 -460
  134. webscout/Provider/OPENAI/deepinfra.py +0 -272
  135. webscout/Provider/OPENAI/e2b.py +0 -1350
  136. webscout/Provider/OPENAI/exaai.py +0 -404
  137. webscout/Provider/OPENAI/exachat.py +0 -433
  138. webscout/Provider/OPENAI/freeaichat.py +0 -352
  139. webscout/Provider/OPENAI/glider.py +0 -316
  140. webscout/Provider/OPENAI/heckai.py +0 -337
  141. webscout/Provider/OPENAI/llmchatco.py +0 -327
  142. webscout/Provider/OPENAI/netwrck.py +0 -348
  143. webscout/Provider/OPENAI/opkfc.py +0 -488
  144. webscout/Provider/OPENAI/scirachat.py +0 -463
  145. webscout/Provider/OPENAI/sonus.py +0 -294
  146. webscout/Provider/OPENAI/standardinput.py +0 -425
  147. webscout/Provider/OPENAI/textpollinations.py +0 -285
  148. webscout/Provider/OPENAI/toolbaz.py +0 -405
  149. webscout/Provider/OPENAI/typegpt.py +0 -346
  150. webscout/Provider/OPENAI/uncovrAI.py +0 -455
  151. webscout/Provider/OPENAI/utils.py +0 -211
  152. webscout/Provider/OPENAI/venice.py +0 -413
  153. webscout/Provider/OPENAI/wisecat.py +0 -381
  154. webscout/Provider/OPENAI/writecream.py +0 -156
  155. webscout/Provider/OPENAI/x0gpt.py +0 -371
  156. webscout/Provider/OPENAI/yep.py +0 -327
  157. webscout/Provider/OpenGPT.py +0 -199
  158. webscout/Provider/Openai.py +0 -496
  159. webscout/Provider/PI.py +0 -344
  160. webscout/Provider/Perplexitylabs.py +0 -415
  161. webscout/Provider/Phind.py +0 -535
  162. webscout/Provider/PizzaGPT.py +0 -198
  163. webscout/Provider/QwenLM.py +0 -254
  164. webscout/Provider/Reka.py +0 -214
  165. webscout/Provider/StandardInput.py +0 -278
  166. webscout/Provider/TTI/AiForce/__init__.py +0 -22
  167. webscout/Provider/TTI/AiForce/async_aiforce.py +0 -224
  168. webscout/Provider/TTI/AiForce/sync_aiforce.py +0 -245
  169. webscout/Provider/TTI/FreeAIPlayground/__init__.py +0 -9
  170. webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +0 -181
  171. webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +0 -180
  172. webscout/Provider/TTI/ImgSys/__init__.py +0 -23
  173. webscout/Provider/TTI/ImgSys/async_imgsys.py +0 -202
  174. webscout/Provider/TTI/ImgSys/sync_imgsys.py +0 -195
  175. webscout/Provider/TTI/MagicStudio/__init__.py +0 -2
  176. webscout/Provider/TTI/MagicStudio/async_magicstudio.py +0 -111
  177. webscout/Provider/TTI/MagicStudio/sync_magicstudio.py +0 -109
  178. webscout/Provider/TTI/Nexra/__init__.py +0 -22
  179. webscout/Provider/TTI/Nexra/async_nexra.py +0 -286
  180. webscout/Provider/TTI/Nexra/sync_nexra.py +0 -258
  181. webscout/Provider/TTI/PollinationsAI/__init__.py +0 -23
  182. webscout/Provider/TTI/PollinationsAI/async_pollinations.py +0 -311
  183. webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +0 -265
  184. webscout/Provider/TTI/__init__.py +0 -12
  185. webscout/Provider/TTI/aiarta/__init__.py +0 -2
  186. webscout/Provider/TTI/aiarta/async_aiarta.py +0 -482
  187. webscout/Provider/TTI/aiarta/sync_aiarta.py +0 -440
  188. webscout/Provider/TTI/artbit/__init__.py +0 -22
  189. webscout/Provider/TTI/artbit/async_artbit.py +0 -155
  190. webscout/Provider/TTI/artbit/sync_artbit.py +0 -148
  191. webscout/Provider/TTI/fastflux/__init__.py +0 -22
  192. webscout/Provider/TTI/fastflux/async_fastflux.py +0 -261
  193. webscout/Provider/TTI/fastflux/sync_fastflux.py +0 -252
  194. webscout/Provider/TTI/huggingface/__init__.py +0 -22
  195. webscout/Provider/TTI/huggingface/async_huggingface.py +0 -199
  196. webscout/Provider/TTI/huggingface/sync_huggingface.py +0 -195
  197. webscout/Provider/TTI/piclumen/__init__.py +0 -23
  198. webscout/Provider/TTI/piclumen/async_piclumen.py +0 -268
  199. webscout/Provider/TTI/piclumen/sync_piclumen.py +0 -233
  200. webscout/Provider/TTI/pixelmuse/__init__.py +0 -4
  201. webscout/Provider/TTI/pixelmuse/async_pixelmuse.py +0 -249
  202. webscout/Provider/TTI/pixelmuse/sync_pixelmuse.py +0 -182
  203. webscout/Provider/TTI/talkai/__init__.py +0 -4
  204. webscout/Provider/TTI/talkai/async_talkai.py +0 -229
  205. webscout/Provider/TTI/talkai/sync_talkai.py +0 -207
  206. webscout/Provider/TTS/__init__.py +0 -7
  207. webscout/Provider/TTS/deepgram.py +0 -156
  208. webscout/Provider/TTS/elevenlabs.py +0 -111
  209. webscout/Provider/TTS/gesserit.py +0 -127
  210. webscout/Provider/TTS/murfai.py +0 -113
  211. webscout/Provider/TTS/parler.py +0 -111
  212. webscout/Provider/TTS/speechma.py +0 -180
  213. webscout/Provider/TTS/streamElements.py +0 -333
  214. webscout/Provider/TTS/utils.py +0 -280
  215. webscout/Provider/TeachAnything.py +0 -187
  216. webscout/Provider/TextPollinationsAI.py +0 -231
  217. webscout/Provider/TwoAI.py +0 -199
  218. webscout/Provider/Venice.py +0 -219
  219. webscout/Provider/VercelAI.py +0 -234
  220. webscout/Provider/WebSim.py +0 -228
  221. webscout/Provider/WiseCat.py +0 -196
  222. webscout/Provider/Writecream.py +0 -211
  223. webscout/Provider/WritingMate.py +0 -197
  224. webscout/Provider/Youchat.py +0 -330
  225. webscout/Provider/__init__.py +0 -198
  226. webscout/Provider/ai4chat.py +0 -202
  227. webscout/Provider/aimathgpt.py +0 -189
  228. webscout/Provider/akashgpt.py +0 -342
  229. webscout/Provider/askmyai.py +0 -158
  230. webscout/Provider/asksteve.py +0 -203
  231. webscout/Provider/bagoodex.py +0 -145
  232. webscout/Provider/cerebras.py +0 -242
  233. webscout/Provider/chatglm.py +0 -205
  234. webscout/Provider/cleeai.py +0 -213
  235. webscout/Provider/copilot.py +0 -428
  236. webscout/Provider/elmo.py +0 -234
  237. webscout/Provider/freeaichat.py +0 -271
  238. webscout/Provider/gaurish.py +0 -244
  239. webscout/Provider/geminiapi.py +0 -208
  240. webscout/Provider/geminiprorealtime.py +0 -160
  241. webscout/Provider/granite.py +0 -187
  242. webscout/Provider/hermes.py +0 -219
  243. webscout/Provider/julius.py +0 -223
  244. webscout/Provider/koala.py +0 -268
  245. webscout/Provider/labyrinth.py +0 -340
  246. webscout/Provider/learnfastai.py +0 -266
  247. webscout/Provider/lepton.py +0 -194
  248. webscout/Provider/llama3mitril.py +0 -180
  249. webscout/Provider/llamatutor.py +0 -192
  250. webscout/Provider/llmchat.py +0 -213
  251. webscout/Provider/llmchatco.py +0 -311
  252. webscout/Provider/meta.py +0 -794
  253. webscout/Provider/multichat.py +0 -325
  254. webscout/Provider/promptrefine.py +0 -193
  255. webscout/Provider/scira_chat.py +0 -277
  256. webscout/Provider/scnet.py +0 -187
  257. webscout/Provider/searchchat.py +0 -293
  258. webscout/Provider/sonus.py +0 -208
  259. webscout/Provider/talkai.py +0 -194
  260. webscout/Provider/toolbaz.py +0 -320
  261. webscout/Provider/turboseek.py +0 -219
  262. webscout/Provider/tutorai.py +0 -252
  263. webscout/Provider/typefully.py +0 -280
  264. webscout/Provider/typegpt.py +0 -232
  265. webscout/Provider/uncovr.py +0 -312
  266. webscout/Provider/x0gpt.py +0 -256
  267. webscout/Provider/yep.py +0 -376
  268. webscout/litagent/__init__.py +0 -29
  269. webscout/litagent/agent.py +0 -455
  270. webscout/litagent/constants.py +0 -60
  271. webscout/litprinter/__init__.py +0 -59
  272. webscout/scout/__init__.py +0 -8
  273. webscout/scout/core/__init__.py +0 -7
  274. webscout/scout/core/crawler.py +0 -140
  275. webscout/scout/core/scout.py +0 -568
  276. webscout/scout/core/search_result.py +0 -96
  277. webscout/scout/core/text_analyzer.py +0 -63
  278. webscout/scout/core/text_utils.py +0 -277
  279. webscout/scout/core/web_analyzer.py +0 -52
  280. webscout/scout/core.py +0 -881
  281. webscout/scout/element.py +0 -460
  282. webscout/scout/parsers/__init__.py +0 -69
  283. webscout/scout/parsers/html5lib_parser.py +0 -172
  284. webscout/scout/parsers/html_parser.py +0 -236
  285. webscout/scout/parsers/lxml_parser.py +0 -178
  286. webscout/scout/utils.py +0 -37
  287. webscout/swiftcli/__init__.py +0 -809
  288. webscout/zeroart/__init__.py +0 -55
  289. webscout/zeroart/base.py +0 -60
  290. webscout/zeroart/effects.py +0 -99
  291. webscout/zeroart/fonts.py +0 -816
  292. webscout-8.2.2.dist-info/RECORD +0 -309
  293. webscout-8.2.2.dist-info/entry_points.txt +0 -5
  294. webscout-8.2.2.dist-info/top_level.txt +0 -3
  295. webstoken/__init__.py +0 -30
  296. webstoken/classifier.py +0 -189
  297. webstoken/keywords.py +0 -216
  298. webstoken/language.py +0 -128
  299. webstoken/ner.py +0 -164
  300. webstoken/normalizer.py +0 -35
  301. webstoken/processor.py +0 -77
  302. webstoken/sentiment.py +0 -206
  303. webstoken/stemmer.py +0 -73
  304. webstoken/tagger.py +0 -60
  305. webstoken/tokenizer.py +0 -158
  306. {webscout-8.2.2.dist-info → webscout-8.2.7.dist-info/licenses}/LICENSE.md +0 -0
@@ -1,324 +0,0 @@
1
- import requests
2
- import json
3
- import re
4
- import uuid
5
- import time
6
- from typing import Dict, Optional, Generator, Union, Any
7
-
8
- from webscout.AIbase import AISearch
9
- from webscout import exceptions
10
- from webscout.litagent import LitAgent
11
-
12
-
13
- class Response:
14
- """A wrapper class for SCIRA API responses.
15
-
16
- This class automatically converts response objects to their text representation
17
- when printed or converted to string.
18
-
19
- Attributes:
20
- text (str): The text content of the response
21
-
22
- Example:
23
- >>> response = Response("Hello, world!")
24
- >>> print(response)
25
- Hello, world!
26
- >>> str(response)
27
- 'Hello, world!'
28
- """
29
- def __init__(self, text: str):
30
- self.text = text
31
-
32
- def __str__(self):
33
- return self.text
34
-
35
- def __repr__(self):
36
- return self.text
37
-
38
-
39
- class Scira(AISearch):
40
- """A class to interact with the SCIRA AI search API.
41
-
42
- SCIRA provides a powerful search interface that returns AI-generated responses
43
- based on web content. It supports both streaming and non-streaming responses.
44
-
45
- Basic Usage:
46
- >>> from webscout import Scira
47
- >>> ai = Scira()
48
- >>> # Non-streaming example
49
- >>> response = ai.search("What is Python?")
50
- >>> print(response)
51
- Python is a high-level programming language...
52
-
53
- >>> # Streaming example
54
- >>> for chunk in ai.search("Tell me about AI", stream=True):
55
- ... print(chunk, end="", flush=True)
56
- Artificial Intelligence is...
57
-
58
- >>> # Raw response format
59
- >>> for chunk in ai.search("Hello", stream=True, raw=True):
60
- ... print(chunk)
61
- {'text': 'Hello'}
62
- {'text': ' there!'}
63
-
64
- Args:
65
- timeout (int, optional): Request timeout in seconds. Defaults to 60.
66
- proxies (dict, optional): Proxy configuration for requests. Defaults to None.
67
- model (str, optional): Model to use for the search. Defaults to "scira-default".
68
- group (str, optional): Group parameter. Defaults to "web".
69
- """
70
-
71
- AVAILABLE_MODELS = {
72
- "scira-default": "Grok3",
73
- "scira-grok-3-mini": "Grok3-mini", # thinking model
74
- "scira-vision" : "Grok2-Vision", # vision model
75
- "scira-4.1-mini": "GPT4.1-mini",
76
- "scira-qwq": "QWQ-32B",
77
- "scira-o4-mini": "o4-mini",
78
- "scira-google": "gemini 2.5 flash"
79
-
80
-
81
- }
82
-
83
- def __init__(
84
- self,
85
- timeout: int = 60,
86
- proxies: Optional[dict] = None,
87
- model: str = "scira-default",
88
- deepsearch: bool = False
89
- ):
90
- """Initialize the SCIRA API client.
91
-
92
- Args:
93
- timeout (int, optional): Request timeout in seconds. Defaults to 60.
94
- proxies (dict, optional): Proxy configuration for requests. Defaults to None.
95
- model (str, optional): Model to use for the search. Defaults to "scira-default" (Grok3).
96
- deepsearch (bool, optional): Whether to use deep search mode. If True, uses "extreme" group for more comprehensive results. If False, uses "web" group for faster results. Defaults to False.
97
-
98
- Example:
99
- >>> ai = Scira(timeout=120) # Longer timeout
100
- >>> ai = Scira(proxies={'http': 'http://proxy.com:8080'}) # With proxy
101
- >>> ai = Scira(model="scira-claude") # Use Claude model
102
- >>> ai = Scira(deepsearch=True) # Use deep search mode
103
- """
104
- # Validate model
105
- if model not in self.AVAILABLE_MODELS:
106
- raise ValueError(
107
- f"Invalid model: {model}. Choose from: {list(self.AVAILABLE_MODELS.keys())}"
108
- )
109
-
110
- self.session = requests.Session()
111
- self.api_endpoint = "https://scira.ai/api/search"
112
- self.timeout = timeout
113
- self.proxies = proxies
114
- self.model = model
115
-
116
- # Set group based on deepsearch parameter
117
- self.group = "extreme" if deepsearch else "web"
118
- self.last_response = {}
119
-
120
- # Set headers
121
- self.headers = {
122
- "Content-Type": "application/json",
123
- "Accept": "*/*",
124
- "User-Agent": LitAgent().random()
125
- }
126
-
127
- self.session.headers.update(self.headers)
128
-
129
- def search(
130
- self,
131
- prompt: str,
132
- stream: bool = False,
133
- raw: bool = False,
134
- ) -> Union[Response, Generator[Union[Dict[str, str], Response], None, None]]:
135
- """Search using the SCIRA API and get AI-generated responses.
136
-
137
- This method sends a search query to SCIRA and returns the AI-generated response.
138
- It supports both streaming and non-streaming modes, as well as raw response format.
139
-
140
- Args:
141
- prompt (str): The search query or prompt to send to the API.
142
- stream (bool, optional): If True, yields response chunks as they arrive.
143
- If False, returns complete response. Defaults to False.
144
- raw (bool, optional): If True, returns raw response dictionaries with 'text' key.
145
- If False, returns Response objects that convert to text automatically.
146
- Defaults to False.
147
-
148
- Returns:
149
- Union[Response, Generator[Union[Dict[str, str], Response], None, None]]:
150
- - If stream=False: Returns complete response
151
- - If stream=True: Yields response chunks as they arrive
152
-
153
- Raises:
154
- exceptions.APIConnectionError: If there's an issue connecting to the API
155
- exceptions.APIResponseError: If the API returns an error response
156
-
157
- Example:
158
- >>> ai = Scira()
159
- >>> # Non-streaming example
160
- >>> response = ai.search("What is Python?")
161
- >>> print(response)
162
- Python is a high-level programming language...
163
-
164
- >>> # Streaming example
165
- >>> for chunk in ai.search("Tell me about AI", stream=True):
166
- ... print(chunk, end="", flush=True)
167
- Artificial Intelligence is...
168
- """
169
- # Create a unique message ID
170
- message_id = str(uuid.uuid4()).replace("-", "")[:16]
171
- self.user_id = str(uuid.uuid4()).replace("-", "")[:16]
172
- # Prepare the payload
173
- payload = {
174
- "id": message_id,
175
- "messages": [
176
- {
177
- "role": "user",
178
- "content": prompt,
179
- "parts": [
180
- {
181
- "type": "text",
182
- "text": prompt
183
- }
184
- ]
185
- }
186
- ],
187
- "model": self.model,
188
- "group": self.group,
189
- "user_id": self.user_id,
190
- "timezone": "Asia/Calcutta"
191
- }
192
-
193
- try:
194
- # Send the request
195
- response = self.session.post(
196
- self.api_endpoint,
197
- headers=self.headers,
198
- data=json.dumps(payload),
199
- stream=True,
200
- timeout=self.timeout,
201
- proxies=self.proxies
202
- )
203
-
204
- # Check for successful response
205
- if response.status_code != 200:
206
- raise exceptions.APIResponseError(
207
- f"API returned error status: {response.status_code}"
208
- )
209
-
210
- # Store the last response
211
- self.last_response = {"status_code": response.status_code}
212
-
213
- # Handle streaming response
214
- if stream:
215
- return self._handle_streaming_response(response, raw)
216
-
217
- # Handle non-streaming response
218
- return self._handle_non_streaming_response(response, raw)
219
-
220
- except requests.RequestException as e:
221
- raise exceptions.APIConnectionError(f"Error connecting to API: {str(e)}")
222
-
223
- def _handle_streaming_response(
224
- self,
225
- response: requests.Response,
226
- raw: bool
227
- ) -> Generator[Union[Dict[str, str], Response], None, None]:
228
- """Handle streaming response from the API.
229
-
230
- Args:
231
- response (requests.Response): The streaming response from the API
232
- raw (bool): Whether to return raw response dictionaries
233
-
234
- Yields:
235
- Union[Dict[str, str], Response]: Response chunks as they arrive
236
- """
237
- for line in response.iter_lines():
238
- if line:
239
- try:
240
- # Decode the line
241
- decoded_line = line.decode("utf-8")
242
-
243
- # Check if this is a line starting with "0:" (content)
244
- if re.match(r'^0:', decoded_line):
245
- # Extract the content after "0:"
246
- content = re.sub(r'^0:', '', decoded_line)
247
- # Remove surrounding quotes if present
248
- content = re.sub(r'^"(.*)"$', r'\1', content)
249
- # Replace escaped newlines with actual newlines
250
- content = content.replace('\\n', '\n')
251
-
252
- if raw:
253
- yield {"text": content}
254
- else:
255
- yield Response(content)
256
- except Exception:
257
- # Skip lines that can't be processed
258
- pass
259
-
260
- def _handle_non_streaming_response(
261
- self,
262
- response: requests.Response,
263
- raw: bool
264
- ) -> Union[Dict[str, str], Response]:
265
- """Handle non-streaming response from the API.
266
-
267
- Args:
268
- response (requests.Response): The response from the API
269
- raw (bool): Whether to return raw response dictionary
270
-
271
- Returns:
272
- Union[Dict[str, str], Response]: Complete response
273
- """
274
- full_text = ""
275
-
276
- for line in response.iter_lines():
277
- if line:
278
- try:
279
- # Decode the line
280
- decoded_line = line.decode("utf-8")
281
-
282
- # Check if this is a line starting with "0:" (content)
283
- if re.match(r'^0:', decoded_line):
284
- # Extract the content after "0:"
285
- content = re.sub(r'^0:', '', decoded_line)
286
- # Remove surrounding quotes if present
287
- content = re.sub(r'^"(.*)"$', r'\1', content)
288
- # Replace escaped newlines with actual newlines
289
- content = content.replace('\\n', '\n')
290
- full_text += content
291
- except Exception:
292
- # Skip lines that can't be processed
293
- pass
294
-
295
- if raw:
296
- return {"text": full_text}
297
- else:
298
- return Response(full_text)
299
-
300
- @staticmethod
301
- def clean_content(text: str) -> str:
302
- """Clean the response content by removing unnecessary formatting.
303
-
304
- Args:
305
- text (str): The text to clean
306
-
307
- Returns:
308
- str: The cleaned text
309
- """
310
- # Remove any extra whitespace
311
- cleaned_text = re.sub(r'\s+', ' ', text)
312
- # Remove any trailing whitespace
313
- cleaned_text = cleaned_text.strip()
314
-
315
- return cleaned_text
316
-
317
-
318
- if __name__ == "__main__":
319
- from rich import print
320
- ai = Scira()
321
- user_query = input(">>> ")
322
- response = ai.search(user_query, stream=True, raw=False)
323
- for chunk in response:
324
- print(chunk, end="", flush=True)
@@ -1,281 +0,0 @@
1
- import requests
2
- import json
3
- import re
4
- from typing import Dict, Optional, Generator, Union, Any
5
-
6
- from webscout.AIbase import AISearch
7
- from webscout import exceptions
8
- from webscout.litagent import LitAgent
9
-
10
-
11
- class Response:
12
- """A wrapper class for webpilotai API responses.
13
-
14
- This class automatically converts response objects to their text representation
15
- when printed or converted to string.
16
-
17
- Attributes:
18
- text (str): The text content of the response
19
-
20
- Example:
21
- >>> response = Response("Hello, world!")
22
- >>> print(response)
23
- Hello, world!
24
- >>> str(response)
25
- 'Hello, world!'
26
- """
27
- def __init__(self, text: str):
28
- self.text = text
29
-
30
- def __str__(self):
31
- return self.text
32
-
33
- def __repr__(self):
34
- return self.text
35
-
36
-
37
- class webpilotai(AISearch):
38
- """A class to interact with the webpilotai (WebPilot) AI search API.
39
-
40
- webpilotai provides a web-based comprehensive search response interface that returns AI-generated
41
- responses with source references and related questions. It supports both streaming and
42
- non-streaming responses.
43
-
44
- Basic Usage:
45
- >>> from webscout import webpilotai
46
- >>> ai = webpilotai()
47
- >>> # Non-streaming example
48
- >>> response = ai.search("What is Python?")
49
- >>> print(response)
50
- Python is a high-level programming language...
51
-
52
- >>> # Streaming example
53
- >>> for chunk in ai.search("Tell me about AI", stream=True):
54
- ... print(chunk, end="", flush=True)
55
- Artificial Intelligence is...
56
-
57
- >>> # Raw response format
58
- >>> for chunk in ai.search("Hello", stream=True, raw=True):
59
- ... print(chunk)
60
- {'text': 'Hello'}
61
- {'text': ' there!'}
62
-
63
- Args:
64
- timeout (int, optional): Request timeout in seconds. Defaults to 90.
65
- proxies (dict, optional): Proxy configuration for requests. Defaults to None.
66
- """
67
-
68
- def __init__(
69
- self,
70
- timeout: int = 90,
71
- proxies: Optional[dict] = None,
72
- ):
73
- """Initialize the webpilotai API client.
74
-
75
- Args:
76
- timeout (int, optional): Request timeout in seconds. Defaults to 90.
77
- proxies (dict, optional): Proxy configuration for requests. Defaults to None.
78
-
79
- Example:
80
- >>> ai = webpilotai(timeout=120) # Longer timeout
81
- >>> ai = webpilotai(proxies={'http': 'http://proxy.com:8080'}) # With proxy
82
- """
83
- self.session = requests.Session()
84
- self.api_endpoint = "https://api.webpilotai.com/rupee/v1/search"
85
- self.timeout = timeout
86
- self.last_response = {}
87
-
88
- # The 'Bearer null' is part of the API's expected headers
89
- self.headers = {
90
- 'Accept': 'application/json, text/plain, */*, text/event-stream',
91
- 'Content-Type': 'application/json;charset=UTF-8',
92
- 'Authorization': 'Bearer null',
93
- 'Origin': 'https://www.webpilot.ai',
94
- 'Referer': 'https://www.webpilot.ai/',
95
- 'User-Agent': LitAgent().random(),
96
- }
97
-
98
- self.session.headers.update(self.headers)
99
- self.proxies = proxies
100
-
101
- def search(
102
- self,
103
- prompt: str,
104
- stream: bool = False,
105
- raw: bool = False,
106
- ) -> Union[Response, Generator[Union[Dict[str, str], Response], None, None]]:
107
- """Search using the webpilotai API and get AI-generated responses.
108
-
109
- This method sends a search query to webpilotai and returns the AI-generated response.
110
- It supports both streaming and non-streaming modes, as well as raw response format.
111
-
112
- Args:
113
- prompt (str): The search query or prompt to send to the API.
114
- stream (bool, optional): If True, yields response chunks as they arrive.
115
- If False, returns complete response. Defaults to False.
116
- raw (bool, optional): If True, returns raw response dictionaries with 'text' key.
117
- If False, returns Response objects that convert to text automatically.
118
- Defaults to False.
119
-
120
- Returns:
121
- Union[Response, Generator[Union[Dict[str, str], Response], None, None]]:
122
- - If stream=False: Returns complete response as Response object
123
- - If stream=True: Yields response chunks as either Dict or Response objects
124
-
125
- Raises:
126
- APIConnectionError: If the API request fails
127
-
128
- Examples:
129
- Basic search:
130
- >>> ai = webpilotai()
131
- >>> response = ai.search("What is Python?")
132
- >>> print(response)
133
- Python is a programming language...
134
-
135
- Streaming response:
136
- >>> for chunk in ai.search("Tell me about AI", stream=True):
137
- ... print(chunk, end="")
138
- Artificial Intelligence...
139
-
140
- Raw response format:
141
- >>> for chunk in ai.search("Hello", stream=True, raw=True):
142
- ... print(chunk)
143
- {'text': 'Hello'}
144
- {'text': ' there!'}
145
- """
146
- payload = {
147
- "q": prompt,
148
- "threadId": "" # Empty for new search
149
- }
150
-
151
- def for_stream():
152
- full_response_content = ""
153
- current_event_name = None
154
- current_data_buffer = []
155
-
156
- try:
157
- with self.session.post(
158
- self.api_endpoint,
159
- json=payload,
160
- stream=True,
161
- timeout=self.timeout,
162
- proxies=self.proxies
163
- ) as response:
164
- if not response.ok:
165
- raise exceptions.APIConnectionError(
166
- f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
167
- )
168
-
169
- # Process the stream line by line
170
- for line in response.iter_lines(decode_unicode=True):
171
- if not line: # Empty line indicates end of an event
172
- if current_data_buffer:
173
- # Process the completed event
174
- full_data = "\n".join(current_data_buffer)
175
- if current_event_name == "message":
176
- try:
177
- data_payload = json.loads(full_data)
178
- # Check structure based on the API response
179
- if data_payload.get('type') == 'data':
180
- content_chunk = data_payload.get('data', {}).get('content', "")
181
- if content_chunk:
182
- full_response_content += content_chunk
183
-
184
- # Yield the new content chunk
185
- if raw:
186
- yield {"text": content_chunk}
187
- else:
188
- yield Response(content_chunk)
189
- except json.JSONDecodeError:
190
- pass
191
- except Exception as e:
192
- # Handle exceptions gracefully in stream processing
193
- pass
194
-
195
- # Reset for the next event
196
- current_event_name = None
197
- current_data_buffer = []
198
- continue
199
-
200
- # Parse SSE fields
201
- if line.startswith('event:'):
202
- current_event_name = line[len('event:'):].strip()
203
- elif line.startswith('data:'):
204
- data_part = line[len('data:'):]
205
- # Remove leading space if present (common in SSE)
206
- if data_part.startswith(' '):
207
- data_part = data_part[1:]
208
- current_data_buffer.append(data_part)
209
-
210
- # Process any remaining data in buffer if stream ended without blank line
211
- if current_data_buffer and current_event_name == "message":
212
- try:
213
- full_data = "\n".join(current_data_buffer)
214
- data_payload = json.loads(full_data)
215
- if data_payload.get('type') == 'data':
216
- content_chunk = data_payload.get('data', {}).get('content', "")
217
- if content_chunk and len(content_chunk) > len(full_response_content):
218
- delta = content_chunk[len(full_response_content):]
219
- full_response_content += delta
220
-
221
- if raw:
222
- yield {"text": delta}
223
- else:
224
- yield Response(delta)
225
- except (json.JSONDecodeError, Exception):
226
- pass
227
-
228
- except requests.exceptions.Timeout:
229
- raise exceptions.APIConnectionError("Request timed out")
230
- except requests.exceptions.RequestException as e:
231
- raise exceptions.APIConnectionError(f"Request failed: {e}")
232
-
233
- def for_non_stream():
234
- full_response = ""
235
- for chunk in for_stream():
236
- if raw:
237
- yield chunk
238
- else:
239
- full_response += str(chunk)
240
-
241
- if not raw:
242
- # Format the response for better readability
243
- formatted_response = self.format_response(full_response)
244
- self.last_response = Response(formatted_response)
245
- return self.last_response
246
-
247
- return for_stream() if stream else for_non_stream()
248
-
249
- @staticmethod
250
- def format_response(text: str) -> str:
251
- """Format the response text for better readability.
252
-
253
- Args:
254
- text (str): The raw response text
255
-
256
- Returns:
257
- str: Formatted text with improved structure
258
- """
259
- # Clean up formatting
260
- # Remove excessive newlines
261
- clean_text = re.sub(r'\n{3,}', '\n\n', text)
262
-
263
- # Ensure consistent spacing around sections
264
- clean_text = re.sub(r'([.!?])\s*\n\s*([A-Z])', r'\1\n\n\2', clean_text)
265
-
266
- # Clean up any leftover HTML or markdown artifacts
267
- clean_text = re.sub(r'<[^>]*>', '', clean_text)
268
-
269
- # Remove trailing whitespace on each line
270
- clean_text = '\n'.join(line.rstrip() for line in clean_text.split('\n'))
271
-
272
- return clean_text.strip()
273
-
274
-
275
- if __name__ == "__main__":
276
- from rich import print
277
-
278
- ai = webpilotai()
279
- response = ai.search(input(">>> "), stream=True, raw=False)
280
- for chunk in response:
281
- print(chunk, end="", flush=True)