webscout 8.2.3__py3-none-any.whl → 8.2.5__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/AIutel.py +226 -14
- webscout/Bard.py +579 -206
- webscout/DWEBS.py +78 -35
- webscout/Extra/gguf.py +2 -0
- webscout/Extra/tempmail/base.py +1 -1
- webscout/Provider/AISEARCH/hika_search.py +4 -0
- webscout/Provider/AISEARCH/scira_search.py +2 -5
- webscout/Provider/Aitopia.py +75 -51
- webscout/Provider/AllenAI.py +181 -147
- webscout/Provider/ChatGPTClone.py +97 -86
- webscout/Provider/ChatSandbox.py +342 -0
- webscout/Provider/Cloudflare.py +79 -32
- webscout/Provider/Deepinfra.py +135 -94
- webscout/Provider/ElectronHub.py +103 -39
- webscout/Provider/ExaChat.py +36 -20
- webscout/Provider/GPTWeb.py +103 -47
- webscout/Provider/GithubChat.py +52 -49
- webscout/Provider/GizAI.py +283 -0
- webscout/Provider/Glider.py +39 -28
- webscout/Provider/Groq.py +222 -91
- webscout/Provider/HeckAI.py +93 -69
- webscout/Provider/HuggingFaceChat.py +113 -106
- webscout/Provider/Hunyuan.py +94 -83
- webscout/Provider/Jadve.py +104 -79
- webscout/Provider/LambdaChat.py +142 -123
- webscout/Provider/Llama3.py +94 -39
- webscout/Provider/MCPCore.py +315 -0
- webscout/Provider/Marcus.py +95 -37
- webscout/Provider/Netwrck.py +94 -52
- webscout/Provider/OPENAI/__init__.py +4 -1
- webscout/Provider/OPENAI/ai4chat.py +286 -0
- webscout/Provider/OPENAI/chatgptclone.py +35 -14
- webscout/Provider/OPENAI/deepinfra.py +37 -0
- webscout/Provider/OPENAI/exachat.py +4 -0
- webscout/Provider/OPENAI/groq.py +354 -0
- webscout/Provider/OPENAI/heckai.py +6 -2
- webscout/Provider/OPENAI/mcpcore.py +376 -0
- webscout/Provider/OPENAI/multichat.py +368 -0
- webscout/Provider/OPENAI/netwrck.py +3 -1
- webscout/Provider/OPENAI/scirachat.py +2 -4
- webscout/Provider/OPENAI/textpollinations.py +20 -22
- webscout/Provider/OPENAI/toolbaz.py +1 -0
- webscout/Provider/OpenGPT.py +48 -38
- webscout/Provider/PI.py +178 -93
- webscout/Provider/PizzaGPT.py +66 -36
- webscout/Provider/StandardInput.py +42 -30
- webscout/Provider/TeachAnything.py +95 -52
- webscout/Provider/TextPollinationsAI.py +138 -78
- webscout/Provider/TwoAI.py +162 -81
- webscout/Provider/TypliAI.py +305 -0
- webscout/Provider/Venice.py +97 -58
- webscout/Provider/VercelAI.py +33 -14
- webscout/Provider/WiseCat.py +65 -28
- webscout/Provider/Writecream.py +37 -11
- webscout/Provider/WritingMate.py +135 -63
- webscout/Provider/__init__.py +9 -27
- webscout/Provider/ai4chat.py +6 -7
- webscout/Provider/asksteve.py +53 -44
- webscout/Provider/cerebras.py +77 -31
- webscout/Provider/chatglm.py +47 -37
- webscout/Provider/copilot.py +0 -3
- webscout/Provider/elmo.py +109 -60
- webscout/Provider/granite.py +102 -54
- webscout/Provider/hermes.py +95 -48
- webscout/Provider/koala.py +1 -1
- webscout/Provider/learnfastai.py +113 -54
- webscout/Provider/llama3mitril.py +86 -51
- webscout/Provider/llmchat.py +88 -46
- webscout/Provider/llmchatco.py +110 -115
- webscout/Provider/meta.py +41 -37
- webscout/Provider/multichat.py +67 -28
- webscout/Provider/scira_chat.py +49 -30
- webscout/Provider/scnet.py +106 -53
- webscout/Provider/searchchat.py +87 -88
- webscout/Provider/sonus.py +113 -63
- webscout/Provider/toolbaz.py +115 -82
- webscout/Provider/turboseek.py +90 -43
- webscout/Provider/tutorai.py +82 -64
- webscout/Provider/typefully.py +85 -35
- webscout/Provider/typegpt.py +118 -61
- webscout/Provider/uncovr.py +132 -76
- webscout/Provider/x0gpt.py +69 -26
- webscout/Provider/yep.py +79 -66
- webscout/cli.py +256 -0
- webscout/conversation.py +34 -22
- webscout/exceptions.py +23 -0
- webscout/prompt_manager.py +56 -42
- webscout/version.py +1 -1
- webscout/webscout_search.py +65 -47
- webscout/webscout_search_async.py +81 -126
- webscout/yep_search.py +93 -43
- {webscout-8.2.3.dist-info → webscout-8.2.5.dist-info}/METADATA +183 -50
- {webscout-8.2.3.dist-info → webscout-8.2.5.dist-info}/RECORD +97 -113
- {webscout-8.2.3.dist-info → webscout-8.2.5.dist-info}/WHEEL +1 -1
- webscout-8.2.5.dist-info/entry_points.txt +3 -0
- {webscout-8.2.3.dist-info → webscout-8.2.5.dist-info}/top_level.txt +0 -1
- inferno/__init__.py +0 -6
- inferno/__main__.py +0 -9
- inferno/cli.py +0 -6
- webscout/Local/__init__.py +0 -12
- webscout/Local/__main__.py +0 -9
- webscout/Local/api.py +0 -576
- webscout/Local/cli.py +0 -516
- webscout/Local/config.py +0 -75
- webscout/Local/llm.py +0 -287
- webscout/Local/model_manager.py +0 -253
- webscout/Local/server.py +0 -721
- webscout/Local/utils.py +0 -93
- webscout/Provider/C4ai.py +0 -432
- webscout/Provider/ChatGPTES.py +0 -237
- webscout/Provider/Chatify.py +0 -175
- webscout/Provider/DeepSeek.py +0 -196
- webscout/Provider/Llama.py +0 -200
- webscout/Provider/Phind.py +0 -535
- webscout/Provider/WebSim.py +0 -228
- webscout/Provider/askmyai.py +0 -158
- webscout/Provider/gaurish.py +0 -244
- webscout/Provider/labyrinth.py +0 -340
- webscout/Provider/lepton.py +0 -194
- webscout/Provider/llamatutor.py +0 -192
- webscout-8.2.3.dist-info/entry_points.txt +0 -5
- {webscout-8.2.3.dist-info → webscout-8.2.5.dist-info/licenses}/LICENSE.md +0 -0
webscout/Provider/ChatGPTES.py
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import re
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
from typing import Union, List, Dict
|
|
6
|
-
from webscout.AIutel import Optimizers, Conversation, AwesomePrompts
|
|
7
|
-
from webscout.AIbase import Provider
|
|
8
|
-
from webscout import exceptions
|
|
9
|
-
from webscout.litagent import LitAgent
|
|
10
|
-
class ChatGPTES(Provider):
|
|
11
|
-
"""
|
|
12
|
-
A class to interact with the ChatGPT.es API.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
SUPPORTED_MODELS = {
|
|
16
|
-
'gpt-4o', 'gpt-4o-mini', 'chatgpt-4o-latest'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
def __init__(
|
|
20
|
-
self,
|
|
21
|
-
is_conversation: bool = True,
|
|
22
|
-
max_tokens: int = 600,
|
|
23
|
-
timeout: int = 30,
|
|
24
|
-
intro: str = None,
|
|
25
|
-
filepath: str = None,
|
|
26
|
-
update_file: bool = True,
|
|
27
|
-
proxies: dict = {},
|
|
28
|
-
history_offset: int = 10250,
|
|
29
|
-
act: str = None,
|
|
30
|
-
model: str = "chatgpt-4o-latest", # Default model
|
|
31
|
-
system_prompt: str = "You are a helpful assistant.",
|
|
32
|
-
):
|
|
33
|
-
"""
|
|
34
|
-
Initializes the ChatGPT.es API with given parameters.
|
|
35
|
-
"""
|
|
36
|
-
if model not in self.SUPPORTED_MODELS:
|
|
37
|
-
raise ValueError(f"Unsupported model: {model}. Choose from: {self.SUPPORTED_MODELS}")
|
|
38
|
-
|
|
39
|
-
self.session = requests.Session()
|
|
40
|
-
self.is_conversation = is_conversation
|
|
41
|
-
self.max_tokens_to_sample = max_tokens
|
|
42
|
-
self.api_endpoint = 'https://chatgpt.es/wp-admin/admin-ajax.php'
|
|
43
|
-
self.stream_chunk_size = 64
|
|
44
|
-
self.timeout = timeout
|
|
45
|
-
self.last_response = {}
|
|
46
|
-
self.system_prompt = system_prompt
|
|
47
|
-
self.model = model
|
|
48
|
-
self.initial_headers = {
|
|
49
|
-
'User-Agent': LitAgent().random(),
|
|
50
|
-
'Referer': 'https://www.google.com/',
|
|
51
|
-
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,'
|
|
52
|
-
'image/avif,image/webp,image/apng,*/*;q=0.8,'
|
|
53
|
-
'application/signed-exchange;v=b3;q=0.7',
|
|
54
|
-
}
|
|
55
|
-
self.post_headers = {
|
|
56
|
-
'User-Agent': self.initial_headers['User-Agent'],
|
|
57
|
-
'Referer': 'https://chatgpt.es/',
|
|
58
|
-
'Origin': 'https://chatgpt.es',
|
|
59
|
-
'Accept': '*/*',
|
|
60
|
-
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
61
|
-
}
|
|
62
|
-
self.nonce = None
|
|
63
|
-
self.post_id = None
|
|
64
|
-
|
|
65
|
-
self.__available_optimizers = (
|
|
66
|
-
method
|
|
67
|
-
for method in dir(Optimizers)
|
|
68
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
# Conversation setup
|
|
72
|
-
Conversation.intro = (
|
|
73
|
-
AwesomePrompts().get_act(
|
|
74
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
75
|
-
)
|
|
76
|
-
if act
|
|
77
|
-
else intro or Conversation.intro
|
|
78
|
-
)
|
|
79
|
-
self.conversation = Conversation(
|
|
80
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
81
|
-
)
|
|
82
|
-
self.conversation.history_offset = history_offset
|
|
83
|
-
self.session.proxies = proxies
|
|
84
|
-
|
|
85
|
-
def get_nonce_and_post_id(self):
|
|
86
|
-
"""
|
|
87
|
-
Retrieves the nonce and post ID from the ChatGPT.es website.
|
|
88
|
-
"""
|
|
89
|
-
try:
|
|
90
|
-
response = self.session.get('https://chatgpt.es/', headers=self.initial_headers, timeout=self.timeout)
|
|
91
|
-
response.raise_for_status()
|
|
92
|
-
except requests.RequestException as e:
|
|
93
|
-
raise ConnectionError(f"Failed to retrieve nonce and post_id: {e}")
|
|
94
|
-
|
|
95
|
-
nonce_match = re.search(r'data-nonce="(.+?)"', response.text)
|
|
96
|
-
post_id_match = re.search(r'data-post-id="(.+?)"', response.text)
|
|
97
|
-
|
|
98
|
-
if not nonce_match or not post_id_match:
|
|
99
|
-
raise ValueError("Failed to parse nonce or post_id from the response.")
|
|
100
|
-
|
|
101
|
-
self.nonce = nonce_match.group(1)
|
|
102
|
-
self.post_id = post_id_match.group(1)
|
|
103
|
-
|
|
104
|
-
def ask(
|
|
105
|
-
self,
|
|
106
|
-
prompt: str,
|
|
107
|
-
stream: bool = False,
|
|
108
|
-
raw: bool = False,
|
|
109
|
-
optimizer: str = None,
|
|
110
|
-
conversationally: bool = False,
|
|
111
|
-
) -> dict:
|
|
112
|
-
"""
|
|
113
|
-
Chat with ChatGPT.es
|
|
114
|
-
|
|
115
|
-
Args:
|
|
116
|
-
prompt (str): Prompt to be sent.
|
|
117
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
118
|
-
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
119
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
120
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
121
|
-
|
|
122
|
-
Returns:
|
|
123
|
-
dict: Response dictionary.
|
|
124
|
-
"""
|
|
125
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
126
|
-
if optimizer:
|
|
127
|
-
if optimizer in self.__available_optimizers:
|
|
128
|
-
optimizer_func = getattr(Optimizers, optimizer)
|
|
129
|
-
conversation_prompt = optimizer_func(
|
|
130
|
-
conversation_prompt if conversationally else prompt
|
|
131
|
-
)
|
|
132
|
-
else:
|
|
133
|
-
raise ValueError(f"Optimizer '{optimizer}' is not supported. "
|
|
134
|
-
f"Available optimizers: {list(self.__available_optimizers)}")
|
|
135
|
-
|
|
136
|
-
# Retrieve nonce and post_id if they are not set
|
|
137
|
-
if not self.nonce or not self.post_id:
|
|
138
|
-
self.get_nonce_and_post_id()
|
|
139
|
-
|
|
140
|
-
messages = [
|
|
141
|
-
{"role": "user", "content": conversation_prompt},
|
|
142
|
-
]
|
|
143
|
-
|
|
144
|
-
# Prepare conversation history
|
|
145
|
-
conversation = ["Human: strictly respond in the same language as my prompt, preferably English"]
|
|
146
|
-
for msg in messages:
|
|
147
|
-
role = "Human" if msg['role'] == "user" else "AI"
|
|
148
|
-
conversation.append(f"{role}: {msg['content']}")
|
|
149
|
-
|
|
150
|
-
payload = {
|
|
151
|
-
'_wpnonce': self.nonce,
|
|
152
|
-
'post_id': self.post_id,
|
|
153
|
-
'url': 'https://chatgpt.es',
|
|
154
|
-
'action': 'wpaicg_chat_shortcode_message',
|
|
155
|
-
'message': messages[-1]['content'],
|
|
156
|
-
'bot_id': '0',
|
|
157
|
-
'chatbot_identity': 'shortcode',
|
|
158
|
-
'wpaicg_chat_client_id': os.urandom(5).hex(),
|
|
159
|
-
'wpaicg_chat_history': json.dumps(conversation)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
try:
|
|
163
|
-
response = self.session.post(
|
|
164
|
-
self.api_endpoint,
|
|
165
|
-
headers=self.post_headers,
|
|
166
|
-
data=payload,
|
|
167
|
-
timeout=self.timeout
|
|
168
|
-
)
|
|
169
|
-
response.raise_for_status()
|
|
170
|
-
except requests.RequestException as e:
|
|
171
|
-
raise ConnectionError(f"Failed to send request to ChatGPT.es: {e}")
|
|
172
|
-
|
|
173
|
-
try:
|
|
174
|
-
response_data = response.json()
|
|
175
|
-
except json.JSONDecodeError:
|
|
176
|
-
raise ValueError(f"Invalid JSON response: {response.text}")
|
|
177
|
-
|
|
178
|
-
if not isinstance(response_data, dict):
|
|
179
|
-
raise TypeError(f"Expected response_data to be a dict, got {type(response_data)}")
|
|
180
|
-
|
|
181
|
-
# Extract the message directly from the 'data' key
|
|
182
|
-
message = response_data.get('data')
|
|
183
|
-
if not isinstance(message, str):
|
|
184
|
-
raise KeyError("Missing 'data' key in response or 'data' is not a string")
|
|
185
|
-
|
|
186
|
-
self.last_response.update(dict(text=message))
|
|
187
|
-
self.conversation.update_chat_history(
|
|
188
|
-
prompt, self.get_message(self.last_response)
|
|
189
|
-
)
|
|
190
|
-
return self.last_response
|
|
191
|
-
|
|
192
|
-
def chat(
|
|
193
|
-
self,
|
|
194
|
-
prompt: str,
|
|
195
|
-
stream: bool = False,
|
|
196
|
-
optimizer: str = None,
|
|
197
|
-
conversationally: bool = False,
|
|
198
|
-
) -> str:
|
|
199
|
-
"""
|
|
200
|
-
Generate response as a string.
|
|
201
|
-
|
|
202
|
-
Args:
|
|
203
|
-
prompt (str): Prompt to be sent.
|
|
204
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
205
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
206
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
207
|
-
|
|
208
|
-
Returns:
|
|
209
|
-
str: Response generated.
|
|
210
|
-
"""
|
|
211
|
-
response = self.ask(
|
|
212
|
-
prompt,
|
|
213
|
-
stream=stream,
|
|
214
|
-
optimizer=optimizer,
|
|
215
|
-
conversationally=conversationally,
|
|
216
|
-
)
|
|
217
|
-
return self.get_message(response)
|
|
218
|
-
|
|
219
|
-
def get_message(self, response: dict) -> str:
|
|
220
|
-
"""
|
|
221
|
-
Retrieves message only from response.
|
|
222
|
-
|
|
223
|
-
Args:
|
|
224
|
-
response (dict): Response generated by `self.ask`.
|
|
225
|
-
|
|
226
|
-
Returns:
|
|
227
|
-
str: Message extracted.
|
|
228
|
-
"""
|
|
229
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
230
|
-
return response["text"]
|
|
231
|
-
|
|
232
|
-
if __name__ == "__main__":
|
|
233
|
-
ai = ChatGPTES()
|
|
234
|
-
response = ai.chat(input(">>> "))
|
|
235
|
-
for chunk in response:
|
|
236
|
-
print(chunk, end="", flush=True)
|
|
237
|
-
|
webscout/Provider/Chatify.py
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
from webscout.AIutel import Optimizers
|
|
2
|
-
from webscout.AIutel import Conversation
|
|
3
|
-
from webscout.AIutel import AwesomePrompts
|
|
4
|
-
from webscout.AIbase import Provider
|
|
5
|
-
from webscout import exceptions
|
|
6
|
-
import requests
|
|
7
|
-
from webscout.litagent import LitAgent
|
|
8
|
-
class Chatify(Provider):
|
|
9
|
-
"""
|
|
10
|
-
A class to interact with the Chatify AI API.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
def __init__(
|
|
14
|
-
self,
|
|
15
|
-
is_conversation: bool = True,
|
|
16
|
-
max_tokens: int = 600,
|
|
17
|
-
timeout: int = 30,
|
|
18
|
-
intro: str = None,
|
|
19
|
-
filepath: str = None,
|
|
20
|
-
update_file: bool = True,
|
|
21
|
-
proxies: dict = {},
|
|
22
|
-
history_offset: int = 10250,
|
|
23
|
-
act: str = None,
|
|
24
|
-
system_prompt: str = "You are a helpful and informative AI assistant.",
|
|
25
|
-
):
|
|
26
|
-
"""
|
|
27
|
-
Initializes the Chatify AI API with given parameters.
|
|
28
|
-
"""
|
|
29
|
-
self.session = requests.Session()
|
|
30
|
-
self.is_conversation = is_conversation
|
|
31
|
-
self.max_tokens_to_sample = max_tokens
|
|
32
|
-
self.api_endpoint = "https://chatify-ai.vercel.app/api/chat"
|
|
33
|
-
self.timeout = timeout
|
|
34
|
-
self.last_response = {}
|
|
35
|
-
self.headers = {
|
|
36
|
-
'Accept': '*/*',
|
|
37
|
-
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
38
|
-
'Accept-Language': 'en-US,en;q=0.9,en-IN;q=0.8',
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
'DNT': '1',
|
|
41
|
-
'Origin': 'https://chatify-ai.vercel.app',
|
|
42
|
-
'Referer': 'https://chatify-ai.vercel.app/',
|
|
43
|
-
'Sec-CH-UA': '"Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127"',
|
|
44
|
-
'Sec-CH-UA-Mobile': '?0',
|
|
45
|
-
'Sec-CH-UA-Platform': '"Windows"',
|
|
46
|
-
'Sec-Fetch-Dest': 'empty',
|
|
47
|
-
'Sec-Fetch-Mode': 'cors',
|
|
48
|
-
'Sec-Fetch-Site': 'same-origin',
|
|
49
|
-
'User-Agent': LitAgent().random(),
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
self.__available_optimizers = (
|
|
53
|
-
method
|
|
54
|
-
for method in dir(Optimizers)
|
|
55
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
56
|
-
)
|
|
57
|
-
self.session.headers.update(self.headers)
|
|
58
|
-
Conversation.intro = (
|
|
59
|
-
AwesomePrompts().get_act(
|
|
60
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
61
|
-
)
|
|
62
|
-
if act
|
|
63
|
-
else intro or Conversation.intro
|
|
64
|
-
)
|
|
65
|
-
self.conversation = Conversation(
|
|
66
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
67
|
-
)
|
|
68
|
-
self.conversation.history_offset = history_offset
|
|
69
|
-
self.session.proxies = proxies
|
|
70
|
-
self.system_prompt = system_prompt
|
|
71
|
-
|
|
72
|
-
def ask(
|
|
73
|
-
self,
|
|
74
|
-
prompt: str,
|
|
75
|
-
stream: bool = False,
|
|
76
|
-
raw: bool = False,
|
|
77
|
-
optimizer: str = None,
|
|
78
|
-
conversationally: bool = False,
|
|
79
|
-
) -> dict:
|
|
80
|
-
"""
|
|
81
|
-
Sends a prompt to the Chatify API and returns the response.
|
|
82
|
-
"""
|
|
83
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
84
|
-
if optimizer:
|
|
85
|
-
if optimizer in self.__available_optimizers:
|
|
86
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
87
|
-
conversation_prompt if conversationally else prompt
|
|
88
|
-
)
|
|
89
|
-
else:
|
|
90
|
-
raise Exception(
|
|
91
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
messages = []
|
|
95
|
-
if self.system_prompt:
|
|
96
|
-
messages.append({"role": "system", "content": self.system_prompt})
|
|
97
|
-
messages.append({"role": "user", "content": conversation_prompt})
|
|
98
|
-
|
|
99
|
-
payload = {
|
|
100
|
-
"messages": messages
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
def for_stream():
|
|
104
|
-
response = self.session.post(self.api_endpoint, headers=self.headers, json=payload, stream=True, timeout=self.timeout)
|
|
105
|
-
if not response.ok:
|
|
106
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
107
|
-
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
streaming_text = ""
|
|
111
|
-
for line in response.iter_lines():
|
|
112
|
-
if line:
|
|
113
|
-
decoded_line = line.decode('utf-8') # Decode the line
|
|
114
|
-
parts = decoded_line.split(':', 1)
|
|
115
|
-
if len(parts) > 1:
|
|
116
|
-
content = parts[1].strip().strip('"')
|
|
117
|
-
streaming_text += content
|
|
118
|
-
yield content if raw else dict(text=content)
|
|
119
|
-
self.last_response.update(dict(text=streaming_text))
|
|
120
|
-
self.conversation.update_chat_history(
|
|
121
|
-
prompt, self.get_message(self.last_response)
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
def for_non_stream():
|
|
125
|
-
for _ in for_stream():
|
|
126
|
-
pass
|
|
127
|
-
return self.last_response
|
|
128
|
-
|
|
129
|
-
return for_stream() if stream else for_non_stream()
|
|
130
|
-
|
|
131
|
-
def chat(
|
|
132
|
-
self,
|
|
133
|
-
prompt: str,
|
|
134
|
-
stream: bool = False,
|
|
135
|
-
optimizer: str = None,
|
|
136
|
-
conversationally: bool = False,
|
|
137
|
-
) -> str:
|
|
138
|
-
"""
|
|
139
|
-
Generates a response from the Chatify API.
|
|
140
|
-
"""
|
|
141
|
-
|
|
142
|
-
def for_stream():
|
|
143
|
-
for response in self.ask(
|
|
144
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
145
|
-
):
|
|
146
|
-
yield self.get_message(response)
|
|
147
|
-
|
|
148
|
-
def for_non_stream():
|
|
149
|
-
return self.get_message(
|
|
150
|
-
self.ask(
|
|
151
|
-
prompt,
|
|
152
|
-
False,
|
|
153
|
-
optimizer=optimizer,
|
|
154
|
-
conversationally=conversationally,
|
|
155
|
-
)
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
return for_stream() if stream else for_non_stream()
|
|
159
|
-
|
|
160
|
-
def get_message(self, response: dict) -> str:
|
|
161
|
-
"""
|
|
162
|
-
Extracts the message from the API response and formats it.
|
|
163
|
-
"""
|
|
164
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
165
|
-
return response["text"].replace('\\n', '\n').replace('\\n\\n', '\n\n')
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
# Example usage
|
|
169
|
-
if __name__ == "__main__":
|
|
170
|
-
from rich import print
|
|
171
|
-
|
|
172
|
-
ai = Chatify(timeout=5000)
|
|
173
|
-
response = ai.chat("write a poem about AI", stream=True)
|
|
174
|
-
for chunk in response:
|
|
175
|
-
print(chunk, end="", flush=True)
|
webscout/Provider/DeepSeek.py
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import json
|
|
3
|
-
from typing import Any, Dict
|
|
4
|
-
from webscout.AIutel import Optimizers
|
|
5
|
-
from webscout.AIutel import Conversation
|
|
6
|
-
from webscout.AIutel import AwesomePrompts
|
|
7
|
-
from webscout.AIbase import Provider
|
|
8
|
-
from webscout import exceptions
|
|
9
|
-
|
|
10
|
-
class DeepSeek(Provider):
|
|
11
|
-
"""
|
|
12
|
-
A class to interact with the DeepSeek AI API.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
AVAILABLE_MODELS = [
|
|
16
|
-
"deepseek-v3",
|
|
17
|
-
"deepseek-r1",
|
|
18
|
-
"deepseek-llm-67b-chat"
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
def __init__(
|
|
22
|
-
self,
|
|
23
|
-
is_conversation: bool = True,
|
|
24
|
-
max_tokens: int = 600,
|
|
25
|
-
timeout: int = 30,
|
|
26
|
-
intro: str = None,
|
|
27
|
-
filepath: str = None,
|
|
28
|
-
update_file: bool = True,
|
|
29
|
-
proxies: dict = {},
|
|
30
|
-
history_offset: int = 10250,
|
|
31
|
-
act: str = None,
|
|
32
|
-
model: str = "deepseek-r1", # Default model
|
|
33
|
-
system_prompt: str = "You are a helpful AI assistant."
|
|
34
|
-
):
|
|
35
|
-
"""
|
|
36
|
-
Initializes the DeepSeek AI API with given parameters.
|
|
37
|
-
"""
|
|
38
|
-
if model not in self.AVAILABLE_MODELS:
|
|
39
|
-
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS.keys()}")
|
|
40
|
-
|
|
41
|
-
self.session = requests.Session()
|
|
42
|
-
self.is_conversation = is_conversation
|
|
43
|
-
self.max_tokens_to_sample = max_tokens
|
|
44
|
-
self.api_endpoint = "https://www.deepseekapp.io/v1/chat/completions"
|
|
45
|
-
self.timeout = timeout
|
|
46
|
-
self.last_response = {}
|
|
47
|
-
self.system_prompt = system_prompt
|
|
48
|
-
self.model = model
|
|
49
|
-
self.api_key = "skgadi_mare_2_seater"
|
|
50
|
-
self.headers = {
|
|
51
|
-
"Content-Type": "application/json",
|
|
52
|
-
"Authorization": f"Bearer {self.api_key}",
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
self.__available_optimizers = (
|
|
56
|
-
method
|
|
57
|
-
for method in dir(Optimizers)
|
|
58
|
-
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
59
|
-
)
|
|
60
|
-
self.session.headers.update(self.headers)
|
|
61
|
-
Conversation.intro = (
|
|
62
|
-
AwesomePrompts().get_act(
|
|
63
|
-
act, raise_not_found=True, default=None, case_insensitive=True
|
|
64
|
-
)
|
|
65
|
-
if act
|
|
66
|
-
else intro or Conversation.intro
|
|
67
|
-
)
|
|
68
|
-
self.conversation = Conversation(
|
|
69
|
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
70
|
-
)
|
|
71
|
-
self.conversation.history_offset = history_offset
|
|
72
|
-
self.session.proxies = proxies
|
|
73
|
-
|
|
74
|
-
def ask(
|
|
75
|
-
self,
|
|
76
|
-
prompt: str,
|
|
77
|
-
stream: bool = False,
|
|
78
|
-
raw: bool = False,
|
|
79
|
-
optimizer: str = None,
|
|
80
|
-
conversationally: bool = False,
|
|
81
|
-
) -> Dict[str, Any]:
|
|
82
|
-
"""Chat with AI"""
|
|
83
|
-
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
84
|
-
if optimizer:
|
|
85
|
-
if optimizer in self.__available_optimizers:
|
|
86
|
-
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
87
|
-
conversation_prompt if conversationally else prompt
|
|
88
|
-
)
|
|
89
|
-
else:
|
|
90
|
-
raise Exception(
|
|
91
|
-
f"Optimizer is not one of {self.__available_optimizers}"
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
messages = [
|
|
95
|
-
{"role": "system", "content": self.system_prompt},
|
|
96
|
-
{"role": "user", "content": conversation_prompt}
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
payload = {
|
|
100
|
-
"model": self.model,
|
|
101
|
-
"messages": messages
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
def for_stream():
|
|
105
|
-
try:
|
|
106
|
-
with requests.post(self.api_endpoint, headers=self.headers, json=payload, stream=True, timeout=self.timeout) as response:
|
|
107
|
-
if response.status_code != 200:
|
|
108
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
109
|
-
f"Request failed with status code {response.status_code}"
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
streaming_text = ""
|
|
113
|
-
for line in response.iter_lines(decode_unicode=True):
|
|
114
|
-
if line:
|
|
115
|
-
line = line.strip()
|
|
116
|
-
if line.startswith("data: "):
|
|
117
|
-
json_str = line[6:] # Remove "data: " prefix
|
|
118
|
-
if json_str == "[DONE]":
|
|
119
|
-
break
|
|
120
|
-
try:
|
|
121
|
-
json_data = json.loads(json_str)
|
|
122
|
-
if 'choices' in json_data:
|
|
123
|
-
choice = json_data['choices'][0]
|
|
124
|
-
if 'delta' in choice and 'content' in choice['delta']:
|
|
125
|
-
content = choice['delta']['content']
|
|
126
|
-
streaming_text += content
|
|
127
|
-
resp = {"text": content}
|
|
128
|
-
yield resp if raw else resp
|
|
129
|
-
except json.JSONDecodeError:
|
|
130
|
-
continue
|
|
131
|
-
|
|
132
|
-
self.last_response = {"text": streaming_text}
|
|
133
|
-
self.conversation.update_chat_history(prompt, streaming_text)
|
|
134
|
-
|
|
135
|
-
except requests.RequestException as e:
|
|
136
|
-
raise exceptions.FailedToGenerateResponseError(f"Request failed: {e}")
|
|
137
|
-
|
|
138
|
-
def for_non_stream():
|
|
139
|
-
for _ in for_stream():
|
|
140
|
-
pass
|
|
141
|
-
return self.last_response
|
|
142
|
-
|
|
143
|
-
return for_stream() if stream else for_non_stream()
|
|
144
|
-
|
|
145
|
-
def chat(
|
|
146
|
-
self,
|
|
147
|
-
prompt: str,
|
|
148
|
-
stream: bool = False,
|
|
149
|
-
optimizer: str = None,
|
|
150
|
-
conversationally: bool = False,
|
|
151
|
-
) -> str:
|
|
152
|
-
"""Generate response string"""
|
|
153
|
-
def for_stream():
|
|
154
|
-
for response in self.ask(
|
|
155
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
156
|
-
):
|
|
157
|
-
yield self.get_message(response)
|
|
158
|
-
|
|
159
|
-
def for_non_stream():
|
|
160
|
-
return self.get_message(
|
|
161
|
-
self.ask(
|
|
162
|
-
prompt,
|
|
163
|
-
False,
|
|
164
|
-
optimizer=optimizer,
|
|
165
|
-
conversationally=conversationally,
|
|
166
|
-
)
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
return for_stream() if stream else for_non_stream()
|
|
170
|
-
|
|
171
|
-
def get_message(self, response: dict) -> str:
|
|
172
|
-
"""Retrieves message only from response"""
|
|
173
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
174
|
-
return response["text"]
|
|
175
|
-
|
|
176
|
-
if __name__ == "__main__":
|
|
177
|
-
print("-" * 80)
|
|
178
|
-
print(f"{'Model':<50} {'Status':<10} {'Response'}")
|
|
179
|
-
print("-" * 80)
|
|
180
|
-
|
|
181
|
-
for model in DeepSeek.AVAILABLE_MODELS:
|
|
182
|
-
try:
|
|
183
|
-
test_ai = DeepSeek(model=model, timeout=60)
|
|
184
|
-
response = test_ai.chat("Say 'Hello' in one word")
|
|
185
|
-
response_text = response
|
|
186
|
-
|
|
187
|
-
if response_text and len(response_text.strip()) > 0:
|
|
188
|
-
status = "✓"
|
|
189
|
-
# Truncate response if too long
|
|
190
|
-
display_text = response_text.strip()[:50] + "..." if len(response_text.strip()) > 50 else response_text.strip()
|
|
191
|
-
else:
|
|
192
|
-
status = "✗"
|
|
193
|
-
display_text = "Empty or invalid response"
|
|
194
|
-
print(f"{model:<50} {status:<10} {display_text}")
|
|
195
|
-
except Exception as e:
|
|
196
|
-
print(f"{model:<50} {'✗':<10} {str(e)}")
|