webscout 8.0__py3-none-any.whl → 8.2__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.
- inferno/__init__.py +6 -0
- inferno/__main__.py +9 -0
- inferno/cli.py +6 -0
- webscout/Local/__init__.py +6 -0
- webscout/Local/__main__.py +9 -0
- webscout/Local/api.py +576 -0
- webscout/Local/cli.py +338 -0
- webscout/Local/config.py +75 -0
- webscout/Local/llm.py +188 -0
- webscout/Local/model_manager.py +205 -0
- webscout/Local/server.py +187 -0
- webscout/Local/utils.py +93 -0
- webscout/Provider/AISEARCH/DeepFind.py +1 -1
- webscout/Provider/AISEARCH/ISou.py +1 -1
- webscout/Provider/AISEARCH/Perplexity.py +359 -0
- webscout/Provider/AISEARCH/__init__.py +3 -1
- webscout/Provider/AISEARCH/felo_search.py +1 -1
- webscout/Provider/AISEARCH/genspark_search.py +1 -1
- webscout/Provider/AISEARCH/hika_search.py +1 -1
- webscout/Provider/AISEARCH/iask_search.py +436 -0
- webscout/Provider/AISEARCH/scira_search.py +9 -5
- webscout/Provider/AISEARCH/webpilotai_search.py +1 -1
- webscout/Provider/ExaAI.py +1 -1
- webscout/Provider/ExaChat.py +18 -8
- webscout/Provider/GithubChat.py +5 -1
- webscout/Provider/Glider.py +4 -2
- webscout/Provider/Jadve.py +2 -2
- webscout/Provider/OPENAI/__init__.py +24 -0
- webscout/Provider/OPENAI/base.py +46 -0
- webscout/Provider/OPENAI/c4ai.py +347 -0
- webscout/Provider/OPENAI/chatgpt.py +549 -0
- webscout/Provider/OPENAI/chatgptclone.py +460 -0
- webscout/Provider/OPENAI/deepinfra.py +284 -0
- webscout/Provider/OPENAI/exaai.py +419 -0
- webscout/Provider/OPENAI/exachat.py +433 -0
- webscout/Provider/OPENAI/freeaichat.py +355 -0
- webscout/Provider/OPENAI/glider.py +316 -0
- webscout/Provider/OPENAI/heckai.py +337 -0
- webscout/Provider/OPENAI/llmchatco.py +327 -0
- webscout/Provider/OPENAI/netwrck.py +348 -0
- webscout/Provider/OPENAI/opkfc.py +488 -0
- webscout/Provider/OPENAI/scirachat.py +463 -0
- webscout/Provider/OPENAI/sonus.py +294 -0
- webscout/Provider/OPENAI/standardinput.py +425 -0
- webscout/Provider/OPENAI/textpollinations.py +285 -0
- webscout/Provider/OPENAI/toolbaz.py +405 -0
- webscout/Provider/OPENAI/typegpt.py +361 -0
- webscout/Provider/OPENAI/uncovrAI.py +455 -0
- webscout/Provider/OPENAI/utils.py +211 -0
- webscout/Provider/OPENAI/venice.py +428 -0
- webscout/Provider/OPENAI/wisecat.py +381 -0
- webscout/Provider/OPENAI/writecream.py +158 -0
- webscout/Provider/OPENAI/x0gpt.py +389 -0
- webscout/Provider/OPENAI/yep.py +329 -0
- webscout/Provider/StandardInput.py +278 -0
- webscout/Provider/TextPollinationsAI.py +27 -28
- webscout/Provider/Venice.py +1 -1
- webscout/Provider/Writecream.py +211 -0
- webscout/Provider/WritingMate.py +197 -0
- webscout/Provider/Youchat.py +30 -26
- webscout/Provider/__init__.py +14 -6
- webscout/Provider/koala.py +2 -2
- webscout/Provider/llmchatco.py +5 -0
- webscout/Provider/scira_chat.py +18 -12
- webscout/Provider/scnet.py +187 -0
- webscout/Provider/toolbaz.py +320 -0
- webscout/Provider/typegpt.py +3 -184
- webscout/Provider/uncovr.py +3 -3
- webscout/conversation.py +32 -32
- webscout/prompt_manager.py +2 -1
- webscout/version.py +1 -1
- webscout-8.2.dist-info/METADATA +734 -0
- {webscout-8.0.dist-info → webscout-8.2.dist-info}/RECORD +77 -32
- webscout-8.2.dist-info/entry_points.txt +5 -0
- {webscout-8.0.dist-info → webscout-8.2.dist-info}/top_level.txt +1 -0
- webscout/Provider/flowith.py +0 -207
- webscout-8.0.dist-info/METADATA +0 -995
- webscout-8.0.dist-info/entry_points.txt +0 -3
- {webscout-8.0.dist-info → webscout-8.2.dist-info}/LICENSE.md +0 -0
- {webscout-8.0.dist-info → webscout-8.2.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import uuid
|
|
3
|
+
import cloudscraper # Import cloudscraper
|
|
4
|
+
import json
|
|
5
|
+
from typing import List, Dict, Optional, Union, Generator, Any
|
|
6
|
+
|
|
7
|
+
# Import base classes and utility structures
|
|
8
|
+
from .base import OpenAICompatibleProvider, BaseChat, BaseCompletions
|
|
9
|
+
from .utils import (
|
|
10
|
+
ChatCompletionChunk, ChatCompletion, Choice, ChoiceDelta,
|
|
11
|
+
ChatCompletionMessage, CompletionUsage, get_system_prompt # Import get_system_prompt
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
# Attempt to import LitAgent, fallback if not available
|
|
15
|
+
try:
|
|
16
|
+
from webscout.litagent import LitAgent
|
|
17
|
+
except ImportError:
|
|
18
|
+
# Define a dummy LitAgent if webscout is not installed or accessible
|
|
19
|
+
class LitAgent:
|
|
20
|
+
def generate_fingerprint(self, browser: str = "chrome") -> Dict[str, Any]:
|
|
21
|
+
print("Warning: LitAgent not found. Using default minimal headers.")
|
|
22
|
+
return {
|
|
23
|
+
"accept": "*/*",
|
|
24
|
+
"accept_language": "en-US,en;q=0.9",
|
|
25
|
+
"platform": "Windows",
|
|
26
|
+
"sec_ch_ua": '"Not/A)Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
|
|
27
|
+
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
|
|
28
|
+
"browser_type": browser,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# --- YEPCHAT Client ---
|
|
32
|
+
|
|
33
|
+
# ANSI escape codes for formatting
|
|
34
|
+
BOLD = "\033[1m"
|
|
35
|
+
RED = "\033[91m"
|
|
36
|
+
RESET = "\033[0m"
|
|
37
|
+
|
|
38
|
+
class Completions(BaseCompletions):
|
|
39
|
+
def __init__(self, client: 'YEPCHAT'):
|
|
40
|
+
self._client = client
|
|
41
|
+
|
|
42
|
+
def create(
|
|
43
|
+
self,
|
|
44
|
+
*,
|
|
45
|
+
model: str,
|
|
46
|
+
messages: List[Dict[str, str]],
|
|
47
|
+
max_tokens: Optional[int] = 1280,
|
|
48
|
+
stream: bool = False,
|
|
49
|
+
temperature: Optional[float] = 0.6,
|
|
50
|
+
top_p: Optional[float] = 0.7,
|
|
51
|
+
system_prompt: Optional[str] = None, # Added for consistency, but will be ignored
|
|
52
|
+
**kwargs: Any
|
|
53
|
+
) -> Union[ChatCompletion, Generator[ChatCompletionChunk, None, None]]:
|
|
54
|
+
"""
|
|
55
|
+
Creates a model response for the given chat conversation using YEPCHAT API.
|
|
56
|
+
Mimics openai.chat.completions.create
|
|
57
|
+
Note: YEPCHAT does not support system messages. They will be ignored.
|
|
58
|
+
"""
|
|
59
|
+
if model not in self._client.AVAILABLE_MODELS:
|
|
60
|
+
raise ValueError(
|
|
61
|
+
f"Invalid model: {model}. Choose from: {self._client.AVAILABLE_MODELS}"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Filter out system messages and warn the user if any are present
|
|
65
|
+
filtered_messages = []
|
|
66
|
+
has_system_message = False
|
|
67
|
+
if get_system_prompt(messages) or system_prompt: # Check both message list and explicit param
|
|
68
|
+
has_system_message = True
|
|
69
|
+
|
|
70
|
+
for msg in messages:
|
|
71
|
+
if msg["role"] == "system":
|
|
72
|
+
continue # Skip system messages
|
|
73
|
+
filtered_messages.append(msg)
|
|
74
|
+
|
|
75
|
+
if has_system_message:
|
|
76
|
+
# Print warning in bold red
|
|
77
|
+
print(f"{BOLD}{RED}Warning: YEPCHAT does not support system messages, they will be ignored.{RESET}")
|
|
78
|
+
|
|
79
|
+
# If no messages left after filtering, raise an error
|
|
80
|
+
if not filtered_messages:
|
|
81
|
+
raise ValueError("At least one user or assistant message is required for YEPCHAT.")
|
|
82
|
+
|
|
83
|
+
payload = {
|
|
84
|
+
"stream": stream,
|
|
85
|
+
"max_tokens": max_tokens,
|
|
86
|
+
"top_p": top_p,
|
|
87
|
+
"temperature": temperature,
|
|
88
|
+
"messages": filtered_messages, # Use filtered messages
|
|
89
|
+
"model": model,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# Add any extra kwargs to the payload
|
|
93
|
+
payload.update(kwargs)
|
|
94
|
+
|
|
95
|
+
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
96
|
+
created_time = int(time.time())
|
|
97
|
+
|
|
98
|
+
if stream:
|
|
99
|
+
return self._create_stream(request_id, created_time, model, payload)
|
|
100
|
+
else:
|
|
101
|
+
return self._create_non_stream(request_id, created_time, model, payload)
|
|
102
|
+
|
|
103
|
+
def _create_stream(
|
|
104
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any]
|
|
105
|
+
) -> Generator[ChatCompletionChunk, None, None]:
|
|
106
|
+
try:
|
|
107
|
+
# Use session.post from cloudscraper instance
|
|
108
|
+
response = self._client.session.post(
|
|
109
|
+
self._client.api_endpoint,
|
|
110
|
+
headers=self._client.headers,
|
|
111
|
+
cookies=self._client.cookies,
|
|
112
|
+
json=payload,
|
|
113
|
+
stream=True,
|
|
114
|
+
timeout=self._client.timeout
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
if not response.ok:
|
|
118
|
+
# Simplified error handling for now, add refresh logic if needed
|
|
119
|
+
raise IOError(
|
|
120
|
+
f"YEPCHAT API Error: {response.status_code} {response.reason} - {response.text}"
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
124
|
+
if line:
|
|
125
|
+
line = line.strip()
|
|
126
|
+
if line.startswith("data: "):
|
|
127
|
+
json_str = line[6:]
|
|
128
|
+
if json_str == "[DONE]":
|
|
129
|
+
break
|
|
130
|
+
try:
|
|
131
|
+
data = json.loads(json_str)
|
|
132
|
+
choice_data = data.get('choices', [{}])[0]
|
|
133
|
+
delta_data = choice_data.get('delta', {})
|
|
134
|
+
finish_reason = choice_data.get('finish_reason')
|
|
135
|
+
content = delta_data.get('content')
|
|
136
|
+
|
|
137
|
+
if content is not None: # Only yield chunks with content
|
|
138
|
+
delta = ChoiceDelta(content=content, role=delta_data.get('role', 'assistant'))
|
|
139
|
+
choice = Choice(index=0, delta=delta, finish_reason=finish_reason)
|
|
140
|
+
chunk = ChatCompletionChunk(
|
|
141
|
+
id=request_id,
|
|
142
|
+
choices=[choice],
|
|
143
|
+
created=created_time,
|
|
144
|
+
model=model,
|
|
145
|
+
)
|
|
146
|
+
yield chunk
|
|
147
|
+
|
|
148
|
+
except json.JSONDecodeError:
|
|
149
|
+
print(f"Warning: Could not decode JSON line: {json_str}")
|
|
150
|
+
continue
|
|
151
|
+
|
|
152
|
+
# Yield final chunk with finish reason if not already sent
|
|
153
|
+
delta = ChoiceDelta()
|
|
154
|
+
choice = Choice(index=0, delta=delta, finish_reason="stop") # Assume stop if loop finishes
|
|
155
|
+
chunk = ChatCompletionChunk(
|
|
156
|
+
id=request_id,
|
|
157
|
+
choices=[choice],
|
|
158
|
+
created=created_time,
|
|
159
|
+
model=model,
|
|
160
|
+
)
|
|
161
|
+
yield chunk
|
|
162
|
+
|
|
163
|
+
except cloudscraper.exceptions.CloudflareChallengeError as e:
|
|
164
|
+
pass
|
|
165
|
+
|
|
166
|
+
def _create_non_stream(
|
|
167
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any]
|
|
168
|
+
) -> ChatCompletion:
|
|
169
|
+
full_response_content = ""
|
|
170
|
+
finish_reason = "stop" # Assume stop unless error occurs
|
|
171
|
+
|
|
172
|
+
try:
|
|
173
|
+
stream_generator = self._create_stream(request_id, created_time, model, payload)
|
|
174
|
+
for chunk in stream_generator:
|
|
175
|
+
if chunk.choices and chunk.choices[0].delta and chunk.choices[0].delta.content:
|
|
176
|
+
full_response_content += chunk.choices[0].delta.content
|
|
177
|
+
if chunk.choices and chunk.choices[0].finish_reason:
|
|
178
|
+
finish_reason = chunk.choices[0].finish_reason # Capture finish reason if provided
|
|
179
|
+
|
|
180
|
+
except IOError as e:
|
|
181
|
+
print(f"Error obtaining non-stream response from YEPCHAT: {e}")
|
|
182
|
+
finish_reason = "error"
|
|
183
|
+
|
|
184
|
+
# Construct the final ChatCompletion object
|
|
185
|
+
message = ChatCompletionMessage(
|
|
186
|
+
role="assistant",
|
|
187
|
+
content=full_response_content
|
|
188
|
+
)
|
|
189
|
+
choice = Choice(
|
|
190
|
+
index=0,
|
|
191
|
+
message=message,
|
|
192
|
+
finish_reason=finish_reason
|
|
193
|
+
)
|
|
194
|
+
# Usage data is not provided by this API in a standard way, set to 0
|
|
195
|
+
usage = CompletionUsage(prompt_tokens=0, completion_tokens=0, total_tokens=0)
|
|
196
|
+
|
|
197
|
+
completion = ChatCompletion(
|
|
198
|
+
id=request_id,
|
|
199
|
+
choices=[choice],
|
|
200
|
+
created=created_time,
|
|
201
|
+
model=model,
|
|
202
|
+
usage=usage,
|
|
203
|
+
)
|
|
204
|
+
return completion
|
|
205
|
+
|
|
206
|
+
class Chat(BaseChat):
|
|
207
|
+
def __init__(self, client: 'YEPCHAT'):
|
|
208
|
+
self.completions = Completions(client)
|
|
209
|
+
|
|
210
|
+
class YEPCHAT(OpenAICompatibleProvider):
|
|
211
|
+
"""
|
|
212
|
+
OpenAI-compatible client for YEPCHAT API.
|
|
213
|
+
|
|
214
|
+
Usage:
|
|
215
|
+
client = YEPCHAT()
|
|
216
|
+
response = client.chat.completions.create(
|
|
217
|
+
model="DeepSeek-R1-Distill-Qwen-32B",
|
|
218
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
219
|
+
)
|
|
220
|
+
print(response.choices[0].message.content)
|
|
221
|
+
"""
|
|
222
|
+
AVAILABLE_MODELS = ["DeepSeek-R1-Distill-Qwen-32B", "Mixtral-8x7B-Instruct-v0.1"]
|
|
223
|
+
|
|
224
|
+
def __init__(
|
|
225
|
+
self,
|
|
226
|
+
timeout: int = 30,
|
|
227
|
+
browser: str = "chrome"
|
|
228
|
+
):
|
|
229
|
+
"""
|
|
230
|
+
Initialize the YEPCHAT client.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
timeout: Request timeout in seconds.
|
|
234
|
+
browser: Browser name for LitAgent to generate User-Agent.
|
|
235
|
+
"""
|
|
236
|
+
self.timeout = timeout
|
|
237
|
+
self.api_endpoint = "https://api.yep.com/v1/chat/completions"
|
|
238
|
+
self.session = cloudscraper.create_scraper() # Use cloudscraper
|
|
239
|
+
|
|
240
|
+
# Initialize LitAgent for user agent generation and fingerprinting
|
|
241
|
+
try:
|
|
242
|
+
agent = LitAgent()
|
|
243
|
+
fingerprint = agent.generate_fingerprint(browser=browser)
|
|
244
|
+
except Exception as e:
|
|
245
|
+
print(f"Warning: Failed to generate fingerprint with LitAgent: {e}. Using fallback.")
|
|
246
|
+
# Fallback fingerprint data
|
|
247
|
+
fingerprint = {
|
|
248
|
+
"accept": "*/*",
|
|
249
|
+
"accept_language": "en-US,en;q=0.9",
|
|
250
|
+
"sec_ch_ua": '"Not/A)Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
|
|
251
|
+
"platform": "Windows",
|
|
252
|
+
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
# Initialize headers using the fingerprint
|
|
256
|
+
self.headers = {
|
|
257
|
+
"Accept": fingerprint["accept"],
|
|
258
|
+
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
259
|
+
"Accept-Language": fingerprint["accept_language"],
|
|
260
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
261
|
+
"DNT": "1",
|
|
262
|
+
"Origin": "https://yep.com",
|
|
263
|
+
"Referer": "https://yep.com/",
|
|
264
|
+
"Sec-CH-UA": fingerprint["sec_ch_ua"] or '"Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127"',
|
|
265
|
+
"Sec-CH-UA-Mobile": "?0",
|
|
266
|
+
"Sec-CH-UA-Platform": f'"{fingerprint["platform"]}"',
|
|
267
|
+
"User-Agent": fingerprint["user_agent"],
|
|
268
|
+
}
|
|
269
|
+
self.session.headers.update(self.headers)
|
|
270
|
+
|
|
271
|
+
# Generate cookies (consider if these need refreshing or specific values)
|
|
272
|
+
self.cookies = {"__Host-session": uuid.uuid4().hex, '__cf_bm': uuid.uuid4().hex}
|
|
273
|
+
|
|
274
|
+
# Initialize the chat interface
|
|
275
|
+
self.chat = Chat(self)
|
|
276
|
+
|
|
277
|
+
def convert_model_name(self, model: str) -> str:
|
|
278
|
+
"""
|
|
279
|
+
Ensures the model name is valid for YEPCHAT.
|
|
280
|
+
Returns the validated model name or raises an error if invalid.
|
|
281
|
+
"""
|
|
282
|
+
if model in self.AVAILABLE_MODELS:
|
|
283
|
+
return model
|
|
284
|
+
else:
|
|
285
|
+
# Raise error instead of defaulting, as model is mandatory in create()
|
|
286
|
+
raise ValueError(f"Model '{model}' not supported by YEPCHAT. Available: {self.AVAILABLE_MODELS}")
|
|
287
|
+
|
|
288
|
+
# Example usage (optional, for testing)
|
|
289
|
+
if __name__ == '__main__':
|
|
290
|
+
print("Testing YEPCHAT OpenAI-Compatible Client...")
|
|
291
|
+
|
|
292
|
+
# Test Non-Streaming
|
|
293
|
+
try:
|
|
294
|
+
print("\n--- Non-Streaming Test (DeepSeek) ---")
|
|
295
|
+
client = YEPCHAT()
|
|
296
|
+
response = client.chat.completions.create(
|
|
297
|
+
model="DeepSeek-R1-Distill-Qwen-32B",
|
|
298
|
+
messages=[
|
|
299
|
+
{"role": "user", "content": "Say 'Hello World'"}
|
|
300
|
+
],
|
|
301
|
+
stream=False
|
|
302
|
+
)
|
|
303
|
+
print("Response:", response.choices[0].message.content)
|
|
304
|
+
print("Usage:", response.usage) # Will show 0 tokens
|
|
305
|
+
except Exception as e:
|
|
306
|
+
print(f"Non-Streaming Test Failed: {e}")
|
|
307
|
+
|
|
308
|
+
# Test Streaming
|
|
309
|
+
try:
|
|
310
|
+
print("\n--- Streaming Test (Mixtral) ---")
|
|
311
|
+
client_stream = YEPCHAT()
|
|
312
|
+
stream = client_stream.chat.completions.create(
|
|
313
|
+
model="Mixtral-8x7B-Instruct-v0.1",
|
|
314
|
+
messages=[
|
|
315
|
+
{"role": "user", "content": "Write a short sentence about AI."}
|
|
316
|
+
],
|
|
317
|
+
stream=True
|
|
318
|
+
)
|
|
319
|
+
print("Streaming Response:")
|
|
320
|
+
full_stream_response = ""
|
|
321
|
+
for chunk in stream:
|
|
322
|
+
content = chunk.choices[0].delta.content
|
|
323
|
+
if content:
|
|
324
|
+
print(content, end="", flush=True)
|
|
325
|
+
full_stream_response += content
|
|
326
|
+
print("\n--- End of Stream ---")
|
|
327
|
+
print("Full streamed text:", full_stream_response)
|
|
328
|
+
except Exception as e:
|
|
329
|
+
print(f"Streaming Test Failed: {e}")
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
from os import system
|
|
2
|
+
import requests
|
|
3
|
+
import json
|
|
4
|
+
import uuid
|
|
5
|
+
import re
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Any, Dict, Optional, Union, Generator
|
|
8
|
+
from webscout.AIutel import Optimizers
|
|
9
|
+
from webscout.AIutel import Conversation
|
|
10
|
+
from webscout.AIutel import AwesomePrompts
|
|
11
|
+
from webscout.AIbase import Provider
|
|
12
|
+
from webscout import exceptions
|
|
13
|
+
from webscout.litagent import LitAgent
|
|
14
|
+
|
|
15
|
+
class StandardInputAI(Provider):
|
|
16
|
+
"""
|
|
17
|
+
A class to interact with the Standard Input chat API.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
AVAILABLE_MODELS = {
|
|
21
|
+
"standard-quick": "quick",
|
|
22
|
+
"standard-reasoning": "quick", # Same model but with reasoning enabled
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
is_conversation: bool = True,
|
|
28
|
+
max_tokens: int = 2049,
|
|
29
|
+
timeout: int = 30,
|
|
30
|
+
intro: str = None,
|
|
31
|
+
filepath: str = None,
|
|
32
|
+
update_file: bool = True,
|
|
33
|
+
proxies: dict = {},
|
|
34
|
+
history_offset: int = 10250,
|
|
35
|
+
act: str = None,
|
|
36
|
+
model: str = "standard-quick",
|
|
37
|
+
chat_id: str = None,
|
|
38
|
+
user_id: str = None,
|
|
39
|
+
browser: str = "chrome",
|
|
40
|
+
system_prompt: str = "You are a helpful assistant.",
|
|
41
|
+
enable_reasoning: bool = False,
|
|
42
|
+
):
|
|
43
|
+
"""
|
|
44
|
+
Initializes the Standard Input API client.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
is_conversation (bool): Whether to maintain conversation history.
|
|
48
|
+
max_tokens (int): Maximum number of tokens to generate.
|
|
49
|
+
timeout (int): Request timeout in seconds.
|
|
50
|
+
intro (str): Introduction text for the conversation.
|
|
51
|
+
filepath (str): Path to save conversation history.
|
|
52
|
+
update_file (bool): Whether to update the conversation history file.
|
|
53
|
+
proxies (dict): Proxy configuration for requests.
|
|
54
|
+
history_offset (int): Maximum history length in characters.
|
|
55
|
+
act (str): Persona for the AI to adopt.
|
|
56
|
+
model (str): Model to use, must be one of AVAILABLE_MODELS.
|
|
57
|
+
chat_id (str): Unique identifier for the chat session.
|
|
58
|
+
user_id (str): Unique identifier for the user.
|
|
59
|
+
browser (str): Browser to emulate in requests.
|
|
60
|
+
system_prompt (str): System prompt for the AI.
|
|
61
|
+
enable_reasoning (bool): Whether to enable reasoning feature.
|
|
62
|
+
"""
|
|
63
|
+
if model not in self.AVAILABLE_MODELS:
|
|
64
|
+
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
|
|
65
|
+
|
|
66
|
+
self.url = "https://chat.standard-input.com/api/chat"
|
|
67
|
+
|
|
68
|
+
# Initialize LitAgent for user agent generation
|
|
69
|
+
self.agent = LitAgent()
|
|
70
|
+
# Use fingerprinting to create a consistent browser identity
|
|
71
|
+
self.fingerprint = self.agent.generate_fingerprint(browser)
|
|
72
|
+
self.system_prompt = system_prompt
|
|
73
|
+
|
|
74
|
+
# Use the fingerprint for headers
|
|
75
|
+
self.headers = {
|
|
76
|
+
"accept": "*/*",
|
|
77
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
78
|
+
"accept-language": self.fingerprint["accept_language"],
|
|
79
|
+
"content-type": "application/json",
|
|
80
|
+
"dnt": "1",
|
|
81
|
+
"origin": "https://chat.standard-input.com",
|
|
82
|
+
"referer": "https://chat.standard-input.com/",
|
|
83
|
+
"sec-ch-ua": self.fingerprint["sec_ch_ua"] or '"Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
|
|
84
|
+
"sec-ch-ua-mobile": "?0",
|
|
85
|
+
"sec-ch-ua-platform": f'"{self.fingerprint["platform"]}"',
|
|
86
|
+
"sec-fetch-dest": "empty",
|
|
87
|
+
"sec-fetch-mode": "cors",
|
|
88
|
+
"sec-fetch-site": "same-origin",
|
|
89
|
+
"sec-gpc": "1",
|
|
90
|
+
"user-agent": self.fingerprint["user_agent"],
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# Default cookies - these should be updated for production use
|
|
94
|
+
self.cookies = {
|
|
95
|
+
"auth-chat": '''%7B%22user%22%3A%7B%22id%22%3A%2243a26ebd-7691-4a5a-8321-12aff017af86%22%2C%22email%22%3A%22iu511inmev%40illubd.com%22%2C%22accountId%22%3A%22057d78c9-06db-48eb-aeaa-0efdbaeb9446%22%2C%22provider%22%3A%22password%22%7D%2C%22tokens%22%3A%7B%22access%22%3A%22eyJhbGciOiJFUzI1NiIsImtpZCI6Ijg1NDhmZWY1LTk5MjYtNDk2Yi1hMjI2LTQ5OTExYjllYzU2NSIsInR5cCI6IkpXVCJ9.eyJtb2RlIjoiYWNjZXNzIiwidHlwZSI6InVzZXIiLCJwcm9wZXJ0aWVzIjp7ImlkIjoiNDNhMjZlYmQtNzY5MS00YTVhLTgzMzEtMTJhZmYwMTdhZjg2IiwiZW1haWwiOiJpdTUxMWlubWV2QGlsbHViZC5jb20iLCJhY2NvdW50SWQiOiIwNTdkNzhjOS0wNmRiLTQ4ZWItYWVhYS0wZWZkYmFlYjk0NDYiLCJwcm92aWRlciI6InBhc3N3b3JkIn0sImF1ZCI6InN0YW5kYXJkLWlucHV0LWlvcyIsImlzcyI6Imh0dHBzOi8vYXV0aC5zdGFuZGFyZC1pbnB1dC5jb20iLCJzdWIiOiJ1c2VyOjRmYWMzMTllZjA4MDRiZmMiLCJleHAiOjE3NDU0MDU5MDN9.d3VsEq-UCNsQWkiPlTVw7caS0wTXfCYe6yeFLeb4Ce6ZYTIFFn685SF-aKvLOxaYaq7Pyk4D2qr24riPVhxUWQ%22%2C%22refresh%22%3A%22user%3A4fac319ef0804bfc%3A3a757177-5507-4a36-9356-492f5ed06105%22%7D%7D''',
|
|
96
|
+
"auth": '''%7B%22user%22%3A%7B%22id%22%3A%22c51e291f-8f44-439d-a38b-9ea147581a13%22%2C%22email%22%3A%22r6cigexlsb%40mrotzis.com%22%2C%22accountId%22%3A%22599fd4ce-04a2-40f6-a78f-d33d0059b77f%22%2C%22provider%22%3A%22password%22%7D%2C%22tokens%22%3A%7B%22access%22%3A%22eyJhbGciOiJFUzI1NiIsImtpZCI6Ijg1NDhmZWY1LTk5MjYtNDk2Yi1hMjI2LTQ5OTExYjllYzU2NSIsInR5cCI6IkpXVCJ9.eyJtb2RlIjoiYWNjZXNzIiwidHlwZSI6InVzZXIiLCJwcm9wZXJ0aWVzIjp7ImlkIjoiYzUxZTI5MWYtOGY0NC00MzlkLWEzOGItOWVhMTQ3NTgxYTEzIiwiZW1haWwiOiJyNmNpZ2V4bHNiQG1yb3R6aXMuY29tIiwiYWNjb3VudElkIjoiNTk5ZmQ0Y2UtMDRhMi00MGY2LWE3OGYtZDMzZDAwNTliNzdmIiwicHJvdmlkZXIiOiJwYXNzd29yZCJ9LCJhdWQiOiJzdGFuZGFyZC1pbnB1dC1pb3MiLCJpc3MiOiJodHRwczovL2F1dGguc3RhbmRhcmQtaW5wdXQuY29tIiwic3ViIjoidXNlcjo4Y2FmMjRkYzUxNDc4MmNkIiwiZXhwIjoxNzQ2NzI0MTU3fQ.a3970nBJkd8JoU-khRA2JlRMuYeJ7378QS4ZL446kOkDi35uTwuC4qGrWH9efk9GkFaVcWPtYeOJjRb7f2SeJA%22%2C%22refresh%22%3A%22user%3A8caf24dc514782cd%3A14e24386-8443-4df0-ae25-234ad59218ef%22%7D%7D''',
|
|
97
|
+
"sidebar:state": "true",
|
|
98
|
+
"ph_phc_f3wUUyCfmKlKtkc2pfT7OsdcW2mBEVGN2A87yEYbG3c_posthog": '''%7B%22distinct_id%22%3A%220195c7cc-ac8f-79ff-b901-e14a78fc2a67%22%2C%22%24sesid%22%3A%5B1744688627860%2C%220196377f-9f12-77e6-a9ea-0e9669423803%22%2C1744687832850%5D%2C%22%24initial_person_info%22%3A%7B%22r%22%3A%22%24direct%22%2C%22u%22%3A%22https%3A%2F%2Fstandard-input.com%2F%22%7D%7D'''
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
self.session = requests.Session()
|
|
102
|
+
self.session.headers.update(self.headers)
|
|
103
|
+
self.session.proxies.update(proxies)
|
|
104
|
+
|
|
105
|
+
self.is_conversation = is_conversation
|
|
106
|
+
self.max_tokens_to_sample = max_tokens
|
|
107
|
+
self.timeout = timeout
|
|
108
|
+
self.last_response = {}
|
|
109
|
+
self.model = model
|
|
110
|
+
self.chat_id = chat_id or str(uuid.uuid4())
|
|
111
|
+
self.user_id = user_id or f"user_{str(uuid.uuid4())[:8].upper()}"
|
|
112
|
+
self.enable_reasoning = enable_reasoning
|
|
113
|
+
|
|
114
|
+
self.__available_optimizers = (
|
|
115
|
+
method
|
|
116
|
+
for method in dir(Optimizers)
|
|
117
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
118
|
+
)
|
|
119
|
+
Conversation.intro = (
|
|
120
|
+
AwesomePrompts().get_act(
|
|
121
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
122
|
+
)
|
|
123
|
+
if act
|
|
124
|
+
else intro or Conversation.intro
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
self.conversation = Conversation(
|
|
128
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
129
|
+
)
|
|
130
|
+
self.conversation.history_offset = history_offset
|
|
131
|
+
|
|
132
|
+
def refresh_identity(self, browser: str = None):
|
|
133
|
+
"""
|
|
134
|
+
Refreshes the browser identity fingerprint.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
browser: Specific browser to use for the new fingerprint
|
|
138
|
+
"""
|
|
139
|
+
browser = browser or self.fingerprint.get("browser_type", "chrome")
|
|
140
|
+
self.fingerprint = self.agent.generate_fingerprint(browser)
|
|
141
|
+
|
|
142
|
+
# Update headers with new fingerprint
|
|
143
|
+
self.headers.update({
|
|
144
|
+
"Accept-Language": self.fingerprint["accept_language"],
|
|
145
|
+
"Sec-CH-UA": self.fingerprint["sec_ch_ua"] or self.headers["sec-ch-ua"],
|
|
146
|
+
"Sec-CH-UA-Platform": f'"{self.fingerprint["platform"]}"',
|
|
147
|
+
"User-Agent": self.fingerprint["user_agent"],
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
# Update session headers
|
|
151
|
+
for header, value in self.headers.items():
|
|
152
|
+
self.session.headers[header] = value
|
|
153
|
+
|
|
154
|
+
return self.fingerprint
|
|
155
|
+
|
|
156
|
+
def ask(
|
|
157
|
+
self,
|
|
158
|
+
prompt: str,
|
|
159
|
+
optimizer: str = None,
|
|
160
|
+
conversationally: bool = False,
|
|
161
|
+
) -> Dict[str, Any]:
|
|
162
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
163
|
+
if optimizer:
|
|
164
|
+
if optimizer in self.__available_optimizers:
|
|
165
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
166
|
+
conversation_prompt if conversationally else prompt
|
|
167
|
+
)
|
|
168
|
+
else:
|
|
169
|
+
raise Exception(f"Optimizer is not one of {self.__available_optimizers}")
|
|
170
|
+
|
|
171
|
+
# Prepare the messages
|
|
172
|
+
messages = [
|
|
173
|
+
{"role": "system", "content": self.system_prompt},
|
|
174
|
+
{"role": "user", "content": conversation_prompt, "parts": [{"type": "text", "text": conversation_prompt}]}
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
# Prepare the request payload
|
|
178
|
+
payload = {
|
|
179
|
+
"id": self.chat_id,
|
|
180
|
+
"messages": messages,
|
|
181
|
+
"modelId": self.AVAILABLE_MODELS[self.model],
|
|
182
|
+
"enabledFeatures": ["reasoning"] if self.enable_reasoning or self.model == "standard-reasoning" else []
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
try:
|
|
186
|
+
response = self.session.post(self.url, cookies=self.cookies, json=payload, stream=True, timeout=self.timeout)
|
|
187
|
+
if response.status_code != 200:
|
|
188
|
+
# Try to get response content for better error messages
|
|
189
|
+
try:
|
|
190
|
+
error_content = response.text
|
|
191
|
+
except:
|
|
192
|
+
error_content = "<could not read response content>"
|
|
193
|
+
|
|
194
|
+
if response.status_code in [403, 429]:
|
|
195
|
+
print(f"Received status code {response.status_code}, refreshing identity...")
|
|
196
|
+
self.refresh_identity()
|
|
197
|
+
response = self.session.post(self.url, cookies=self.cookies, json=payload, stream=True, timeout=self.timeout)
|
|
198
|
+
if not response.ok:
|
|
199
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
200
|
+
f"Failed to generate response after identity refresh - ({response.status_code}, {response.reason}) - {error_content}"
|
|
201
|
+
)
|
|
202
|
+
print("Identity refreshed successfully.")
|
|
203
|
+
else:
|
|
204
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
205
|
+
f"Request failed with status code {response.status_code}. Response: {error_content}"
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
full_response = ""
|
|
209
|
+
debug_lines = []
|
|
210
|
+
|
|
211
|
+
# Process the streaming response
|
|
212
|
+
for i, line in enumerate(response.iter_lines(decode_unicode=True)):
|
|
213
|
+
if line:
|
|
214
|
+
try:
|
|
215
|
+
line_str = line
|
|
216
|
+
debug_lines.append(line_str)
|
|
217
|
+
|
|
218
|
+
# Extract content from the response
|
|
219
|
+
match = re.search(r'0:"(.*?)"', line_str)
|
|
220
|
+
if match:
|
|
221
|
+
content = match.group(1)
|
|
222
|
+
full_response += content
|
|
223
|
+
continue
|
|
224
|
+
except: pass
|
|
225
|
+
|
|
226
|
+
self.last_response = {"text": full_response}
|
|
227
|
+
self.conversation.update_chat_history(prompt, full_response)
|
|
228
|
+
return {"text": full_response}
|
|
229
|
+
except Exception as e:
|
|
230
|
+
raise exceptions.FailedToGenerateResponseError(f"Request failed: {e}")
|
|
231
|
+
|
|
232
|
+
def chat(
|
|
233
|
+
self,
|
|
234
|
+
prompt: str,
|
|
235
|
+
optimizer: str = None,
|
|
236
|
+
conversationally: bool = False,
|
|
237
|
+
) -> str:
|
|
238
|
+
return self.get_message(
|
|
239
|
+
self.ask(
|
|
240
|
+
prompt, optimizer=optimizer, conversationally=conversationally
|
|
241
|
+
)
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
def get_message(self, response: dict) -> str:
|
|
245
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
246
|
+
return response["text"].replace('\\n', '\n').replace('\\n\\n', '\n\n')
|
|
247
|
+
|
|
248
|
+
if __name__ == "__main__":
|
|
249
|
+
print("-" * 100)
|
|
250
|
+
print(f"{'Model':<50} {'Status':<10} {'Response'}")
|
|
251
|
+
print("-" * 100)
|
|
252
|
+
|
|
253
|
+
test_prompt = "Say 'Hello' in one word"
|
|
254
|
+
|
|
255
|
+
# Test each model
|
|
256
|
+
for model in StandardInputAI.AVAILABLE_MODELS:
|
|
257
|
+
print(f"\rTesting {model}...", end="")
|
|
258
|
+
|
|
259
|
+
try:
|
|
260
|
+
test_ai = StandardInputAI(model=model, timeout=120) # Increased timeout
|
|
261
|
+
response = test_ai.chat(test_prompt)
|
|
262
|
+
|
|
263
|
+
if response and len(response.strip()) > 0:
|
|
264
|
+
status = "✓"
|
|
265
|
+
# Clean and truncate response
|
|
266
|
+
clean_text = response.strip().encode('utf-8', errors='ignore').decode('utf-8')
|
|
267
|
+
display_text = clean_text[:50] + "..." if len(clean_text) > 50 else clean_text
|
|
268
|
+
else:
|
|
269
|
+
status = "✗"
|
|
270
|
+
display_text = "Empty or invalid response"
|
|
271
|
+
|
|
272
|
+
print(f"\r{model:<50} {status:<10} {display_text}")
|
|
273
|
+
except Exception as e:
|
|
274
|
+
error_msg = str(e)
|
|
275
|
+
# Truncate very long error messages
|
|
276
|
+
if len(error_msg) > 100:
|
|
277
|
+
error_msg = error_msg[:97] + "..."
|
|
278
|
+
print(f"\r{model:<50} {'✗':<10} Error: {error_msg}")
|
|
@@ -12,34 +12,33 @@ class TextPollinationsAI(Provider):
|
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
14
|
AVAILABLE_MODELS = [
|
|
15
|
-
"openai",
|
|
16
|
-
"openai-large",
|
|
17
|
-
"openai-reasoning",
|
|
18
|
-
"qwen-coder",
|
|
19
|
-
"llama",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"deepseek-reasoning
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"gemini
|
|
34
|
-
"hormoz",
|
|
35
|
-
"hypnosis-tracy",
|
|
36
|
-
"mistral-roblox",
|
|
37
|
-
"roblox-rp",
|
|
38
|
-
"deepseek",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"openai-audio", # OpenAI GPT-4o-audio-preview
|
|
15
|
+
"openai",
|
|
16
|
+
"openai-large",
|
|
17
|
+
"openai-reasoning",
|
|
18
|
+
"qwen-coder",
|
|
19
|
+
"llama",
|
|
20
|
+
"llamascout",
|
|
21
|
+
"mistral",
|
|
22
|
+
"unity",
|
|
23
|
+
"midijourney",
|
|
24
|
+
"rtist",
|
|
25
|
+
"searchgpt",
|
|
26
|
+
"evil",
|
|
27
|
+
"deepseek-reasoning",
|
|
28
|
+
"deepseek-reasoning-large",
|
|
29
|
+
"llamalight",
|
|
30
|
+
"phi",
|
|
31
|
+
"llama-vision",
|
|
32
|
+
"pixtral",
|
|
33
|
+
"gemini",
|
|
34
|
+
"hormoz",
|
|
35
|
+
"hypnosis-tracy",
|
|
36
|
+
"mistral-roblox",
|
|
37
|
+
"roblox-rp",
|
|
38
|
+
"deepseek",
|
|
39
|
+
"sur",
|
|
40
|
+
"llama-scaleway",
|
|
41
|
+
"openai-audio",
|
|
43
42
|
]
|
|
44
43
|
|
|
45
44
|
def __init__(
|