webscout 8.2.6__py3-none-any.whl → 8.2.8__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 +1 -1
- webscout/AIutel.py +298 -239
- webscout/Extra/Act.md +309 -0
- webscout/Extra/GitToolkit/gitapi/README.md +110 -0
- webscout/Extra/YTToolkit/README.md +375 -0
- webscout/Extra/YTToolkit/ytapi/README.md +44 -0
- webscout/Extra/YTToolkit/ytapi/extras.py +92 -19
- webscout/Extra/autocoder/autocoder.py +309 -114
- webscout/Extra/autocoder/autocoder_utiles.py +15 -15
- webscout/Extra/gguf.md +430 -0
- webscout/Extra/tempmail/README.md +488 -0
- webscout/Extra/weather.md +281 -0
- webscout/Litlogger/Readme.md +175 -0
- webscout/Provider/AISEARCH/DeepFind.py +41 -37
- webscout/Provider/AISEARCH/README.md +279 -0
- webscout/Provider/AISEARCH/__init__.py +0 -1
- webscout/Provider/AISEARCH/genspark_search.py +228 -86
- webscout/Provider/AISEARCH/hika_search.py +11 -11
- webscout/Provider/AISEARCH/scira_search.py +324 -322
- webscout/Provider/AllenAI.py +7 -14
- webscout/Provider/Blackboxai.py +518 -74
- webscout/Provider/Cloudflare.py +0 -1
- webscout/Provider/Deepinfra.py +23 -21
- webscout/Provider/Flowith.py +217 -0
- webscout/Provider/FreeGemini.py +250 -0
- webscout/Provider/GizAI.py +15 -5
- webscout/Provider/Glider.py +11 -8
- webscout/Provider/HeckAI.py +80 -52
- webscout/Provider/Koboldai.py +7 -4
- webscout/Provider/LambdaChat.py +2 -2
- webscout/Provider/Marcus.py +10 -18
- webscout/Provider/OPENAI/BLACKBOXAI.py +735 -0
- webscout/Provider/OPENAI/Cloudflare.py +378 -0
- webscout/Provider/OPENAI/FreeGemini.py +282 -0
- webscout/Provider/OPENAI/NEMOTRON.py +244 -0
- webscout/Provider/OPENAI/README.md +1253 -0
- webscout/Provider/OPENAI/__init__.py +8 -0
- webscout/Provider/OPENAI/ai4chat.py +293 -286
- webscout/Provider/OPENAI/api.py +810 -0
- webscout/Provider/OPENAI/base.py +217 -14
- webscout/Provider/OPENAI/c4ai.py +373 -367
- webscout/Provider/OPENAI/chatgpt.py +7 -0
- webscout/Provider/OPENAI/chatgptclone.py +7 -0
- webscout/Provider/OPENAI/chatsandbox.py +172 -0
- webscout/Provider/OPENAI/deepinfra.py +30 -20
- webscout/Provider/OPENAI/e2b.py +6 -0
- webscout/Provider/OPENAI/exaai.py +7 -0
- webscout/Provider/OPENAI/exachat.py +6 -0
- webscout/Provider/OPENAI/flowith.py +162 -0
- webscout/Provider/OPENAI/freeaichat.py +359 -352
- webscout/Provider/OPENAI/glider.py +323 -316
- webscout/Provider/OPENAI/groq.py +361 -354
- webscout/Provider/OPENAI/heckai.py +30 -64
- webscout/Provider/OPENAI/llmchatco.py +8 -0
- webscout/Provider/OPENAI/mcpcore.py +7 -0
- webscout/Provider/OPENAI/multichat.py +8 -0
- webscout/Provider/OPENAI/netwrck.py +356 -350
- webscout/Provider/OPENAI/opkfc.py +8 -0
- webscout/Provider/OPENAI/scirachat.py +471 -462
- webscout/Provider/OPENAI/sonus.py +9 -0
- webscout/Provider/OPENAI/standardinput.py +9 -1
- webscout/Provider/OPENAI/textpollinations.py +339 -329
- webscout/Provider/OPENAI/toolbaz.py +7 -0
- webscout/Provider/OPENAI/typefully.py +355 -0
- webscout/Provider/OPENAI/typegpt.py +358 -346
- webscout/Provider/OPENAI/uncovrAI.py +7 -0
- webscout/Provider/OPENAI/utils.py +103 -7
- webscout/Provider/OPENAI/venice.py +12 -0
- webscout/Provider/OPENAI/wisecat.py +19 -19
- webscout/Provider/OPENAI/writecream.py +7 -0
- webscout/Provider/OPENAI/x0gpt.py +7 -0
- webscout/Provider/OPENAI/yep.py +50 -21
- webscout/Provider/OpenGPT.py +1 -1
- webscout/Provider/TTI/AiForce/README.md +159 -0
- webscout/Provider/TTI/FreeAIPlayground/README.md +99 -0
- webscout/Provider/TTI/ImgSys/README.md +174 -0
- webscout/Provider/TTI/MagicStudio/README.md +101 -0
- webscout/Provider/TTI/Nexra/README.md +155 -0
- webscout/Provider/TTI/PollinationsAI/README.md +146 -0
- webscout/Provider/TTI/README.md +128 -0
- webscout/Provider/TTI/aiarta/README.md +134 -0
- webscout/Provider/TTI/artbit/README.md +100 -0
- webscout/Provider/TTI/fastflux/README.md +129 -0
- webscout/Provider/TTI/huggingface/README.md +114 -0
- webscout/Provider/TTI/piclumen/README.md +161 -0
- webscout/Provider/TTI/pixelmuse/README.md +79 -0
- webscout/Provider/TTI/talkai/README.md +139 -0
- webscout/Provider/TTS/README.md +192 -0
- webscout/Provider/TTS/__init__.py +2 -1
- webscout/Provider/TTS/speechma.py +500 -100
- webscout/Provider/TTS/sthir.py +94 -0
- webscout/Provider/TeachAnything.py +3 -7
- webscout/Provider/TextPollinationsAI.py +4 -2
- webscout/Provider/{aimathgpt.py → UNFINISHED/ChatHub.py} +88 -68
- webscout/Provider/UNFINISHED/liner_api_request.py +263 -0
- webscout/Provider/UNFINISHED/oivscode.py +351 -0
- webscout/Provider/UNFINISHED/test_lmarena.py +119 -0
- webscout/Provider/Writecream.py +11 -2
- webscout/Provider/__init__.py +8 -14
- webscout/Provider/ai4chat.py +4 -58
- webscout/Provider/asksteve.py +17 -9
- webscout/Provider/cerebras.py +3 -1
- webscout/Provider/koala.py +170 -268
- webscout/Provider/llmchat.py +3 -0
- webscout/Provider/lmarena.py +198 -0
- webscout/Provider/meta.py +7 -4
- webscout/Provider/samurai.py +223 -0
- webscout/Provider/scira_chat.py +4 -2
- webscout/Provider/typefully.py +23 -151
- webscout/__init__.py +4 -2
- webscout/cli.py +3 -28
- webscout/conversation.py +35 -35
- webscout/litagent/Readme.md +276 -0
- webscout/scout/README.md +402 -0
- webscout/swiftcli/Readme.md +323 -0
- webscout/version.py +1 -1
- webscout/webscout_search.py +2 -182
- webscout/webscout_search_async.py +1 -179
- webscout/zeroart/README.md +89 -0
- webscout/zeroart/__init__.py +134 -54
- webscout/zeroart/base.py +19 -13
- webscout/zeroart/effects.py +101 -99
- webscout/zeroart/fonts.py +1239 -816
- {webscout-8.2.6.dist-info → webscout-8.2.8.dist-info}/METADATA +116 -74
- {webscout-8.2.6.dist-info → webscout-8.2.8.dist-info}/RECORD +130 -103
- {webscout-8.2.6.dist-info → webscout-8.2.8.dist-info}/WHEEL +1 -1
- webscout-8.2.8.dist-info/entry_points.txt +3 -0
- webscout-8.2.8.dist-info/top_level.txt +1 -0
- webscout/Provider/AISEARCH/ISou.py +0 -256
- webscout/Provider/ElectronHub.py +0 -773
- webscout/Provider/Free2GPT.py +0 -241
- webscout/Provider/GPTWeb.py +0 -249
- webscout/Provider/bagoodex.py +0 -145
- webscout/Provider/geminiprorealtime.py +0 -160
- webscout/scout/core.py +0 -881
- webscout-8.2.6.dist-info/entry_points.txt +0 -3
- webscout-8.2.6.dist-info/top_level.txt +0 -2
- webstoken/__init__.py +0 -30
- webstoken/classifier.py +0 -189
- webstoken/keywords.py +0 -216
- webstoken/language.py +0 -128
- webstoken/ner.py +0 -164
- webstoken/normalizer.py +0 -35
- webstoken/processor.py +0 -77
- webstoken/sentiment.py +0 -206
- webstoken/stemmer.py +0 -73
- webstoken/tagger.py +0 -60
- webstoken/tokenizer.py +0 -158
- /webscout/Provider/{Youchat.py → UNFINISHED/Youchat.py} +0 -0
- {webscout-8.2.6.dist-info → webscout-8.2.8.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional, Union, Generator
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
import re
|
|
4
|
+
from curl_cffi.requests import Session
|
|
5
|
+
from curl_cffi import CurlError
|
|
6
|
+
from webscout.AIbase import Provider
|
|
7
|
+
from webscout.AIutel import Optimizers, Conversation, AwesomePrompts, sanitize_stream
|
|
8
|
+
from webscout.litagent import LitAgent
|
|
9
|
+
from webscout import exceptions
|
|
10
|
+
|
|
11
|
+
class lmarena(Provider):
|
|
12
|
+
"""
|
|
13
|
+
Provider for the Arena API (battle mode).
|
|
14
|
+
"""
|
|
15
|
+
AVAILABLE_MODELS = ["arena-battle"]
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
is_conversation: bool = True,
|
|
20
|
+
max_tokens: int = 2048,
|
|
21
|
+
timeout: int = 30,
|
|
22
|
+
intro: str = None,
|
|
23
|
+
filepath: str = None,
|
|
24
|
+
update_file: bool = True,
|
|
25
|
+
proxies: dict = {},
|
|
26
|
+
history_offset: int = 10250,
|
|
27
|
+
act: str = None,
|
|
28
|
+
):
|
|
29
|
+
self.url = "https://arena-api-stable.vercel.app/evaluation"
|
|
30
|
+
self.session = Session()
|
|
31
|
+
self.is_conversation = is_conversation
|
|
32
|
+
self.max_tokens_to_sample = max_tokens
|
|
33
|
+
self.timeout = timeout
|
|
34
|
+
self.last_response = {}
|
|
35
|
+
self.supabase_jwt = "base64-eyJhY2Nlc3NfdG9rZW4iOiJleUpoYkdjaU9pSklVekkxTmlJc0ltdHBaQ0k2SWtOVFQwNHhkM05uU0hkRlNFTkNNbGNpTENKMGVYQWlPaUpLVjFRaWZRLmV5SnBjM01pT2lKb2RIUndjem92TDJoMWIyZDZiMlZ4ZW1OeVpIWnJkM1IyYjJScExuTjFjR0ZpWVhObExtTnZMMkYxZEdndmRqRWlMQ0p6ZFdJaU9pSXhNV0kxT1ROaE9DMHpZak5sTFRSak1UQXRPRE13TUMwMk16QTBNMk15TW1VeU1qWWlMQ0poZFdRaU9pSmhkWFJvWlc1MGFXTmhkR1ZrSWl3aVpYaHdJam94TnpRM05UUXhPVGc1TENKcFlYUWlPakUzTkRjMU16Z3pPRGtzSW1WdFlXbHNJam9pSWl3aWNHaHZibVVpT2lJaUxDSmhjSEJmYldWMFlXUmhkR0VpT250OUxDSjFjMlZ5WDIxbGRHRmtZWFJoSWpwN0ltbGtJam9pTW1aaU1qVXhPRGN0T0RFMFppMDBNR0l3TFdJNE5UQXRZemswTnpOak1EVTVNakZtSW4wc0luSnZiR1VpT2lKaGRYUm9aVzUwYVdOaGRHVmtJaXdpWVdGc0lqb2lZV0ZzTVNJc0ltRnRjaUk2VzNzaWJXVjBhRzlrSWpvaVlXNXZibmx0YjNWeklpd2lkR2x0WlhOMFlXMXdJam94TnpRME9UWTJOak15ZlYwc0luTmxjM05wYjI1ZmFXUWlPaUl3TjJWaE5UZGtNeTFsT1RNMkxUUXpZVE10WW1Oa05pMW1aREZpTjJOa01ESmpaV0lpTENKcGMxOWhibTl1ZVcxdmRYTWlPblJ5ZFdWOS5jR3VsYlBRRmQ5MzZmcmpmdC1oWjBUQ0k1Rk1sdVU5ZUNac3h3VkNVTkhrIiwidG9rZW5fdHlwZSI6ImJlYXJlciIsImV4cGlyZXNfaW4iOjM2MDAsImV4cGlyZXNfYXQiOjE3NDc1NDE5ODksInJlZnJlc2hfdG9rZW4iOiJ0cG95ZTViN2s2N3kiLCJ1c2VyIjp7ImlkIjoiMTFiNTkzYTgtM2IzZS00YzEwLTgzMDAtNjMwNDNjMjJlMjI2IiwiYXVkIjoiYXV0aGVudGljYXRlZCIsInJvbGUiOiJhdXRoZW50aWNhdGVkIiwiZW1haWwiOiIiLCJwaG9uZSI6IiIsImxhc3Rfc2lnbl9pbl9hdCI6IjIwMjUtMDQtMThUMDg6NTc6MTIuNzMxMzg1WiIsImFwcF9tZXRhZGF0YSI6e30sInVzZXJfbWV0YWRhdGEiOnsiaWQiOiIyZmIyNTE4Ny04MTRmLTQwYjAtYjg1MC1jOTQ3M2MwNTkyMWYifSwiaWRlbnRpdGllcyI6W10sImNyZWF0ZWRfYXQiOiIyMDI1LTA0LTE4VDA4OjU3OjEyLjcyODk4NVoiLCJ1cGRhdGVkX2F0IjoiMjAyNS0wNS0xOFQwMzoxOTo0OS4yNzkxNzJaIiwiaXNfYW5vbnltb3VzIjp0cnVlfX0"
|
|
36
|
+
self.agent = LitAgent()
|
|
37
|
+
self.headers = {
|
|
38
|
+
"accept": "*/*",
|
|
39
|
+
"content-type": "application/json",
|
|
40
|
+
"origin": "https://beta.lmarena.ai",
|
|
41
|
+
"referer": "https://arena-api-stable.vercel.app/",
|
|
42
|
+
}
|
|
43
|
+
if self.supabase_jwt:
|
|
44
|
+
self.headers["supabase-jwt"] = self.supabase_jwt
|
|
45
|
+
self.session.headers.update(self.headers)
|
|
46
|
+
self.session.proxies = proxies
|
|
47
|
+
self.__available_optimizers = (
|
|
48
|
+
method
|
|
49
|
+
for method in dir(Optimizers)
|
|
50
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
51
|
+
)
|
|
52
|
+
Conversation.intro = (
|
|
53
|
+
AwesomePrompts().get_act(
|
|
54
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
55
|
+
)
|
|
56
|
+
if act
|
|
57
|
+
else intro or Conversation.intro
|
|
58
|
+
)
|
|
59
|
+
self.conversation = Conversation(
|
|
60
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
61
|
+
)
|
|
62
|
+
self.conversation.history_offset = history_offset
|
|
63
|
+
|
|
64
|
+
@staticmethod
|
|
65
|
+
def _arena_extractor(chunk: Union[str, Dict[str, Any]]) -> Optional[str]:
|
|
66
|
+
"""Extracts content from the arena stream format 'b0:"..."'."""
|
|
67
|
+
if isinstance(chunk, str):
|
|
68
|
+
match = re.search(r'b0:"(.*?)"', chunk)
|
|
69
|
+
if match:
|
|
70
|
+
content = match.group(1).encode().decode('unicode_escape')
|
|
71
|
+
return content.replace('\\', '\\').replace('\\"', '"')
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
def _build_payload(self, prompt: str) -> Dict[str, Any]:
|
|
75
|
+
session_id = str(uuid4())
|
|
76
|
+
user_msg_id = str(uuid4())
|
|
77
|
+
model_a_msg_id = str(uuid4())
|
|
78
|
+
model_b_msg_id = str(uuid4())
|
|
79
|
+
return {
|
|
80
|
+
"id": session_id,
|
|
81
|
+
"mode": "battle",
|
|
82
|
+
"userMessageId": user_msg_id,
|
|
83
|
+
"modelAMessageId": model_a_msg_id,
|
|
84
|
+
"modelBMessageId": model_b_msg_id,
|
|
85
|
+
"messages": [
|
|
86
|
+
{
|
|
87
|
+
"id": user_msg_id,
|
|
88
|
+
"role": "user",
|
|
89
|
+
"content": prompt,
|
|
90
|
+
"experimental_attachments": [],
|
|
91
|
+
"parentMessageIds": [],
|
|
92
|
+
"participantPosition": "a",
|
|
93
|
+
"modelId": None,
|
|
94
|
+
"evaluationSessionId": session_id,
|
|
95
|
+
"status": "pending",
|
|
96
|
+
"failureReason": None
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"modality": "chat"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
def ask(
|
|
103
|
+
self,
|
|
104
|
+
prompt: str,
|
|
105
|
+
stream: bool = False,
|
|
106
|
+
raw: bool = False,
|
|
107
|
+
optimizer: str = None,
|
|
108
|
+
conversationally: bool = False,
|
|
109
|
+
) -> Union[Dict[str, Any], Generator]:
|
|
110
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
111
|
+
if optimizer:
|
|
112
|
+
if optimizer in self.__available_optimizers:
|
|
113
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
114
|
+
conversation_prompt if conversationally else prompt
|
|
115
|
+
)
|
|
116
|
+
else:
|
|
117
|
+
raise Exception(f"Optimizer is not one of {self.__available_optimizers}")
|
|
118
|
+
payload = self._build_payload(conversation_prompt)
|
|
119
|
+
def for_stream():
|
|
120
|
+
try:
|
|
121
|
+
response = self.session.post(
|
|
122
|
+
self.url,
|
|
123
|
+
json=payload,
|
|
124
|
+
stream=True,
|
|
125
|
+
timeout=self.timeout
|
|
126
|
+
)
|
|
127
|
+
if not response.ok:
|
|
128
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
129
|
+
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
130
|
+
)
|
|
131
|
+
streaming_text = ""
|
|
132
|
+
processed_stream = sanitize_stream(
|
|
133
|
+
data=response.iter_content(chunk_size=None),
|
|
134
|
+
intro_value=None,
|
|
135
|
+
to_json=False,
|
|
136
|
+
content_extractor=self._arena_extractor
|
|
137
|
+
)
|
|
138
|
+
for content_chunk in processed_stream:
|
|
139
|
+
if content_chunk and isinstance(content_chunk, str):
|
|
140
|
+
streaming_text += content_chunk
|
|
141
|
+
yield content_chunk if raw else dict(text=content_chunk)
|
|
142
|
+
self.last_response = {"text": streaming_text}
|
|
143
|
+
self.conversation.update_chat_history(prompt, streaming_text)
|
|
144
|
+
except CurlError as e:
|
|
145
|
+
raise exceptions.FailedToGenerateResponseError(f"Request failed (CurlError): {e}")
|
|
146
|
+
except Exception as e:
|
|
147
|
+
raise exceptions.FailedToGenerateResponseError(f"An unexpected error occurred ({type(e).__name__}): {e}")
|
|
148
|
+
def for_non_stream():
|
|
149
|
+
full_text = ""
|
|
150
|
+
for chunk_data in for_stream():
|
|
151
|
+
if isinstance(chunk_data, dict) and "text" in chunk_data:
|
|
152
|
+
full_text += chunk_data["text"]
|
|
153
|
+
elif isinstance(chunk_data, str):
|
|
154
|
+
full_text += chunk_data
|
|
155
|
+
self.last_response = {"text": full_text}
|
|
156
|
+
return self.last_response
|
|
157
|
+
return for_stream() if stream else for_non_stream()
|
|
158
|
+
|
|
159
|
+
def chat(
|
|
160
|
+
self,
|
|
161
|
+
prompt: str,
|
|
162
|
+
stream: bool = False,
|
|
163
|
+
optimizer: str = None,
|
|
164
|
+
conversationally: bool = False,
|
|
165
|
+
) -> Union[str, Generator]:
|
|
166
|
+
def for_stream():
|
|
167
|
+
for response in self.ask(prompt, True, optimizer=optimizer, conversationally=conversationally):
|
|
168
|
+
yield self.get_message(response)
|
|
169
|
+
def for_non_stream():
|
|
170
|
+
return self.get_message(
|
|
171
|
+
self.ask(prompt, False, optimizer=optimizer, conversationally=conversationally)
|
|
172
|
+
)
|
|
173
|
+
return for_stream() if stream else for_non_stream()
|
|
174
|
+
|
|
175
|
+
def get_message(self, response: dict) -> str:
|
|
176
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
177
|
+
return response["text"]
|
|
178
|
+
|
|
179
|
+
if __name__ == "__main__":
|
|
180
|
+
print("-" * 80)
|
|
181
|
+
print(f"{'Model':<20} {'Status':<10} {'Response'}")
|
|
182
|
+
print("-" * 80)
|
|
183
|
+
try:
|
|
184
|
+
test_ai = lmarena(timeout=60)
|
|
185
|
+
response = test_ai.chat("Say 'Hello' in one word", stream=True)
|
|
186
|
+
response_text = ""
|
|
187
|
+
for chunk in response:
|
|
188
|
+
response_text += chunk
|
|
189
|
+
print(f"\r{'arena-battle':<20} {'Testing...':<10}", end="", flush=True)
|
|
190
|
+
if response_text and len(response_text.strip()) > 0:
|
|
191
|
+
status = "✓"
|
|
192
|
+
display_text = response_text.strip()[:50] + "..." if len(response_text.strip()) > 50 else response_text.strip()
|
|
193
|
+
else:
|
|
194
|
+
status = "✗"
|
|
195
|
+
display_text = "Empty or invalid response"
|
|
196
|
+
print(f"\r{'arena-battle':<20} {status:<10} {display_text}")
|
|
197
|
+
except Exception as e:
|
|
198
|
+
print(f"\r{'arena-battle':<20} {'✗':<10} {str(e)}")
|
webscout/Provider/meta.py
CHANGED
|
@@ -537,6 +537,7 @@ class Meta(Provider):
|
|
|
537
537
|
raise exceptions.FailedToGenerateResponseError(
|
|
538
538
|
f"Failed to generate response - {response.text}"
|
|
539
539
|
)
|
|
540
|
+
final_message = None
|
|
540
541
|
for line in lines:
|
|
541
542
|
if line:
|
|
542
543
|
json_line = json.loads(line)
|
|
@@ -544,10 +545,12 @@ class Meta(Provider):
|
|
|
544
545
|
if not extracted_data.get("message"):
|
|
545
546
|
continue
|
|
546
547
|
self.last_response.update(extracted_data)
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
548
|
+
final_message = extracted_data # Always keep the latest
|
|
549
|
+
if final_message:
|
|
550
|
+
yield final_message if not raw else json.dumps(final_message)
|
|
551
|
+
self.conversation.update_chat_history(
|
|
552
|
+
prompt, self.get_message(self.last_response)
|
|
553
|
+
)
|
|
551
554
|
|
|
552
555
|
return for_stream()
|
|
553
556
|
else:
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
from typing import *
|
|
2
|
+
from webscout.AIutel import Conversation
|
|
3
|
+
from webscout.AIutel import Optimizers
|
|
4
|
+
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
5
|
+
from webscout.AIbase import Provider
|
|
6
|
+
from webscout import exceptions
|
|
7
|
+
from curl_cffi.requests import Session
|
|
8
|
+
from curl_cffi import CurlError
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
class samurai(Provider):
|
|
12
|
+
"""
|
|
13
|
+
A class to interact with a custom API endpoint.
|
|
14
|
+
"""
|
|
15
|
+
AVAILABLE_MODELS = [
|
|
16
|
+
"openai/gpt-4.1",
|
|
17
|
+
"openai/gpt-4o-search-preview",
|
|
18
|
+
"openai/gpt-4o-mini-search-preview",
|
|
19
|
+
"openai/gpt-4.1-nano",
|
|
20
|
+
"openai/chatgpt-4o-latest",
|
|
21
|
+
"openai/gpt-4.1-mini",
|
|
22
|
+
"gpt-4o",
|
|
23
|
+
"o3-mini",
|
|
24
|
+
"Claude-sonnet-3.7",
|
|
25
|
+
"anthropic/claude-3.5-sonnet",
|
|
26
|
+
"gemini-1.5-pro",
|
|
27
|
+
"gemini-1.5-pro-latest",
|
|
28
|
+
"gemini-flash-2.0",
|
|
29
|
+
"gemini-1.5-flash",
|
|
30
|
+
"llama-3.1-405b",
|
|
31
|
+
"Meta-Llama-3.1-405B-Instruct-Turbo",
|
|
32
|
+
"Meta-Llama-3.3-70B-Instruct-Turbo",
|
|
33
|
+
"chutesai/Llama-4-Maverick-17B-128E-Instruct-FP8",
|
|
34
|
+
"chutesai/Llama-4-Scout-17B-16E-Instruct",
|
|
35
|
+
"Qwen-QwQ-32B-Preview",
|
|
36
|
+
"Qwen/Qwen3-235B-A22B-fp8-tput",
|
|
37
|
+
"deepseek-r1",
|
|
38
|
+
"deepseek-v3",
|
|
39
|
+
"deepseek-ai/DeepSeek-V3-0324",
|
|
40
|
+
"dbrx-instruct",
|
|
41
|
+
"x-ai/grok-3-",
|
|
42
|
+
"perplexity-ai/r1-1776"
|
|
43
|
+
]
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
is_conversation: bool = True,
|
|
47
|
+
max_tokens: int = 2049,
|
|
48
|
+
timeout: int = 30,
|
|
49
|
+
intro: str = None,
|
|
50
|
+
filepath: str = None,
|
|
51
|
+
update_file: bool = True,
|
|
52
|
+
proxies: dict = {},
|
|
53
|
+
history_offset: int = 10250,
|
|
54
|
+
act: str = None,
|
|
55
|
+
model: str = "openai/gpt-4.1",
|
|
56
|
+
system_prompt: str = "You are a helpful assistant."
|
|
57
|
+
):
|
|
58
|
+
"""Initializes the Custom API client."""
|
|
59
|
+
self.url = "https://vmxvcq-5000.csb.app/v1/chat/completions"
|
|
60
|
+
self.headers = {
|
|
61
|
+
"Authorization": "Bearer Public-Samurai-001",
|
|
62
|
+
"Content-Type": "application/json"
|
|
63
|
+
}
|
|
64
|
+
self.session = Session()
|
|
65
|
+
self.session.headers.update(self.headers)
|
|
66
|
+
self.system_prompt = system_prompt
|
|
67
|
+
self.is_conversation = is_conversation
|
|
68
|
+
self.max_tokens_to_sample = max_tokens
|
|
69
|
+
self.timeout = timeout
|
|
70
|
+
self.last_response = {}
|
|
71
|
+
self.model = model
|
|
72
|
+
|
|
73
|
+
self.__available_optimizers = (
|
|
74
|
+
method
|
|
75
|
+
for method in dir(Optimizers)
|
|
76
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
77
|
+
)
|
|
78
|
+
Conversation.intro = (
|
|
79
|
+
AwesomePrompts().get_act(
|
|
80
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
81
|
+
)
|
|
82
|
+
if act
|
|
83
|
+
else intro or Conversation.intro
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
self.conversation = Conversation(
|
|
87
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
88
|
+
)
|
|
89
|
+
self.conversation.history_offset = history_offset
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def _extractor(chunk: dict) -> Optional[str]:
|
|
93
|
+
"""Extracts content from stream JSON objects."""
|
|
94
|
+
return chunk.get("choices", [{}])[0].get("delta", {}).get("content")
|
|
95
|
+
|
|
96
|
+
def ask(
|
|
97
|
+
self,
|
|
98
|
+
prompt: str,
|
|
99
|
+
stream: bool = False,
|
|
100
|
+
raw: bool = False,
|
|
101
|
+
optimizer: str = None,
|
|
102
|
+
conversationally: bool = False,
|
|
103
|
+
) -> Union[Dict[str, Any], Generator]:
|
|
104
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
105
|
+
if optimizer:
|
|
106
|
+
if optimizer in self.__available_optimizers:
|
|
107
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
108
|
+
conversation_prompt if conversationally else prompt
|
|
109
|
+
)
|
|
110
|
+
else:
|
|
111
|
+
raise Exception(f"Optimizer is not one of {self.__available_optimizers}")
|
|
112
|
+
|
|
113
|
+
payload = {
|
|
114
|
+
"model": self.model,
|
|
115
|
+
"messages": [
|
|
116
|
+
{"role": "system", "content": self.system_prompt},
|
|
117
|
+
{"role": "user", "content": conversation_prompt},
|
|
118
|
+
],
|
|
119
|
+
"stream": stream
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
def for_stream():
|
|
123
|
+
streaming_text = ""
|
|
124
|
+
try:
|
|
125
|
+
response = self.session.post(
|
|
126
|
+
self.url,
|
|
127
|
+
data=json.dumps(payload),
|
|
128
|
+
stream=True,
|
|
129
|
+
timeout=self.timeout,
|
|
130
|
+
impersonate="chrome110"
|
|
131
|
+
)
|
|
132
|
+
response.raise_for_status()
|
|
133
|
+
|
|
134
|
+
processed_stream = sanitize_stream(
|
|
135
|
+
data=response.iter_lines(),
|
|
136
|
+
intro_value="data:",
|
|
137
|
+
to_json=True,
|
|
138
|
+
skip_markers=["[DONE]"],
|
|
139
|
+
content_extractor=self._extractor,
|
|
140
|
+
yield_raw_on_error=False
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
for content_chunk in processed_stream:
|
|
144
|
+
if content_chunk and isinstance(content_chunk, str):
|
|
145
|
+
streaming_text += content_chunk
|
|
146
|
+
resp = dict(text=content_chunk)
|
|
147
|
+
yield resp if not raw else content_chunk
|
|
148
|
+
|
|
149
|
+
except Exception as e:
|
|
150
|
+
raise exceptions.FailedToGenerateResponseError(f"Request failed: {str(e)}") from e
|
|
151
|
+
finally:
|
|
152
|
+
if streaming_text:
|
|
153
|
+
self.last_response = {"text": streaming_text}
|
|
154
|
+
self.conversation.update_chat_history(prompt, streaming_text)
|
|
155
|
+
|
|
156
|
+
def for_non_stream():
|
|
157
|
+
try:
|
|
158
|
+
response = self.session.post(
|
|
159
|
+
self.url,
|
|
160
|
+
data=json.dumps(payload),
|
|
161
|
+
timeout=self.timeout,
|
|
162
|
+
impersonate="chrome110"
|
|
163
|
+
)
|
|
164
|
+
response.raise_for_status()
|
|
165
|
+
json_response = response.json()
|
|
166
|
+
content = json_response.get("choices", [{}])[0].get("message", {}).get("content", "")
|
|
167
|
+
|
|
168
|
+
self.last_response = {"text": content}
|
|
169
|
+
self.conversation.update_chat_history(prompt, content)
|
|
170
|
+
return self.last_response if not raw else content
|
|
171
|
+
|
|
172
|
+
except Exception as e:
|
|
173
|
+
raise exceptions.FailedToGenerateResponseError(f"Request failed: {str(e)}") from e
|
|
174
|
+
|
|
175
|
+
return for_stream() if stream else for_non_stream()
|
|
176
|
+
|
|
177
|
+
def chat(
|
|
178
|
+
self,
|
|
179
|
+
prompt: str,
|
|
180
|
+
stream: bool = False,
|
|
181
|
+
optimizer: str = None,
|
|
182
|
+
conversationally: bool = False,
|
|
183
|
+
) -> Union[str, Generator[str, None, None]]:
|
|
184
|
+
def for_stream_chat():
|
|
185
|
+
gen = self.ask(prompt, stream=True, raw=False, optimizer=optimizer, conversationally=conversationally)
|
|
186
|
+
for response_dict in gen:
|
|
187
|
+
yield self.get_message(response_dict)
|
|
188
|
+
|
|
189
|
+
def for_non_stream_chat():
|
|
190
|
+
response_data = self.ask(prompt, stream=False, raw=False, optimizer=optimizer, conversationally=conversationally)
|
|
191
|
+
return self.get_message(response_data)
|
|
192
|
+
|
|
193
|
+
return for_stream_chat() if stream else for_non_stream_chat()
|
|
194
|
+
|
|
195
|
+
def get_message(self, response: dict) -> str:
|
|
196
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
197
|
+
return response["text"]
|
|
198
|
+
|
|
199
|
+
if __name__ == "__main__":
|
|
200
|
+
# Ensure curl_cffi is installed
|
|
201
|
+
print("-" * 80)
|
|
202
|
+
print(f"{'Model':<50} {'Status':<10} {'Response'}")
|
|
203
|
+
print("-" * 80)
|
|
204
|
+
|
|
205
|
+
for model in samurai.AVAILABLE_MODELS:
|
|
206
|
+
try:
|
|
207
|
+
test_ai = samurai(model=model, timeout=60)
|
|
208
|
+
response = test_ai.chat("Say 'Hello' in one word", stream=True)
|
|
209
|
+
response_text = ""
|
|
210
|
+
for chunk in response:
|
|
211
|
+
response_text += chunk
|
|
212
|
+
|
|
213
|
+
if response_text and len(response_text.strip()) > 0:
|
|
214
|
+
status = "✓"
|
|
215
|
+
# Clean and truncate response
|
|
216
|
+
clean_text = response_text.strip().encode('utf-8', errors='ignore').decode('utf-8')
|
|
217
|
+
display_text = clean_text[:50] + "..." if len(clean_text) > 50 else clean_text
|
|
218
|
+
else:
|
|
219
|
+
status = "✗"
|
|
220
|
+
display_text = "Empty or invalid response"
|
|
221
|
+
print(f"\r{model:<50} {status:<10} {display_text}")
|
|
222
|
+
except Exception as e:
|
|
223
|
+
print(f"\r{model:<50} {'✗':<10} {str(e)}")
|
webscout/Provider/scira_chat.py
CHANGED
|
@@ -22,10 +22,12 @@ class SciraAI(Provider):
|
|
|
22
22
|
"scira-grok-3": "Grok3",
|
|
23
23
|
"scira-anthropic": "Sonnet 3.7 thinking",
|
|
24
24
|
"scira-vision" : "Grok2-Vision", # vision model
|
|
25
|
-
"scira-
|
|
25
|
+
"scira-4o": "GPT4o",
|
|
26
26
|
"scira-qwq": "QWQ-32B",
|
|
27
27
|
"scira-o4-mini": "o4-mini",
|
|
28
|
-
"scira-google": "gemini 2.5 flash"
|
|
28
|
+
"scira-google": "gemini 2.5 flash",
|
|
29
|
+
"scira-google-pro": "gemini 2.5 pro",
|
|
30
|
+
"scira-llama-4": "llama 4 Maverick",
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
def __init__(
|