webscout 8.2.8__py3-none-any.whl → 8.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webscout might be problematic. Click here for more details.
- webscout/AIauto.py +34 -16
- webscout/AIbase.py +96 -37
- webscout/AIutel.py +491 -87
- webscout/Bard.py +441 -323
- webscout/Extra/GitToolkit/__init__.py +10 -10
- webscout/Extra/YTToolkit/ytapi/video.py +232 -232
- webscout/Litlogger/README.md +10 -0
- webscout/Litlogger/__init__.py +7 -59
- webscout/Litlogger/formats.py +4 -0
- webscout/Litlogger/handlers.py +103 -0
- webscout/Litlogger/levels.py +13 -0
- webscout/Litlogger/logger.py +92 -0
- webscout/Provider/AISEARCH/Perplexity.py +332 -358
- webscout/Provider/AISEARCH/felo_search.py +9 -35
- webscout/Provider/AISEARCH/genspark_search.py +30 -56
- webscout/Provider/AISEARCH/hika_search.py +4 -16
- webscout/Provider/AISEARCH/iask_search.py +410 -436
- webscout/Provider/AISEARCH/monica_search.py +4 -30
- webscout/Provider/AISEARCH/scira_search.py +6 -32
- webscout/Provider/AISEARCH/webpilotai_search.py +38 -64
- webscout/Provider/Blackboxai.py +155 -35
- webscout/Provider/ChatSandbox.py +2 -1
- webscout/Provider/Deepinfra.py +339 -339
- webscout/Provider/ExaChat.py +358 -358
- webscout/Provider/Gemini.py +169 -169
- webscout/Provider/GithubChat.py +1 -2
- webscout/Provider/Glider.py +3 -3
- webscout/Provider/HeckAI.py +172 -82
- webscout/Provider/LambdaChat.py +1 -0
- webscout/Provider/MCPCore.py +7 -3
- webscout/Provider/OPENAI/BLACKBOXAI.py +421 -139
- webscout/Provider/OPENAI/Cloudflare.py +38 -21
- webscout/Provider/OPENAI/FalconH1.py +457 -0
- webscout/Provider/OPENAI/FreeGemini.py +35 -18
- webscout/Provider/OPENAI/NEMOTRON.py +34 -34
- webscout/Provider/OPENAI/PI.py +427 -0
- webscout/Provider/OPENAI/Qwen3.py +304 -0
- webscout/Provider/OPENAI/README.md +952 -1253
- webscout/Provider/OPENAI/TwoAI.py +374 -0
- webscout/Provider/OPENAI/__init__.py +7 -1
- webscout/Provider/OPENAI/ai4chat.py +73 -63
- webscout/Provider/OPENAI/api.py +869 -644
- webscout/Provider/OPENAI/base.py +2 -0
- webscout/Provider/OPENAI/c4ai.py +34 -13
- webscout/Provider/OPENAI/chatgpt.py +575 -556
- webscout/Provider/OPENAI/chatgptclone.py +512 -487
- webscout/Provider/OPENAI/chatsandbox.py +11 -6
- webscout/Provider/OPENAI/copilot.py +258 -0
- webscout/Provider/OPENAI/deepinfra.py +327 -318
- webscout/Provider/OPENAI/e2b.py +140 -104
- webscout/Provider/OPENAI/exaai.py +420 -411
- webscout/Provider/OPENAI/exachat.py +448 -443
- webscout/Provider/OPENAI/flowith.py +7 -3
- webscout/Provider/OPENAI/freeaichat.py +12 -8
- webscout/Provider/OPENAI/glider.py +15 -8
- webscout/Provider/OPENAI/groq.py +5 -2
- webscout/Provider/OPENAI/heckai.py +311 -307
- webscout/Provider/OPENAI/llmchatco.py +9 -7
- webscout/Provider/OPENAI/mcpcore.py +18 -9
- webscout/Provider/OPENAI/multichat.py +7 -5
- webscout/Provider/OPENAI/netwrck.py +16 -11
- webscout/Provider/OPENAI/oivscode.py +290 -0
- webscout/Provider/OPENAI/opkfc.py +507 -496
- webscout/Provider/OPENAI/pydantic_imports.py +172 -0
- webscout/Provider/OPENAI/scirachat.py +29 -17
- webscout/Provider/OPENAI/sonus.py +308 -303
- webscout/Provider/OPENAI/standardinput.py +442 -433
- webscout/Provider/OPENAI/textpollinations.py +18 -11
- webscout/Provider/OPENAI/toolbaz.py +419 -413
- webscout/Provider/OPENAI/typefully.py +17 -10
- webscout/Provider/OPENAI/typegpt.py +21 -11
- webscout/Provider/OPENAI/uncovrAI.py +477 -462
- webscout/Provider/OPENAI/utils.py +90 -79
- webscout/Provider/OPENAI/venice.py +435 -425
- webscout/Provider/OPENAI/wisecat.py +387 -381
- webscout/Provider/OPENAI/writecream.py +166 -163
- webscout/Provider/OPENAI/x0gpt.py +26 -37
- webscout/Provider/OPENAI/yep.py +384 -356
- webscout/Provider/PI.py +2 -1
- webscout/Provider/TTI/README.md +55 -101
- webscout/Provider/TTI/__init__.py +4 -9
- webscout/Provider/TTI/aiarta.py +365 -0
- webscout/Provider/TTI/artbit.py +0 -0
- webscout/Provider/TTI/base.py +64 -0
- webscout/Provider/TTI/fastflux.py +200 -0
- webscout/Provider/TTI/magicstudio.py +201 -0
- webscout/Provider/TTI/piclumen.py +203 -0
- webscout/Provider/TTI/pixelmuse.py +225 -0
- webscout/Provider/TTI/pollinations.py +221 -0
- webscout/Provider/TTI/utils.py +11 -0
- webscout/Provider/TTS/__init__.py +2 -1
- webscout/Provider/TTS/base.py +159 -159
- webscout/Provider/TTS/openai_fm.py +129 -0
- webscout/Provider/TextPollinationsAI.py +308 -308
- webscout/Provider/TwoAI.py +239 -44
- webscout/Provider/UNFINISHED/Youchat.py +330 -330
- webscout/Provider/UNFINISHED/puterjs.py +635 -0
- webscout/Provider/UNFINISHED/test_lmarena.py +119 -119
- webscout/Provider/Writecream.py +246 -246
- webscout/Provider/__init__.py +2 -2
- webscout/Provider/ai4chat.py +33 -8
- webscout/Provider/granite.py +41 -6
- webscout/Provider/koala.py +169 -169
- webscout/Provider/oivscode.py +309 -0
- webscout/Provider/samurai.py +3 -2
- webscout/Provider/scnet.py +1 -0
- webscout/Provider/typegpt.py +3 -3
- webscout/Provider/uncovr.py +368 -368
- webscout/client.py +70 -0
- webscout/litprinter/__init__.py +58 -58
- webscout/optimizers.py +419 -419
- webscout/scout/README.md +3 -1
- webscout/scout/core/crawler.py +134 -64
- webscout/scout/core/scout.py +148 -109
- webscout/scout/element.py +106 -88
- webscout/swiftcli/Readme.md +323 -323
- webscout/swiftcli/plugins/manager.py +9 -2
- webscout/version.py +1 -1
- webscout/zeroart/__init__.py +134 -134
- webscout/zeroart/effects.py +100 -100
- webscout/zeroart/fonts.py +1238 -1238
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/METADATA +160 -35
- webscout-8.3.dist-info/RECORD +290 -0
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/WHEEL +1 -1
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/entry_points.txt +1 -0
- webscout/Litlogger/Readme.md +0 -175
- webscout/Litlogger/core/__init__.py +0 -6
- webscout/Litlogger/core/level.py +0 -23
- webscout/Litlogger/core/logger.py +0 -165
- webscout/Litlogger/handlers/__init__.py +0 -12
- webscout/Litlogger/handlers/console.py +0 -33
- webscout/Litlogger/handlers/file.py +0 -143
- webscout/Litlogger/handlers/network.py +0 -173
- webscout/Litlogger/styles/__init__.py +0 -7
- webscout/Litlogger/styles/colors.py +0 -249
- webscout/Litlogger/styles/formats.py +0 -458
- webscout/Litlogger/styles/text.py +0 -87
- webscout/Litlogger/utils/__init__.py +0 -6
- webscout/Litlogger/utils/detectors.py +0 -153
- webscout/Litlogger/utils/formatters.py +0 -200
- webscout/Provider/ChatGPTGratis.py +0 -194
- webscout/Provider/TTI/AiForce/README.md +0 -159
- webscout/Provider/TTI/AiForce/__init__.py +0 -22
- webscout/Provider/TTI/AiForce/async_aiforce.py +0 -224
- webscout/Provider/TTI/AiForce/sync_aiforce.py +0 -245
- webscout/Provider/TTI/FreeAIPlayground/README.md +0 -99
- webscout/Provider/TTI/FreeAIPlayground/__init__.py +0 -9
- webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +0 -181
- webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +0 -180
- webscout/Provider/TTI/ImgSys/README.md +0 -174
- webscout/Provider/TTI/ImgSys/__init__.py +0 -23
- webscout/Provider/TTI/ImgSys/async_imgsys.py +0 -202
- webscout/Provider/TTI/ImgSys/sync_imgsys.py +0 -195
- webscout/Provider/TTI/MagicStudio/README.md +0 -101
- webscout/Provider/TTI/MagicStudio/__init__.py +0 -2
- webscout/Provider/TTI/MagicStudio/async_magicstudio.py +0 -111
- webscout/Provider/TTI/MagicStudio/sync_magicstudio.py +0 -109
- webscout/Provider/TTI/Nexra/README.md +0 -155
- webscout/Provider/TTI/Nexra/__init__.py +0 -22
- webscout/Provider/TTI/Nexra/async_nexra.py +0 -286
- webscout/Provider/TTI/Nexra/sync_nexra.py +0 -258
- webscout/Provider/TTI/PollinationsAI/README.md +0 -146
- webscout/Provider/TTI/PollinationsAI/__init__.py +0 -23
- webscout/Provider/TTI/PollinationsAI/async_pollinations.py +0 -311
- webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +0 -265
- webscout/Provider/TTI/aiarta/README.md +0 -134
- webscout/Provider/TTI/aiarta/__init__.py +0 -2
- webscout/Provider/TTI/aiarta/async_aiarta.py +0 -482
- webscout/Provider/TTI/aiarta/sync_aiarta.py +0 -440
- webscout/Provider/TTI/artbit/README.md +0 -100
- webscout/Provider/TTI/artbit/__init__.py +0 -22
- webscout/Provider/TTI/artbit/async_artbit.py +0 -155
- webscout/Provider/TTI/artbit/sync_artbit.py +0 -148
- webscout/Provider/TTI/fastflux/README.md +0 -129
- webscout/Provider/TTI/fastflux/__init__.py +0 -22
- webscout/Provider/TTI/fastflux/async_fastflux.py +0 -261
- webscout/Provider/TTI/fastflux/sync_fastflux.py +0 -252
- webscout/Provider/TTI/huggingface/README.md +0 -114
- webscout/Provider/TTI/huggingface/__init__.py +0 -22
- webscout/Provider/TTI/huggingface/async_huggingface.py +0 -199
- webscout/Provider/TTI/huggingface/sync_huggingface.py +0 -195
- webscout/Provider/TTI/piclumen/README.md +0 -161
- webscout/Provider/TTI/piclumen/__init__.py +0 -23
- webscout/Provider/TTI/piclumen/async_piclumen.py +0 -268
- webscout/Provider/TTI/piclumen/sync_piclumen.py +0 -233
- webscout/Provider/TTI/pixelmuse/README.md +0 -79
- webscout/Provider/TTI/pixelmuse/__init__.py +0 -4
- webscout/Provider/TTI/pixelmuse/async_pixelmuse.py +0 -249
- webscout/Provider/TTI/pixelmuse/sync_pixelmuse.py +0 -182
- webscout/Provider/TTI/talkai/README.md +0 -139
- webscout/Provider/TTI/talkai/__init__.py +0 -4
- webscout/Provider/TTI/talkai/async_talkai.py +0 -229
- webscout/Provider/TTI/talkai/sync_talkai.py +0 -207
- webscout/Provider/UNFINISHED/oivscode.py +0 -351
- webscout-8.2.8.dist-info/RECORD +0 -334
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/licenses/LICENSE.md +0 -0
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/top_level.txt +0 -0
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
############################################################
|
|
2
|
-
# NOT WORKING
|
|
3
|
-
############################################################
|
|
4
|
-
|
|
5
|
-
import requests
|
|
6
|
-
import json
|
|
7
|
-
from typing import Union, Any, Dict, Optional, Generator
|
|
8
|
-
|
|
9
|
-
from webscout.AIutel import Optimizers
|
|
10
|
-
from webscout.AIutel import Conversation
|
|
11
|
-
from webscout.AIutel import AwesomePrompts
|
|
12
|
-
from webscout.AIbase import Provider
|
|
13
|
-
from webscout import exceptions
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class oivscode(Provider):
|
|
17
|
-
"""
|
|
18
|
-
A class to interact with a test API.
|
|
19
|
-
"""
|
|
20
|
-
AVAILABLE_MODELS = [
|
|
21
|
-
"deepseek/deepseek-chat",
|
|
22
|
-
"claude-3-5-haiku-20241022",
|
|
23
|
-
"gpt-4o-mini",
|
|
24
|
-
"claude-3-5-sonnet-20240620",
|
|
25
|
-
"ours/deepseek-chat",
|
|
26
|
-
"custom/deepseek",
|
|
27
|
-
"Qwen/Qwen2.5-72B-Instruct-Turbo",
|
|
28
|
-
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
|
29
|
-
"claude-3-5-sonnet-20241022",
|
|
30
|
-
"omni-moderation-latest",
|
|
31
|
-
"omni-moderation-latest-intents",
|
|
32
|
-
"omni-moderation-2024-09-26",
|
|
33
|
-
"gpt-4",
|
|
34
|
-
"gpt-4o",
|
|
35
|
-
"gpt-4o-audio-preview",
|
|
36
|
-
"gpt-4o-audio-preview-2024-12-17",
|
|
37
|
-
"gpt-4o-audio-preview-2024-10-01",
|
|
38
|
-
"gpt-4o-mini-audio-preview-2024-12-17",
|
|
39
|
-
"gpt-4o-mini",
|
|
40
|
-
"gpt-4o-mini-2024-07-18",
|
|
41
|
-
"o1",
|
|
42
|
-
"o1-mini",
|
|
43
|
-
"o1-mini-2024-09-12",
|
|
44
|
-
"o1-preview",
|
|
45
|
-
"o1-preview-2024-09-12",
|
|
46
|
-
"o1-2024-12-17",
|
|
47
|
-
"chatgpt-4o-latest",
|
|
48
|
-
"gpt-4o-2024-05-13",
|
|
49
|
-
"gpt-4o-2024-08-06",
|
|
50
|
-
"gpt-4o-2024-11-20",
|
|
51
|
-
"gpt-4o-realtime-preview-2024-10-01",
|
|
52
|
-
"gpt-4o-realtime-preview",
|
|
53
|
-
"gpt-4o-realtime-preview-2024-12-17",
|
|
54
|
-
"gpt-4o-mini-realtime-preview",
|
|
55
|
-
"gpt-4o-mini-realtime-preview-2024-12-17",
|
|
56
|
-
"gpt-4-turbo-preview",
|
|
57
|
-
"gpt-4-0314",
|
|
58
|
-
"gpt-4-0613",
|
|
59
|
-
"gpt-4-32k",
|
|
60
|
-
"gpt-4-32k-0314",
|
|
61
|
-
"gpt-4-32k-0613",
|
|
62
|
-
"gpt-4-turbo",
|
|
63
|
-
"gpt-4-turbo-2024-04-09",
|
|
64
|
-
"gpt-4-1106-preview",
|
|
65
|
-
"gpt-4-0125-preview",
|
|
66
|
-
"gpt-4-vision-preview",
|
|
67
|
-
"gpt-4-1106-vision-preview",
|
|
68
|
-
"gpt-3.5-turbo",
|
|
69
|
-
"gpt-3.5-turbo-0301",
|
|
70
|
-
"gpt-3.5-turbo-0613",
|
|
71
|
-
"gpt-3.5-turbo-1106",
|
|
72
|
-
"gpt-3.5-turbo-0125",
|
|
73
|
-
"gpt-3.5-turbo-16k",
|
|
74
|
-
"gpt-3.5-turbo-16k-0613",
|
|
75
|
-
"text-embedding-3-large",
|
|
76
|
-
"text-embedding-3-small",
|
|
77
|
-
"text-embedding-ada-002",
|
|
78
|
-
"text-embedding-ada-002-v2",
|
|
79
|
-
"text-moderation-stable",
|
|
80
|
-
"text-moderation-007",
|
|
81
|
-
"text-moderation-latest",
|
|
82
|
-
"256-x-256/dall-e-2",
|
|
83
|
-
"512-x-512/dall-e-2",
|
|
84
|
-
"1024-x-1024/dall-e-2",
|
|
85
|
-
"hd/1024-x-1792/dall-e-3",
|
|
86
|
-
"hd/1792-x-1024/dall-e-3",
|
|
87
|
-
"hd/1024-x-1024/dall-e-3",
|
|
88
|
-
"standard/1024-x-1792/dall-e-3",
|
|
89
|
-
"standard/1792-x-1024/dall-e-3",
|
|
90
|
-
"standard/1024-x-1024/dall-e-3",
|
|
91
|
-
"whisper-1",
|
|
92
|
-
"tts-1",
|
|
93
|
-
"tts-1-hd",
|
|
94
|
-
"ft:davinci-002",
|
|
95
|
-
"ft:babbage-002",
|
|
96
|
-
"babbage-002",
|
|
97
|
-
"davinci-002",
|
|
98
|
-
"gpt-3.5-turbo-instruct",
|
|
99
|
-
"gpt-3.5-turbo-instruct-0914",
|
|
100
|
-
"claude-instant-1",
|
|
101
|
-
"claude-instant-1.2",
|
|
102
|
-
"claude-2",
|
|
103
|
-
"claude-2.1",
|
|
104
|
-
"claude-3-haiku-20240307",
|
|
105
|
-
"claude-3-5-haiku-20241022",
|
|
106
|
-
"claude-3-opus-20240229",
|
|
107
|
-
"claude-3-sonnet-20240229",
|
|
108
|
-
"claude-3-5-sonnet-20240620",
|
|
109
|
-
"claude-3-5-sonnet-20241022",
|
|
110
|
-
"togethercomputer/llama-2-70b-chat",
|
|
111
|
-
"togethercomputer/llama-2-70b",
|
|
112
|
-
"togethercomputer/LLaMA-2-7B-32K",
|
|
113
|
-
"togethercomputer/Llama-2-7B-32K-Instruct",
|
|
114
|
-
"togethercomputer/llama-2-7b",
|
|
115
|
-
"togethercomputer/falcon-40b-instruct",
|
|
116
|
-
"togethercomputer/falcon-7b-instruct",
|
|
117
|
-
"togethercomputer/alpaca-7b",
|
|
118
|
-
"HuggingFaceH4/starchat-alpha",
|
|
119
|
-
"togethercomputer/CodeLlama-34b",
|
|
120
|
-
"togethercomputer/CodeLlama-34b-Instruct",
|
|
121
|
-
"togethercomputer/CodeLlama-34b-Python",
|
|
122
|
-
"defog/sqlcoder",
|
|
123
|
-
"NumbersStation/nsql-llama-2-7B",
|
|
124
|
-
"WizardLM/WizardCoder-15B-V1.0",
|
|
125
|
-
"WizardLM/WizardCoder-Python-34B-V1.0",
|
|
126
|
-
"NousResearch/Nous-Hermes-Llama2-13b",
|
|
127
|
-
"Austism/chronos-hermes-13b",
|
|
128
|
-
"upstage/SOLAR-0-70b-16bit",
|
|
129
|
-
"WizardLM/WizardLM-70B-V1.0",
|
|
130
|
-
"deepseek/deepseek-chat",
|
|
131
|
-
"deepseek/deepseek-coder",
|
|
132
|
-
"fireworks_ai/accounts/fireworks/models/llama-v3p2-1b-instruct",
|
|
133
|
-
"fireworks_ai/accounts/fireworks/models/llama-v3p2-3b-instruct",
|
|
134
|
-
"fireworks_ai/accounts/fireworks/models/llama-v3p2-11b-vision-instruct",
|
|
135
|
-
"accounts/fireworks/models/llama-v3p2-90b-vision-instruct",
|
|
136
|
-
"fireworks_ai/accounts/fireworks/models/firefunction-v2",
|
|
137
|
-
"fireworks_ai/accounts/fireworks/models/mixtral-8x22b-instruct-hf",
|
|
138
|
-
"fireworks_ai/accounts/fireworks/models/qwen2-72b-instruct",
|
|
139
|
-
"fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct",
|
|
140
|
-
"fireworks_ai/accounts/fireworks/models/yi-large",
|
|
141
|
-
"fireworks_ai/accounts/fireworks/models/deepseek-coder-v2-instruct",
|
|
142
|
-
"fireworks_ai/accounts/fireworks/models/deepseek-v3",
|
|
143
|
-
"fireworks_ai/nomic-ai/nomic-embed-text-v1.5",
|
|
144
|
-
"fireworks_ai/nomic-ai/nomic-embed-text-v1",
|
|
145
|
-
"fireworks_ai/WhereIsAI/UAE-Large-V1",
|
|
146
|
-
"fireworks_ai/thenlper/gte-large",
|
|
147
|
-
"fireworks_ai/thenlper/gte-base",
|
|
148
|
-
]
|
|
149
|
-
|
|
150
|
-
def __init__(
|
|
151
|
-
self,
|
|
152
|
-
is_conversation: bool = True,
|
|
153
|
-
max_tokens: int = 1024,
|
|
154
|
-
timeout: int = 30,
|
|
155
|
-
intro: str = None,
|
|
156
|
-
filepath: str = None,
|
|
157
|
-
update_file: bool = True,
|
|
158
|
-
proxies: dict = {},
|
|
159
|
-
history_offset: int = 10250,
|
|
160
|
-
act: str = None,
|
|
161
|
-
model: str = "claude-3-5-sonnet-20240620",
|
|
162
|
-
system_prompt: str = "You are a helpful AI assistant.",
|
|
163
|
-
|
|
164
|
-
):
|
|
165
|
-
"""
|
|
166
|
-
Initializes the oivscode with given parameters.
|
|
167
|
-
"""
|
|
168
|
-
if model not in self.AVAILABLE_MODELS:
|
|
169
|
-
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
self.session = requests.Session()
|
|
173
|
-
self.is_conversation = is_conversation
|
|
174
|
-
self.max_tokens_to_sample = max_tokens
|
|
175
|
-
self.api_endpoint = "https://oi-vscode-server.onrender.com/v1/chat/completions"
|
|
176
|
-
self.timeout = timeout
|
|
177
|
-
self.last_response = {}
|
|
178
|
-
self.model = model
|
|
179
|
-
self.system_prompt = system_prompt
|
|
180
|
-
self.headers = {
|
|
181
|
-
"accept": "*/*",
|
|
182
|
-
"accept-language": "en-US,en;q=0.9,en-GB;q=0.8,en-IN;q=0.7",
|
|
183
|
-
"cache-control": "no-cache",
|
|
184
|
-
"content-type": "application/json",
|
|
185
|
-
"pragma": "no-cache",
|
|
186
|
-
"priority": "u=1, i",
|
|
187
|
-
"sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132", "Microsoft Edge";v="132"',
|
|
188
|
-
"sec-ch-ua-mobile": "?0",
|
|
189
|
-
"sec-ch-ua-platform": '"Windows"',
|
|
190
|
-
"sec-fetch-dest": "empty",
|
|
191
|
-
"sec-fetch-mode": "cors",
|
|
192
|
-
"sec-fetch-site": "same-site"
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
self.__available_optimizers = (
|
|
197
|
-
method
|
|
198
|
-
for method in dir(Optimizers)
|
|
199
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
200
|
-
)
|
|
201
|
-
self.session.headers.update(self.headers)
|
|
202
|
-
Conversation.intro = (
|
|
203
|
-
AwesomePrompts().get_act(
|
|
204
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
205
|
-
)
|
|
206
|
-
if act
|
|
207
|
-
else intro or Conversation.intro
|
|
208
|
-
)
|
|
209
|
-
self.conversation = Conversation(
|
|
210
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
211
|
-
)
|
|
212
|
-
self.conversation.history_offset = history_offset
|
|
213
|
-
self.session.proxies = proxies
|
|
214
|
-
|
|
215
|
-
def ask(
|
|
216
|
-
self,
|
|
217
|
-
prompt: str,
|
|
218
|
-
stream: bool = False,
|
|
219
|
-
raw: bool = False,
|
|
220
|
-
optimizer: str = None,
|
|
221
|
-
conversationally: bool = False,
|
|
222
|
-
) -> Union[Dict[str, Any], Generator[Any, None, None]]:
|
|
223
|
-
"""Chat with AI
|
|
224
|
-
|
|
225
|
-
Args:
|
|
226
|
-
prompt (str): Prompt to be send.
|
|
227
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
228
|
-
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
229
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
230
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
231
|
-
Returns:
|
|
232
|
-
dict or generator:
|
|
233
|
-
If stream is False, returns a dict
|
|
234
|
-
If stream is True, returns a generator
|
|
235
|
-
"""
|
|
236
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
237
|
-
if optimizer:
|
|
238
|
-
if optimizer in self.__available_optimizers:
|
|
239
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
240
|
-
conversation_prompt if conversationally else prompt
|
|
241
|
-
)
|
|
242
|
-
else:
|
|
243
|
-
raise Exception(
|
|
244
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
245
|
-
)
|
|
246
|
-
|
|
247
|
-
payload = {
|
|
248
|
-
"model": self.model,
|
|
249
|
-
"stream": stream,
|
|
250
|
-
"messages": [
|
|
251
|
-
{"role": "system", "content": self.system_prompt},
|
|
252
|
-
{"role": "user", "content": conversation_prompt}
|
|
253
|
-
]
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
def for_stream():
|
|
257
|
-
response = self.session.post(
|
|
258
|
-
self.api_endpoint, json=payload, stream=True, timeout=self.timeout
|
|
259
|
-
)
|
|
260
|
-
if not response.ok:
|
|
261
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
262
|
-
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
263
|
-
)
|
|
264
|
-
from rich import print
|
|
265
|
-
print(response.text)
|
|
266
|
-
message_load = ""
|
|
267
|
-
for value in response.iter_lines(
|
|
268
|
-
decode_unicode=True,
|
|
269
|
-
delimiter="" if raw else "data:",
|
|
270
|
-
chunk_size=64,
|
|
271
|
-
):
|
|
272
|
-
try:
|
|
273
|
-
resp = json.loads(value)
|
|
274
|
-
incomplete_message = self.get_message(resp)
|
|
275
|
-
if incomplete_message:
|
|
276
|
-
message_load += incomplete_message
|
|
277
|
-
resp["choices"][0]["delta"]["content"] = message_load
|
|
278
|
-
self.last_response.update(resp)
|
|
279
|
-
yield value if raw else resp
|
|
280
|
-
elif raw:
|
|
281
|
-
yield value
|
|
282
|
-
except json.decoder.JSONDecodeError:
|
|
283
|
-
pass
|
|
284
|
-
self.conversation.update_chat_history(
|
|
285
|
-
prompt, self.get_message(self.last_response)
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
def for_non_stream():
|
|
289
|
-
response = self.session.post(
|
|
290
|
-
self.chat_endpoint, json=payload, stream=False, timeout=self.timeout
|
|
291
|
-
)
|
|
292
|
-
if (
|
|
293
|
-
not response.ok
|
|
294
|
-
or not response.headers.get("Content-Type", "") == "application/json"
|
|
295
|
-
):
|
|
296
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
297
|
-
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
298
|
-
)
|
|
299
|
-
resp = response.json()
|
|
300
|
-
self.last_response.update(resp)
|
|
301
|
-
self.conversation.update_chat_history(
|
|
302
|
-
prompt, self.get_message(self.last_response)
|
|
303
|
-
)
|
|
304
|
-
return resp
|
|
305
|
-
|
|
306
|
-
return for_stream() if stream else for_non_stream()
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
def chat(
|
|
310
|
-
self,
|
|
311
|
-
prompt: str,
|
|
312
|
-
stream: bool = False,
|
|
313
|
-
optimizer: str = None,
|
|
314
|
-
conversationally: bool = False,
|
|
315
|
-
) -> Union[str, Generator[str, None, None]]:
|
|
316
|
-
"""Generate response `str`
|
|
317
|
-
Args:
|
|
318
|
-
prompt (str): Prompt to be send.
|
|
319
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
320
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
321
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
322
|
-
Returns:
|
|
323
|
-
str: Response generated
|
|
324
|
-
"""
|
|
325
|
-
def for_stream():
|
|
326
|
-
for response in self.ask(
|
|
327
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
328
|
-
):
|
|
329
|
-
yield self.get_message(response)
|
|
330
|
-
def for_non_stream():
|
|
331
|
-
return self.get_message(
|
|
332
|
-
self.ask(
|
|
333
|
-
prompt,
|
|
334
|
-
False,
|
|
335
|
-
optimizer=optimizer,
|
|
336
|
-
conversationally=conversationally,
|
|
337
|
-
)
|
|
338
|
-
)
|
|
339
|
-
return for_stream() if stream else for_non_stream()
|
|
340
|
-
|
|
341
|
-
def get_message(self, response: dict) -> str:
|
|
342
|
-
"""Retrieves message only from response"""
|
|
343
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
344
|
-
return response["text"]
|
|
345
|
-
|
|
346
|
-
if __name__ == "__main__":
|
|
347
|
-
from rich import print
|
|
348
|
-
chatbot = oivscode()
|
|
349
|
-
response = chatbot.chat(input(">>> "), stream=True)
|
|
350
|
-
for chunk in response:
|
|
351
|
-
print(chunk, end="", flush=True)
|