webscout 8.2.9__py3-none-any.whl → 2026.1.19__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.
- webscout/AIauto.py +524 -251
- webscout/AIbase.py +247 -319
- webscout/AIutel.py +68 -703
- webscout/Bard.py +1072 -1026
- webscout/Extra/GitToolkit/__init__.py +10 -10
- webscout/Extra/GitToolkit/gitapi/__init__.py +20 -12
- webscout/Extra/GitToolkit/gitapi/gist.py +142 -0
- webscout/Extra/GitToolkit/gitapi/organization.py +91 -0
- webscout/Extra/GitToolkit/gitapi/repository.py +308 -195
- webscout/Extra/GitToolkit/gitapi/search.py +162 -0
- webscout/Extra/GitToolkit/gitapi/trending.py +236 -0
- webscout/Extra/GitToolkit/gitapi/user.py +128 -96
- webscout/Extra/GitToolkit/gitapi/utils.py +82 -62
- webscout/Extra/YTToolkit/README.md +443 -375
- webscout/Extra/YTToolkit/YTdownloader.py +953 -957
- webscout/Extra/YTToolkit/__init__.py +3 -3
- webscout/Extra/YTToolkit/transcriber.py +595 -476
- webscout/Extra/YTToolkit/ytapi/README.md +230 -44
- webscout/Extra/YTToolkit/ytapi/__init__.py +22 -6
- webscout/Extra/YTToolkit/ytapi/captions.py +190 -0
- webscout/Extra/YTToolkit/ytapi/channel.py +302 -307
- webscout/Extra/YTToolkit/ytapi/errors.py +13 -13
- webscout/Extra/YTToolkit/ytapi/extras.py +178 -118
- webscout/Extra/YTToolkit/ytapi/hashtag.py +120 -0
- webscout/Extra/YTToolkit/ytapi/https.py +89 -88
- webscout/Extra/YTToolkit/ytapi/patterns.py +61 -61
- webscout/Extra/YTToolkit/ytapi/playlist.py +59 -59
- webscout/Extra/YTToolkit/ytapi/pool.py +8 -8
- webscout/Extra/YTToolkit/ytapi/query.py +143 -40
- webscout/Extra/YTToolkit/ytapi/shorts.py +122 -0
- webscout/Extra/YTToolkit/ytapi/stream.py +68 -63
- webscout/Extra/YTToolkit/ytapi/suggestions.py +97 -0
- webscout/Extra/YTToolkit/ytapi/utils.py +66 -62
- webscout/Extra/YTToolkit/ytapi/video.py +403 -232
- webscout/Extra/__init__.py +2 -3
- webscout/Extra/gguf.py +1298 -684
- webscout/Extra/tempmail/README.md +487 -487
- webscout/Extra/tempmail/__init__.py +28 -28
- webscout/Extra/tempmail/async_utils.py +143 -141
- webscout/Extra/tempmail/base.py +172 -161
- webscout/Extra/tempmail/cli.py +191 -187
- webscout/Extra/tempmail/emailnator.py +88 -84
- webscout/Extra/tempmail/mail_tm.py +378 -361
- webscout/Extra/tempmail/temp_mail_io.py +304 -292
- webscout/Extra/weather.py +196 -194
- webscout/Extra/weather_ascii.py +17 -15
- webscout/Provider/AISEARCH/PERPLEXED_search.py +175 -0
- webscout/Provider/AISEARCH/Perplexity.py +292 -333
- webscout/Provider/AISEARCH/README.md +106 -279
- webscout/Provider/AISEARCH/__init__.py +16 -9
- webscout/Provider/AISEARCH/brave_search.py +298 -0
- webscout/Provider/AISEARCH/iask_search.py +357 -410
- webscout/Provider/AISEARCH/monica_search.py +200 -220
- webscout/Provider/AISEARCH/webpilotai_search.py +242 -255
- webscout/Provider/Algion.py +413 -0
- webscout/Provider/Andi.py +74 -69
- webscout/Provider/Apriel.py +313 -0
- webscout/Provider/Ayle.py +323 -0
- webscout/Provider/ChatSandbox.py +329 -342
- webscout/Provider/ClaudeOnline.py +365 -0
- webscout/Provider/Cohere.py +232 -208
- webscout/Provider/DeepAI.py +367 -0
- webscout/Provider/Deepinfra.py +467 -340
- webscout/Provider/EssentialAI.py +217 -0
- webscout/Provider/ExaAI.py +274 -261
- webscout/Provider/Gemini.py +175 -169
- webscout/Provider/GithubChat.py +385 -369
- webscout/Provider/Gradient.py +286 -0
- webscout/Provider/Groq.py +556 -801
- webscout/Provider/HadadXYZ.py +323 -0
- webscout/Provider/HeckAI.py +392 -375
- webscout/Provider/HuggingFace.py +387 -0
- webscout/Provider/IBM.py +340 -0
- webscout/Provider/Jadve.py +317 -291
- webscout/Provider/K2Think.py +306 -0
- webscout/Provider/Koboldai.py +221 -384
- webscout/Provider/Netwrck.py +273 -270
- webscout/Provider/Nvidia.py +310 -0
- webscout/Provider/OPENAI/DeepAI.py +489 -0
- webscout/Provider/OPENAI/K2Think.py +423 -0
- webscout/Provider/OPENAI/PI.py +463 -0
- webscout/Provider/OPENAI/README.md +890 -952
- webscout/Provider/OPENAI/TogetherAI.py +405 -0
- webscout/Provider/OPENAI/TwoAI.py +255 -357
- webscout/Provider/OPENAI/__init__.py +148 -40
- webscout/Provider/OPENAI/ai4chat.py +348 -293
- webscout/Provider/OPENAI/akashgpt.py +436 -0
- webscout/Provider/OPENAI/algion.py +303 -0
- webscout/Provider/OPENAI/{exachat.py → ayle.py} +365 -444
- webscout/Provider/OPENAI/base.py +253 -249
- webscout/Provider/OPENAI/cerebras.py +296 -0
- webscout/Provider/OPENAI/chatgpt.py +870 -556
- webscout/Provider/OPENAI/chatsandbox.py +233 -173
- webscout/Provider/OPENAI/deepinfra.py +403 -322
- webscout/Provider/OPENAI/e2b.py +2370 -1414
- webscout/Provider/OPENAI/elmo.py +278 -0
- webscout/Provider/OPENAI/exaai.py +452 -417
- webscout/Provider/OPENAI/freeassist.py +446 -0
- webscout/Provider/OPENAI/gradient.py +448 -0
- webscout/Provider/OPENAI/groq.py +380 -364
- webscout/Provider/OPENAI/hadadxyz.py +292 -0
- webscout/Provider/OPENAI/heckai.py +333 -308
- webscout/Provider/OPENAI/huggingface.py +321 -0
- webscout/Provider/OPENAI/ibm.py +425 -0
- webscout/Provider/OPENAI/llmchat.py +253 -0
- webscout/Provider/OPENAI/llmchatco.py +378 -335
- webscout/Provider/OPENAI/meta.py +541 -0
- webscout/Provider/OPENAI/netwrck.py +374 -357
- webscout/Provider/OPENAI/nvidia.py +317 -0
- webscout/Provider/OPENAI/oivscode.py +348 -287
- webscout/Provider/OPENAI/openrouter.py +328 -0
- webscout/Provider/OPENAI/pydantic_imports.py +1 -172
- webscout/Provider/OPENAI/sambanova.py +397 -0
- webscout/Provider/OPENAI/sonus.py +305 -304
- webscout/Provider/OPENAI/textpollinations.py +370 -339
- webscout/Provider/OPENAI/toolbaz.py +375 -413
- webscout/Provider/OPENAI/typefully.py +419 -355
- webscout/Provider/OPENAI/typliai.py +279 -0
- webscout/Provider/OPENAI/utils.py +314 -318
- webscout/Provider/OPENAI/wisecat.py +359 -387
- webscout/Provider/OPENAI/writecream.py +185 -163
- webscout/Provider/OPENAI/x0gpt.py +462 -365
- webscout/Provider/OPENAI/zenmux.py +380 -0
- webscout/Provider/OpenRouter.py +386 -0
- webscout/Provider/Openai.py +337 -496
- webscout/Provider/PI.py +443 -429
- webscout/Provider/QwenLM.py +346 -254
- webscout/Provider/STT/__init__.py +28 -0
- webscout/Provider/STT/base.py +303 -0
- webscout/Provider/STT/elevenlabs.py +264 -0
- webscout/Provider/Sambanova.py +317 -0
- webscout/Provider/TTI/README.md +69 -82
- webscout/Provider/TTI/__init__.py +37 -7
- webscout/Provider/TTI/base.py +147 -64
- webscout/Provider/TTI/claudeonline.py +393 -0
- webscout/Provider/TTI/magicstudio.py +292 -201
- webscout/Provider/TTI/miragic.py +180 -0
- webscout/Provider/TTI/pollinations.py +331 -221
- webscout/Provider/TTI/together.py +334 -0
- webscout/Provider/TTI/utils.py +14 -11
- webscout/Provider/TTS/README.md +186 -192
- webscout/Provider/TTS/__init__.py +43 -10
- webscout/Provider/TTS/base.py +523 -159
- webscout/Provider/TTS/deepgram.py +286 -156
- webscout/Provider/TTS/elevenlabs.py +189 -111
- webscout/Provider/TTS/freetts.py +218 -0
- webscout/Provider/TTS/murfai.py +288 -113
- webscout/Provider/TTS/openai_fm.py +364 -129
- webscout/Provider/TTS/parler.py +203 -111
- webscout/Provider/TTS/qwen.py +334 -0
- webscout/Provider/TTS/sherpa.py +286 -0
- webscout/Provider/TTS/speechma.py +693 -580
- webscout/Provider/TTS/streamElements.py +275 -333
- webscout/Provider/TTS/utils.py +280 -280
- webscout/Provider/TextPollinationsAI.py +331 -308
- webscout/Provider/TogetherAI.py +450 -0
- webscout/Provider/TwoAI.py +309 -475
- webscout/Provider/TypliAI.py +311 -305
- webscout/Provider/UNFINISHED/ChatHub.py +219 -209
- webscout/Provider/{OPENAI/glider.py → UNFINISHED/ChutesAI.py} +331 -326
- webscout/Provider/{GizAI.py → UNFINISHED/GizAI.py} +300 -295
- webscout/Provider/{Marcus.py → UNFINISHED/Marcus.py} +218 -198
- webscout/Provider/UNFINISHED/Qodo.py +481 -0
- webscout/Provider/{MCPCore.py → UNFINISHED/XenAI.py} +330 -315
- webscout/Provider/UNFINISHED/Youchat.py +347 -330
- webscout/Provider/UNFINISHED/aihumanizer.py +41 -0
- webscout/Provider/UNFINISHED/grammerchecker.py +37 -0
- webscout/Provider/UNFINISHED/liner.py +342 -0
- webscout/Provider/UNFINISHED/liner_api_request.py +246 -263
- webscout/Provider/{samurai.py → UNFINISHED/samurai.py} +231 -224
- webscout/Provider/WiseCat.py +256 -233
- webscout/Provider/WrDoChat.py +390 -370
- webscout/Provider/__init__.py +115 -174
- webscout/Provider/ai4chat.py +181 -174
- webscout/Provider/akashgpt.py +330 -335
- webscout/Provider/cerebras.py +397 -290
- webscout/Provider/cleeai.py +236 -213
- webscout/Provider/elmo.py +291 -283
- webscout/Provider/geminiapi.py +343 -208
- webscout/Provider/julius.py +245 -223
- webscout/Provider/learnfastai.py +333 -325
- webscout/Provider/llama3mitril.py +230 -215
- webscout/Provider/llmchat.py +308 -258
- webscout/Provider/llmchatco.py +321 -306
- webscout/Provider/meta.py +996 -801
- webscout/Provider/oivscode.py +332 -309
- webscout/Provider/searchchat.py +316 -292
- webscout/Provider/sonus.py +264 -258
- webscout/Provider/toolbaz.py +359 -353
- webscout/Provider/turboseek.py +332 -266
- webscout/Provider/typefully.py +262 -202
- webscout/Provider/x0gpt.py +332 -299
- webscout/__init__.py +31 -39
- webscout/__main__.py +5 -5
- webscout/cli.py +585 -524
- webscout/client.py +1497 -70
- webscout/conversation.py +140 -436
- webscout/exceptions.py +383 -362
- webscout/litagent/__init__.py +29 -29
- webscout/litagent/agent.py +492 -455
- webscout/litagent/constants.py +60 -60
- webscout/models.py +505 -181
- webscout/optimizers.py +74 -420
- webscout/prompt_manager.py +376 -288
- webscout/sanitize.py +1514 -0
- webscout/scout/README.md +452 -404
- webscout/scout/__init__.py +8 -8
- webscout/scout/core/__init__.py +7 -7
- webscout/scout/core/crawler.py +330 -210
- webscout/scout/core/scout.py +800 -607
- webscout/scout/core/search_result.py +51 -96
- webscout/scout/core/text_analyzer.py +64 -63
- webscout/scout/core/text_utils.py +412 -277
- webscout/scout/core/web_analyzer.py +54 -52
- webscout/scout/element.py +872 -478
- webscout/scout/parsers/__init__.py +70 -69
- webscout/scout/parsers/html5lib_parser.py +182 -172
- webscout/scout/parsers/html_parser.py +238 -236
- webscout/scout/parsers/lxml_parser.py +203 -178
- webscout/scout/utils.py +38 -37
- webscout/search/__init__.py +47 -0
- webscout/search/base.py +201 -0
- webscout/search/bing_main.py +45 -0
- webscout/search/brave_main.py +92 -0
- webscout/search/duckduckgo_main.py +57 -0
- webscout/search/engines/__init__.py +127 -0
- webscout/search/engines/bing/__init__.py +15 -0
- webscout/search/engines/bing/base.py +35 -0
- webscout/search/engines/bing/images.py +114 -0
- webscout/search/engines/bing/news.py +96 -0
- webscout/search/engines/bing/suggestions.py +36 -0
- webscout/search/engines/bing/text.py +109 -0
- webscout/search/engines/brave/__init__.py +19 -0
- webscout/search/engines/brave/base.py +47 -0
- webscout/search/engines/brave/images.py +213 -0
- webscout/search/engines/brave/news.py +353 -0
- webscout/search/engines/brave/suggestions.py +318 -0
- webscout/search/engines/brave/text.py +167 -0
- webscout/search/engines/brave/videos.py +364 -0
- webscout/search/engines/duckduckgo/__init__.py +25 -0
- webscout/search/engines/duckduckgo/answers.py +80 -0
- webscout/search/engines/duckduckgo/base.py +189 -0
- webscout/search/engines/duckduckgo/images.py +100 -0
- webscout/search/engines/duckduckgo/maps.py +183 -0
- webscout/search/engines/duckduckgo/news.py +70 -0
- webscout/search/engines/duckduckgo/suggestions.py +22 -0
- webscout/search/engines/duckduckgo/text.py +221 -0
- webscout/search/engines/duckduckgo/translate.py +48 -0
- webscout/search/engines/duckduckgo/videos.py +80 -0
- webscout/search/engines/duckduckgo/weather.py +84 -0
- webscout/search/engines/mojeek.py +61 -0
- webscout/search/engines/wikipedia.py +77 -0
- webscout/search/engines/yahoo/__init__.py +41 -0
- webscout/search/engines/yahoo/answers.py +19 -0
- webscout/search/engines/yahoo/base.py +34 -0
- webscout/search/engines/yahoo/images.py +323 -0
- webscout/search/engines/yahoo/maps.py +19 -0
- webscout/search/engines/yahoo/news.py +258 -0
- webscout/search/engines/yahoo/suggestions.py +140 -0
- webscout/search/engines/yahoo/text.py +273 -0
- webscout/search/engines/yahoo/translate.py +19 -0
- webscout/search/engines/yahoo/videos.py +302 -0
- webscout/search/engines/yahoo/weather.py +220 -0
- webscout/search/engines/yandex.py +67 -0
- webscout/search/engines/yep/__init__.py +13 -0
- webscout/search/engines/yep/base.py +34 -0
- webscout/search/engines/yep/images.py +101 -0
- webscout/search/engines/yep/suggestions.py +38 -0
- webscout/search/engines/yep/text.py +99 -0
- webscout/search/http_client.py +172 -0
- webscout/search/results.py +141 -0
- webscout/search/yahoo_main.py +57 -0
- webscout/search/yep_main.py +48 -0
- webscout/server/__init__.py +48 -0
- webscout/server/config.py +78 -0
- webscout/server/exceptions.py +69 -0
- webscout/server/providers.py +286 -0
- webscout/server/request_models.py +131 -0
- webscout/server/request_processing.py +404 -0
- webscout/server/routes.py +642 -0
- webscout/server/server.py +351 -0
- webscout/server/ui_templates.py +1171 -0
- webscout/swiftcli/__init__.py +79 -95
- webscout/swiftcli/core/__init__.py +7 -7
- webscout/swiftcli/core/cli.py +574 -297
- webscout/swiftcli/core/context.py +98 -104
- webscout/swiftcli/core/group.py +268 -241
- webscout/swiftcli/decorators/__init__.py +28 -28
- webscout/swiftcli/decorators/command.py +243 -221
- webscout/swiftcli/decorators/options.py +247 -220
- webscout/swiftcli/decorators/output.py +392 -252
- webscout/swiftcli/exceptions.py +21 -21
- webscout/swiftcli/plugins/__init__.py +9 -9
- webscout/swiftcli/plugins/base.py +134 -135
- webscout/swiftcli/plugins/manager.py +269 -269
- webscout/swiftcli/utils/__init__.py +58 -59
- webscout/swiftcli/utils/formatting.py +251 -252
- webscout/swiftcli/utils/parsing.py +368 -267
- webscout/update_checker.py +280 -136
- webscout/utils.py +28 -14
- webscout/version.py +2 -1
- webscout/version.py.bak +3 -0
- webscout/zeroart/__init__.py +218 -135
- webscout/zeroart/base.py +70 -66
- webscout/zeroart/effects.py +155 -101
- webscout/zeroart/fonts.py +1799 -1239
- webscout-2026.1.19.dist-info/METADATA +638 -0
- webscout-2026.1.19.dist-info/RECORD +312 -0
- {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/WHEEL +1 -1
- {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/entry_points.txt +1 -1
- webscout/DWEBS.py +0 -520
- webscout/Extra/Act.md +0 -309
- webscout/Extra/GitToolkit/gitapi/README.md +0 -110
- webscout/Extra/autocoder/__init__.py +0 -9
- webscout/Extra/autocoder/autocoder.py +0 -1105
- webscout/Extra/autocoder/autocoder_utiles.py +0 -332
- webscout/Extra/gguf.md +0 -430
- webscout/Extra/weather.md +0 -281
- webscout/Litlogger/README.md +0 -10
- webscout/Litlogger/__init__.py +0 -15
- webscout/Litlogger/formats.py +0 -4
- webscout/Litlogger/handlers.py +0 -103
- webscout/Litlogger/levels.py +0 -13
- webscout/Litlogger/logger.py +0 -92
- webscout/Provider/AI21.py +0 -177
- webscout/Provider/AISEARCH/DeepFind.py +0 -254
- webscout/Provider/AISEARCH/felo_search.py +0 -202
- webscout/Provider/AISEARCH/genspark_search.py +0 -324
- webscout/Provider/AISEARCH/hika_search.py +0 -186
- webscout/Provider/AISEARCH/scira_search.py +0 -298
- webscout/Provider/Aitopia.py +0 -316
- webscout/Provider/AllenAI.py +0 -440
- webscout/Provider/Blackboxai.py +0 -791
- webscout/Provider/ChatGPTClone.py +0 -237
- webscout/Provider/ChatGPTGratis.py +0 -194
- webscout/Provider/Cloudflare.py +0 -324
- webscout/Provider/ExaChat.py +0 -358
- webscout/Provider/Flowith.py +0 -217
- webscout/Provider/FreeGemini.py +0 -250
- webscout/Provider/Glider.py +0 -225
- webscout/Provider/HF_space/__init__.py +0 -0
- webscout/Provider/HF_space/qwen_qwen2.py +0 -206
- webscout/Provider/HuggingFaceChat.py +0 -469
- webscout/Provider/Hunyuan.py +0 -283
- webscout/Provider/LambdaChat.py +0 -411
- webscout/Provider/Llama3.py +0 -259
- webscout/Provider/Nemotron.py +0 -218
- webscout/Provider/OLLAMA.py +0 -396
- webscout/Provider/OPENAI/BLACKBOXAI.py +0 -766
- webscout/Provider/OPENAI/Cloudflare.py +0 -378
- webscout/Provider/OPENAI/FreeGemini.py +0 -283
- webscout/Provider/OPENAI/NEMOTRON.py +0 -232
- webscout/Provider/OPENAI/Qwen3.py +0 -283
- webscout/Provider/OPENAI/api.py +0 -969
- webscout/Provider/OPENAI/c4ai.py +0 -373
- webscout/Provider/OPENAI/chatgptclone.py +0 -494
- webscout/Provider/OPENAI/copilot.py +0 -242
- webscout/Provider/OPENAI/flowith.py +0 -162
- webscout/Provider/OPENAI/freeaichat.py +0 -359
- webscout/Provider/OPENAI/mcpcore.py +0 -389
- webscout/Provider/OPENAI/multichat.py +0 -376
- webscout/Provider/OPENAI/opkfc.py +0 -496
- webscout/Provider/OPENAI/scirachat.py +0 -477
- webscout/Provider/OPENAI/standardinput.py +0 -433
- webscout/Provider/OPENAI/typegpt.py +0 -364
- webscout/Provider/OPENAI/uncovrAI.py +0 -463
- webscout/Provider/OPENAI/venice.py +0 -431
- webscout/Provider/OPENAI/yep.py +0 -382
- webscout/Provider/OpenGPT.py +0 -209
- webscout/Provider/Perplexitylabs.py +0 -415
- webscout/Provider/Reka.py +0 -214
- webscout/Provider/StandardInput.py +0 -290
- webscout/Provider/TTI/aiarta.py +0 -365
- webscout/Provider/TTI/artbit.py +0 -0
- webscout/Provider/TTI/fastflux.py +0 -200
- webscout/Provider/TTI/piclumen.py +0 -203
- webscout/Provider/TTI/pixelmuse.py +0 -225
- webscout/Provider/TTS/gesserit.py +0 -128
- webscout/Provider/TTS/sthir.py +0 -94
- webscout/Provider/TeachAnything.py +0 -229
- webscout/Provider/UNFINISHED/puterjs.py +0 -635
- webscout/Provider/UNFINISHED/test_lmarena.py +0 -119
- webscout/Provider/Venice.py +0 -258
- webscout/Provider/VercelAI.py +0 -253
- webscout/Provider/Writecream.py +0 -246
- webscout/Provider/WritingMate.py +0 -269
- webscout/Provider/asksteve.py +0 -220
- webscout/Provider/chatglm.py +0 -215
- webscout/Provider/copilot.py +0 -425
- webscout/Provider/freeaichat.py +0 -285
- webscout/Provider/granite.py +0 -235
- webscout/Provider/hermes.py +0 -266
- webscout/Provider/koala.py +0 -170
- webscout/Provider/lmarena.py +0 -198
- webscout/Provider/multichat.py +0 -364
- webscout/Provider/scira_chat.py +0 -299
- webscout/Provider/scnet.py +0 -243
- webscout/Provider/talkai.py +0 -194
- webscout/Provider/typegpt.py +0 -289
- webscout/Provider/uncovr.py +0 -368
- webscout/Provider/yep.py +0 -389
- webscout/litagent/Readme.md +0 -276
- webscout/litprinter/__init__.py +0 -59
- webscout/swiftcli/Readme.md +0 -323
- webscout/tempid.py +0 -128
- webscout/webscout_search.py +0 -1184
- webscout/webscout_search_async.py +0 -654
- webscout/yep_search.py +0 -347
- webscout/zeroart/README.md +0 -89
- webscout-8.2.9.dist-info/METADATA +0 -1033
- webscout-8.2.9.dist-info/RECORD +0 -289
- {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/licenses/LICENSE.md +0 -0
- {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/top_level.txt +0 -0
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import ssl
|
|
2
|
-
import json
|
|
3
|
-
import time
|
|
4
|
-
import socket
|
|
5
|
-
import random
|
|
6
|
-
from threading import Thread, Event
|
|
7
|
-
from curl_cffi import requests
|
|
8
|
-
from websocket import WebSocketApp
|
|
9
|
-
from typing import Dict, Any, Union, Generator, List, Optional
|
|
10
|
-
|
|
11
|
-
from webscout.AIutel import Optimizers
|
|
12
|
-
from webscout.AIutel import Conversation
|
|
13
|
-
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
14
|
-
from webscout.AIbase import Provider
|
|
15
|
-
from webscout import exceptions
|
|
16
|
-
from webscout.litagent import LitAgent
|
|
17
|
-
|
|
18
|
-
class PerplexityLabs(Provider):
|
|
19
|
-
"""
|
|
20
|
-
A client for interacting with the Perplexity AI Labs API.
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
AVAILABLE_MODELS = [
|
|
24
|
-
"r1-1776",
|
|
25
|
-
"sonar-pro",
|
|
26
|
-
"sonar",
|
|
27
|
-
"sonar-reasoning-pro",
|
|
28
|
-
"sonar-reasoning"
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
def __init__(
|
|
32
|
-
self,
|
|
33
|
-
is_conversation: bool = True,
|
|
34
|
-
max_tokens: int = 2048,
|
|
35
|
-
timeout: int = 60,
|
|
36
|
-
intro: str = None,
|
|
37
|
-
filepath: str = None,
|
|
38
|
-
update_file: bool = True,
|
|
39
|
-
proxies: dict = {},
|
|
40
|
-
history_offset: int = 10250,
|
|
41
|
-
act: str = None,
|
|
42
|
-
model: str = "r1-1776",
|
|
43
|
-
connection_timeout: float = 10.0,
|
|
44
|
-
max_retries: int = 3,
|
|
45
|
-
):
|
|
46
|
-
"""
|
|
47
|
-
Initialize the Perplexity client.
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
is_conversation: Whether to maintain conversation context
|
|
51
|
-
max_tokens: Maximum token limit for responses
|
|
52
|
-
timeout: Response timeout in seconds
|
|
53
|
-
intro: Conversation intro/system prompt
|
|
54
|
-
filepath: Path for conversation history persistence
|
|
55
|
-
update_file: Whether to update the conversation file
|
|
56
|
-
proxies: Optional proxy configuration
|
|
57
|
-
history_offset: History truncation limit
|
|
58
|
-
act: Persona to use for responses
|
|
59
|
-
model: Default model to use
|
|
60
|
-
connection_timeout: Maximum time to wait for connection
|
|
61
|
-
max_retries: Number of connection retry attempts
|
|
62
|
-
"""
|
|
63
|
-
if model not in self.AVAILABLE_MODELS:
|
|
64
|
-
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
|
|
65
|
-
|
|
66
|
-
self.model = model
|
|
67
|
-
self.connection_timeout = connection_timeout
|
|
68
|
-
self.timeout = timeout
|
|
69
|
-
self.max_retries = max_retries
|
|
70
|
-
self.connected = Event()
|
|
71
|
-
self.last_answer = None
|
|
72
|
-
|
|
73
|
-
# Initialize session with headers using LitAgent user agent
|
|
74
|
-
self.session = requests.Session(headers={
|
|
75
|
-
'User-Agent': LitAgent().random(),
|
|
76
|
-
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
77
|
-
'accept-language': 'en-US,en;q=0.9',
|
|
78
|
-
'cache-control': 'max-age=0',
|
|
79
|
-
'dnt': '1',
|
|
80
|
-
'priority': 'u=0, i',
|
|
81
|
-
'sec-ch-ua': '"Not;A=Brand";v="24", "Chromium";v="128"',
|
|
82
|
-
'sec-ch-ua-mobile': '?0',
|
|
83
|
-
'sec-ch-ua-platform': '"Windows"',
|
|
84
|
-
'sec-fetch-dest': 'document',
|
|
85
|
-
'sec-fetch-mode': 'navigate',
|
|
86
|
-
'sec-fetch-site': 'same-origin',
|
|
87
|
-
'sec-fetch-user': '?1',
|
|
88
|
-
'upgrade-insecure-requests': '1',
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
# Apply proxies if provided
|
|
92
|
-
self.session.proxies.update(proxies)
|
|
93
|
-
|
|
94
|
-
# Set up conversation handling
|
|
95
|
-
self.is_conversation = is_conversation
|
|
96
|
-
self.max_tokens_to_sample = max_tokens
|
|
97
|
-
|
|
98
|
-
self.__available_optimizers = (
|
|
99
|
-
method
|
|
100
|
-
for method in dir(Optimizers)
|
|
101
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
102
|
-
)
|
|
103
|
-
Conversation.intro = (
|
|
104
|
-
AwesomePrompts().get_act(
|
|
105
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
106
|
-
)
|
|
107
|
-
if act
|
|
108
|
-
else intro or Conversation.intro
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
self.conversation = Conversation(
|
|
112
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
113
|
-
)
|
|
114
|
-
self.conversation.history_offset = history_offset
|
|
115
|
-
|
|
116
|
-
# Initialize connection
|
|
117
|
-
self._initialize_connection()
|
|
118
|
-
|
|
119
|
-
def _initialize_connection(self) -> None:
|
|
120
|
-
"""Initialize the connection to Perplexity with retries"""
|
|
121
|
-
for attempt in range(1, self.max_retries + 1):
|
|
122
|
-
try:
|
|
123
|
-
# Get a session ID via polling
|
|
124
|
-
self.timestamp = format(random.getrandbits(32), '08x')
|
|
125
|
-
poll_url = f'https://www.perplexity.ai/socket.io/?EIO=4&transport=polling&t={self.timestamp}'
|
|
126
|
-
|
|
127
|
-
response = self.session.get(poll_url)
|
|
128
|
-
if response.status_code != 200:
|
|
129
|
-
if attempt == self.max_retries:
|
|
130
|
-
raise ConnectionError(f"Failed to get session ID: HTTP {response.status_code}")
|
|
131
|
-
continue
|
|
132
|
-
|
|
133
|
-
# Extract the session ID
|
|
134
|
-
try:
|
|
135
|
-
self.sid = json.loads(response.text[1:])['sid']
|
|
136
|
-
except (json.JSONDecodeError, KeyError) as e:
|
|
137
|
-
if attempt == self.max_retries:
|
|
138
|
-
raise ConnectionError(f"Failed to parse session ID: {e}")
|
|
139
|
-
continue
|
|
140
|
-
|
|
141
|
-
# Authenticate the session
|
|
142
|
-
auth_url = f'https://www.perplexity.ai/socket.io/?EIO=4&transport=polling&t={self.timestamp}&sid={self.sid}'
|
|
143
|
-
auth_response = self.session.post(auth_url, data='40{"jwt":"anonymous-ask-user"}')
|
|
144
|
-
|
|
145
|
-
if auth_response.status_code != 200 or auth_response.text != 'OK':
|
|
146
|
-
if attempt == self.max_retries:
|
|
147
|
-
raise ConnectionError("Authentication failed")
|
|
148
|
-
continue
|
|
149
|
-
|
|
150
|
-
# Setup SSL socket
|
|
151
|
-
context = ssl.create_default_context()
|
|
152
|
-
context.minimum_version = ssl.TLSVersion.TLSv1_3
|
|
153
|
-
try:
|
|
154
|
-
self.sock = context.wrap_socket(
|
|
155
|
-
socket.create_connection(('www.perplexity.ai', 443), timeout=self.connection_timeout),
|
|
156
|
-
server_hostname='www.perplexity.ai'
|
|
157
|
-
)
|
|
158
|
-
except (socket.timeout, socket.error, ssl.SSLError) as e:
|
|
159
|
-
if attempt == self.max_retries:
|
|
160
|
-
raise ConnectionError(f"Socket connection failed: {e}")
|
|
161
|
-
continue
|
|
162
|
-
|
|
163
|
-
# Setup WebSocket
|
|
164
|
-
ws_url = f'wss://www.perplexity.ai/socket.io/?EIO=4&transport=websocket&sid={self.sid}'
|
|
165
|
-
cookies = '; '.join([f'{key}={value}' for key, value in self.session.cookies.get_dict().items()])
|
|
166
|
-
|
|
167
|
-
self.connected.clear()
|
|
168
|
-
self.ws = WebSocketApp(
|
|
169
|
-
url=ws_url,
|
|
170
|
-
header={'User-Agent': self.session.headers['User-Agent']},
|
|
171
|
-
cookie=cookies,
|
|
172
|
-
on_open=self._on_open,
|
|
173
|
-
on_message=self._on_message,
|
|
174
|
-
on_error=self._on_error,
|
|
175
|
-
on_close=self._on_close,
|
|
176
|
-
socket=self.sock
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
# Start WebSocket in a thread
|
|
180
|
-
self.ws_thread = Thread(target=self.ws.run_forever, daemon=True)
|
|
181
|
-
self.ws_thread.start()
|
|
182
|
-
|
|
183
|
-
# Wait for connection to be established
|
|
184
|
-
if self.connected.wait(timeout=self.connection_timeout):
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
except Exception as e:
|
|
188
|
-
if attempt == self.max_retries:
|
|
189
|
-
raise exceptions.FailedToGenerateResponseError(f"Failed to connect: {e}")
|
|
190
|
-
|
|
191
|
-
# If we get here, the attempt failed, wait before retrying
|
|
192
|
-
if attempt < self.max_retries:
|
|
193
|
-
retry_delay = 2 ** attempt # Exponential backoff
|
|
194
|
-
time.sleep(retry_delay)
|
|
195
|
-
|
|
196
|
-
raise exceptions.FailedToGenerateResponseError("Failed to connect to Perplexity after multiple attempts")
|
|
197
|
-
|
|
198
|
-
def _on_open(self, ws):
|
|
199
|
-
"""Handle websocket open event"""
|
|
200
|
-
ws.send('2probe')
|
|
201
|
-
ws.send('5')
|
|
202
|
-
|
|
203
|
-
def _on_close(self, ws, close_status_code, close_msg):
|
|
204
|
-
"""Handle websocket close event"""
|
|
205
|
-
self.connected.clear()
|
|
206
|
-
|
|
207
|
-
def _on_message(self, ws, message):
|
|
208
|
-
"""Handle websocket message events"""
|
|
209
|
-
if message == '2':
|
|
210
|
-
ws.send('3')
|
|
211
|
-
|
|
212
|
-
elif message == '3probe':
|
|
213
|
-
self.connected.set()
|
|
214
|
-
|
|
215
|
-
elif message.startswith('40'):
|
|
216
|
-
self.connected.set()
|
|
217
|
-
|
|
218
|
-
elif message.startswith('42'):
|
|
219
|
-
try:
|
|
220
|
-
response = json.loads(message[2:])[1]
|
|
221
|
-
if 'final' in response or 'partial' in response:
|
|
222
|
-
self.last_answer = response
|
|
223
|
-
except (json.JSONDecodeError, IndexError):
|
|
224
|
-
pass
|
|
225
|
-
|
|
226
|
-
def _on_error(self, ws, error):
|
|
227
|
-
"""Handle websocket error events"""
|
|
228
|
-
self.connected.clear()
|
|
229
|
-
|
|
230
|
-
def ask(
|
|
231
|
-
self,
|
|
232
|
-
prompt: str,
|
|
233
|
-
stream: bool = False,
|
|
234
|
-
raw: bool = False,
|
|
235
|
-
optimizer: str = None,
|
|
236
|
-
conversationally: bool = False,
|
|
237
|
-
model: str = None
|
|
238
|
-
) -> Union[Dict[str, Any], Generator]:
|
|
239
|
-
"""
|
|
240
|
-
Send a query to Perplexity AI and get a response.
|
|
241
|
-
|
|
242
|
-
Args:
|
|
243
|
-
prompt: The question to ask
|
|
244
|
-
stream: Whether to stream the response
|
|
245
|
-
raw: Return raw response format
|
|
246
|
-
optimizer: Optimizer function to apply to prompt
|
|
247
|
-
conversationally: Use conversation context
|
|
248
|
-
model: Override the model to use
|
|
249
|
-
|
|
250
|
-
Returns:
|
|
251
|
-
If stream=True: Generator yielding response updates
|
|
252
|
-
If stream=False: Final response dictionary
|
|
253
|
-
"""
|
|
254
|
-
# Check if connection is still active and reconnect if needed
|
|
255
|
-
if not self.connected.is_set():
|
|
256
|
-
self._initialize_connection()
|
|
257
|
-
|
|
258
|
-
# Use specified model or default
|
|
259
|
-
use_model = model or self.model
|
|
260
|
-
if use_model not in self.AVAILABLE_MODELS:
|
|
261
|
-
raise ValueError(f"Invalid model: {use_model}. Choose from: {', '.join(self.AVAILABLE_MODELS)}")
|
|
262
|
-
|
|
263
|
-
# Process prompt with conversation and optimizers
|
|
264
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
265
|
-
if optimizer:
|
|
266
|
-
if optimizer in self.__available_optimizers:
|
|
267
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
268
|
-
conversation_prompt if conversationally else prompt
|
|
269
|
-
)
|
|
270
|
-
else:
|
|
271
|
-
raise Exception(f"Optimizer is not one of {self.__available_optimizers}")
|
|
272
|
-
|
|
273
|
-
self.last_answer = None
|
|
274
|
-
|
|
275
|
-
# Send the query through websocket
|
|
276
|
-
payload = json.dumps([
|
|
277
|
-
'perplexity_labs',
|
|
278
|
-
{
|
|
279
|
-
'messages': [{'role': 'user', 'content': conversation_prompt}],
|
|
280
|
-
'model': use_model,
|
|
281
|
-
'source': 'default',
|
|
282
|
-
'version': '2.18',
|
|
283
|
-
}
|
|
284
|
-
])
|
|
285
|
-
self.ws.send('42' + payload)
|
|
286
|
-
|
|
287
|
-
def for_stream():
|
|
288
|
-
"""Handle streaming responses"""
|
|
289
|
-
last_seen = None
|
|
290
|
-
start_time = time.time()
|
|
291
|
-
streaming_text = ""
|
|
292
|
-
|
|
293
|
-
while True:
|
|
294
|
-
# Check for timeout
|
|
295
|
-
if time.time() - start_time > self.timeout:
|
|
296
|
-
raise exceptions.FailedToGenerateResponseError("Response stream timed out")
|
|
297
|
-
|
|
298
|
-
# If we have a new response different from what we've seen
|
|
299
|
-
if self.last_answer != last_seen:
|
|
300
|
-
last_seen = self.last_answer
|
|
301
|
-
if last_seen is not None:
|
|
302
|
-
if 'output' in last_seen:
|
|
303
|
-
current_output = last_seen['output']
|
|
304
|
-
# For delta output in streaming
|
|
305
|
-
delta = current_output[len(streaming_text):]
|
|
306
|
-
streaming_text = current_output
|
|
307
|
-
resp = dict(text=delta)
|
|
308
|
-
yield resp if raw else resp
|
|
309
|
-
|
|
310
|
-
# If we have the final response, add to history and return
|
|
311
|
-
if self.last_answer and self.last_answer.get('final', False):
|
|
312
|
-
answer = self.last_answer
|
|
313
|
-
self.conversation.update_chat_history(prompt, streaming_text)
|
|
314
|
-
return
|
|
315
|
-
|
|
316
|
-
time.sleep(0.01)
|
|
317
|
-
|
|
318
|
-
def for_non_stream():
|
|
319
|
-
"""Handle non-streaming responses"""
|
|
320
|
-
start_time = time.time()
|
|
321
|
-
|
|
322
|
-
while True:
|
|
323
|
-
# Check for successful response
|
|
324
|
-
if self.last_answer and self.last_answer.get('final', False):
|
|
325
|
-
answer = self.last_answer
|
|
326
|
-
self.conversation.update_chat_history(prompt, answer['output'])
|
|
327
|
-
return answer if raw else dict(text=answer['output'])
|
|
328
|
-
|
|
329
|
-
# Check for timeout
|
|
330
|
-
if time.time() - start_time > self.timeout:
|
|
331
|
-
raise exceptions.FailedToGenerateResponseError("Response timed out")
|
|
332
|
-
|
|
333
|
-
time.sleep(0.01)
|
|
334
|
-
|
|
335
|
-
return for_stream() if stream else for_non_stream()
|
|
336
|
-
|
|
337
|
-
def chat(
|
|
338
|
-
self,
|
|
339
|
-
prompt: str,
|
|
340
|
-
stream: bool = False,
|
|
341
|
-
optimizer: str = None,
|
|
342
|
-
conversationally: bool = False,
|
|
343
|
-
model: str = None
|
|
344
|
-
) -> Union[str, Generator[str, None, None]]:
|
|
345
|
-
"""
|
|
346
|
-
Send a query and get just the text response.
|
|
347
|
-
|
|
348
|
-
Args:
|
|
349
|
-
prompt: The question to ask
|
|
350
|
-
stream: Whether to stream the response
|
|
351
|
-
optimizer: Optimizer function to apply to prompt
|
|
352
|
-
conversationally: Use conversation context
|
|
353
|
-
model: Override the model to use
|
|
354
|
-
|
|
355
|
-
Returns:
|
|
356
|
-
If stream=True: Generator yielding text chunks
|
|
357
|
-
If stream=False: Complete response text
|
|
358
|
-
"""
|
|
359
|
-
def for_stream():
|
|
360
|
-
for response in self.ask(
|
|
361
|
-
prompt,
|
|
362
|
-
stream=True,
|
|
363
|
-
optimizer=optimizer,
|
|
364
|
-
conversationally=conversationally,
|
|
365
|
-
model=model
|
|
366
|
-
):
|
|
367
|
-
yield self.get_message(response)
|
|
368
|
-
|
|
369
|
-
def for_non_stream():
|
|
370
|
-
return self.get_message(
|
|
371
|
-
self.ask(
|
|
372
|
-
prompt,
|
|
373
|
-
stream=False,
|
|
374
|
-
optimizer=optimizer,
|
|
375
|
-
conversationally=conversationally,
|
|
376
|
-
model=model
|
|
377
|
-
)
|
|
378
|
-
)
|
|
379
|
-
|
|
380
|
-
return for_stream() if stream else for_non_stream()
|
|
381
|
-
|
|
382
|
-
def get_message(self, response: dict) -> str:
|
|
383
|
-
"""Extract text from response dictionary"""
|
|
384
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
385
|
-
return response["text"]
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if __name__ == "__main__":
|
|
389
|
-
print("-" * 80)
|
|
390
|
-
print(f"{'Model':<50} {'Status':<10} {'Response'}")
|
|
391
|
-
print("-" * 80)
|
|
392
|
-
|
|
393
|
-
# Test all available models
|
|
394
|
-
working = 0
|
|
395
|
-
total = len(PerplexityLabs.AVAILABLE_MODELS)
|
|
396
|
-
|
|
397
|
-
for model in PerplexityLabs.AVAILABLE_MODELS:
|
|
398
|
-
try:
|
|
399
|
-
test_ai = PerplexityLabs(model=model, timeout=60)
|
|
400
|
-
response = test_ai.chat("Say 'Hello' in one word", stream=True)
|
|
401
|
-
response_text = ""
|
|
402
|
-
for chunk in response:
|
|
403
|
-
response_text += chunk
|
|
404
|
-
print(f"\r{model:<50} {'Testing...':<10}", end="", flush=True)
|
|
405
|
-
|
|
406
|
-
if response_text and len(response_text.strip()) > 0:
|
|
407
|
-
status = "✓"
|
|
408
|
-
# Truncate response if too long
|
|
409
|
-
display_text = response_text.strip()[:50] + "..." if len(response_text.strip()) > 50 else response_text.strip()
|
|
410
|
-
else:
|
|
411
|
-
status = "✗"
|
|
412
|
-
display_text = "Empty or invalid response"
|
|
413
|
-
print(f"\r{model:<50} {status:<10} {display_text}")
|
|
414
|
-
except Exception as e:
|
|
415
|
-
print(f"\r{model:<50} {'✗':<10} {str(e)}")
|
webscout/Provider/Reka.py
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import json
|
|
5
|
-
|
|
6
|
-
from webscout.AIutel import Optimizers
|
|
7
|
-
from webscout.AIutel import Conversation
|
|
8
|
-
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
9
|
-
from webscout.AIbase import Provider, AsyncProvider
|
|
10
|
-
from webscout import exceptions
|
|
11
|
-
|
|
12
|
-
#-----------------------------------------------REKA-----------------------------------------------
|
|
13
|
-
class REKA(Provider):
|
|
14
|
-
def __init__(
|
|
15
|
-
self,
|
|
16
|
-
api_key: str,
|
|
17
|
-
is_conversation: bool = True,
|
|
18
|
-
max_tokens: int = 600,
|
|
19
|
-
timeout: int = 30,
|
|
20
|
-
intro: str = None,
|
|
21
|
-
filepath: str = None,
|
|
22
|
-
update_file: bool = True,
|
|
23
|
-
proxies: dict = {},
|
|
24
|
-
history_offset: int = 10250,
|
|
25
|
-
act: str = None,
|
|
26
|
-
model: str = "reka-core",
|
|
27
|
-
system_prompt: str = "Be Helpful and Friendly. Keep your response straightforward, short and concise",
|
|
28
|
-
use_search_engine: bool = False,
|
|
29
|
-
use_code_interpreter: bool = False,
|
|
30
|
-
):
|
|
31
|
-
"""Instantiates REKA
|
|
32
|
-
|
|
33
|
-
Args:
|
|
34
|
-
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True
|
|
35
|
-
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
36
|
-
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
37
|
-
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
38
|
-
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
39
|
-
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
40
|
-
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
41
|
-
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
42
|
-
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
43
|
-
model (str, optional): REKA model name. Defaults to "reka-core".
|
|
44
|
-
system_prompt (str, optional): System prompt for REKA. Defaults to "Be Helpful and Friendly. Keep your response straightforward, short and concise".
|
|
45
|
-
use_search_engine (bool, optional): Whether to use the search engine. Defaults to False.
|
|
46
|
-
use_code_interpreter (bool, optional): Whether to use the code interpreter. Defaults to False.
|
|
47
|
-
"""
|
|
48
|
-
self.session = requests.Session()
|
|
49
|
-
self.is_conversation = is_conversation
|
|
50
|
-
self.max_tokens_to_sample = max_tokens
|
|
51
|
-
self.api_endpoint = "https://chat.reka.ai/api/chat"
|
|
52
|
-
self.stream_chunk_size = 64
|
|
53
|
-
self.timeout = timeout
|
|
54
|
-
self.last_response = {}
|
|
55
|
-
self.model = model
|
|
56
|
-
self.system_prompt = system_prompt
|
|
57
|
-
self.use_search_engine = use_search_engine
|
|
58
|
-
self.use_code_interpreter = use_code_interpreter
|
|
59
|
-
self.access_token = api_key
|
|
60
|
-
self.headers = {
|
|
61
|
-
"Authorization": f"Bearer {self.access_token}",
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
self.__available_optimizers = (
|
|
65
|
-
method
|
|
66
|
-
for method in dir(Optimizers)
|
|
67
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
68
|
-
)
|
|
69
|
-
self.session.headers.update(self.headers)
|
|
70
|
-
Conversation.intro = (
|
|
71
|
-
AwesomePrompts().get_act(
|
|
72
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
73
|
-
)
|
|
74
|
-
if act
|
|
75
|
-
else intro or Conversation.intro
|
|
76
|
-
)
|
|
77
|
-
self.conversation = Conversation(
|
|
78
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
79
|
-
)
|
|
80
|
-
self.conversation.history_offset = history_offset
|
|
81
|
-
self.session.proxies = proxies
|
|
82
|
-
|
|
83
|
-
def ask(
|
|
84
|
-
self,
|
|
85
|
-
prompt: str,
|
|
86
|
-
stream: bool = False,
|
|
87
|
-
raw: bool = False,
|
|
88
|
-
optimizer: str = None,
|
|
89
|
-
conversationally: bool = False,
|
|
90
|
-
) -> dict:
|
|
91
|
-
"""Chat with AI
|
|
92
|
-
|
|
93
|
-
Args:
|
|
94
|
-
prompt (str): Prompt to be send.
|
|
95
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
96
|
-
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
97
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
98
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
99
|
-
Returns:
|
|
100
|
-
dict : {}
|
|
101
|
-
```json
|
|
102
|
-
{
|
|
103
|
-
"text" : "How may I assist you today?"
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
"""
|
|
107
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
108
|
-
if optimizer:
|
|
109
|
-
if optimizer in self.__available_optimizers:
|
|
110
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
111
|
-
conversation_prompt if conversationally else prompt
|
|
112
|
-
)
|
|
113
|
-
else:
|
|
114
|
-
raise Exception(
|
|
115
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
self.session.headers.update(self.headers)
|
|
119
|
-
payload = {
|
|
120
|
-
|
|
121
|
-
"conversation_history": [
|
|
122
|
-
{"type": "human", "text": f"## SYSTEM PROMPT: {self.system_prompt}\n\n## QUERY: {conversation_prompt}"},
|
|
123
|
-
],
|
|
124
|
-
|
|
125
|
-
"stream": stream,
|
|
126
|
-
"use_search_engine": self.use_search_engine,
|
|
127
|
-
"use_code_interpreter": self.use_code_interpreter,
|
|
128
|
-
"model_name": self.model,
|
|
129
|
-
# "model_name": "reka-flash",
|
|
130
|
-
# "model_name": "reka-edge",
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
def for_stream():
|
|
134
|
-
response = self.session.post(self.api_endpoint, json=payload, stream=True, timeout=self.timeout)
|
|
135
|
-
if not response.ok:
|
|
136
|
-
raise Exception(
|
|
137
|
-
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
for value in response.iter_lines(
|
|
141
|
-
decode_unicode=True,
|
|
142
|
-
chunk_size=self.stream_chunk_size,
|
|
143
|
-
):
|
|
144
|
-
try:
|
|
145
|
-
resp = json.loads(value)
|
|
146
|
-
self.last_response.update(resp)
|
|
147
|
-
yield value if raw else resp
|
|
148
|
-
except json.decoder.JSONDecodeError:
|
|
149
|
-
pass
|
|
150
|
-
self.conversation.update_chat_history(
|
|
151
|
-
prompt, self.get_message(self.last_response)
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
def for_non_stream():
|
|
155
|
-
# let's make use of stream
|
|
156
|
-
for _ in for_stream():
|
|
157
|
-
pass
|
|
158
|
-
return self.last_response
|
|
159
|
-
|
|
160
|
-
return for_stream() if stream else for_non_stream()
|
|
161
|
-
|
|
162
|
-
def chat(
|
|
163
|
-
self,
|
|
164
|
-
prompt: str,
|
|
165
|
-
stream: bool = False,
|
|
166
|
-
optimizer: str = None,
|
|
167
|
-
conversationally: bool = False,
|
|
168
|
-
) -> str:
|
|
169
|
-
"""Generate response `str`
|
|
170
|
-
Args:
|
|
171
|
-
prompt (str): Prompt to be send.
|
|
172
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
173
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
174
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
175
|
-
Returns:
|
|
176
|
-
str: Response generated
|
|
177
|
-
"""
|
|
178
|
-
|
|
179
|
-
def for_stream():
|
|
180
|
-
for response in self.ask(
|
|
181
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
182
|
-
):
|
|
183
|
-
yield self.get_message(response)
|
|
184
|
-
|
|
185
|
-
def for_non_stream():
|
|
186
|
-
return self.get_message(
|
|
187
|
-
self.ask(
|
|
188
|
-
prompt,
|
|
189
|
-
False,
|
|
190
|
-
optimizer=optimizer,
|
|
191
|
-
conversationally=conversationally,
|
|
192
|
-
)
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
return for_stream() if stream else for_non_stream()
|
|
196
|
-
|
|
197
|
-
def get_message(self, response: dict) -> str:
|
|
198
|
-
"""Retrieves message only from response
|
|
199
|
-
|
|
200
|
-
Args:
|
|
201
|
-
response (dict): Response generated by `self.ask`
|
|
202
|
-
|
|
203
|
-
Returns:
|
|
204
|
-
str: Message extracted
|
|
205
|
-
"""
|
|
206
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
207
|
-
return response.get("text")
|
|
208
|
-
if __name__ == "__main__":
|
|
209
|
-
|
|
210
|
-
from rich import print
|
|
211
|
-
ai = REKA(api_key="YOUR_API_KEY", timeout=5000)
|
|
212
|
-
response = ai.chat("write a poem about AI", stream=True)
|
|
213
|
-
for chunk in response:
|
|
214
|
-
print(chunk, end="", flush=True)
|