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
webscout/Provider/asksteve.py
CHANGED
|
@@ -156,8 +156,8 @@ class AskSteve(Provider):
|
|
|
156
156
|
self.conversation.update_chat_history(
|
|
157
157
|
prompt, self.get_message(self.last_response)
|
|
158
158
|
)
|
|
159
|
-
#
|
|
160
|
-
return text if raw else self.last_response
|
|
159
|
+
# Always return a dict for consistency
|
|
160
|
+
return {"text": text} if raw else self.last_response
|
|
161
161
|
|
|
162
162
|
except CurlError as e:
|
|
163
163
|
raise exceptions.FailedToGenerateResponseError(f"Request failed (CurlError): {e}") from e
|
|
@@ -181,7 +181,6 @@ class AskSteve(Provider):
|
|
|
181
181
|
str: Response generated
|
|
182
182
|
"""
|
|
183
183
|
|
|
184
|
-
# Since ask() doesn't truly stream, we just call it once.
|
|
185
184
|
response_data = self.ask(
|
|
186
185
|
prompt,
|
|
187
186
|
stream=False, # Always False for this API
|
|
@@ -189,19 +188,28 @@ class AskSteve(Provider):
|
|
|
189
188
|
optimizer=optimizer,
|
|
190
189
|
conversationally=conversationally,
|
|
191
190
|
)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
if stream:
|
|
192
|
+
def stream_wrapper():
|
|
193
|
+
yield self.get_message(response_data)
|
|
194
|
+
return stream_wrapper()
|
|
195
|
+
else:
|
|
196
|
+
return self.get_message(response_data)
|
|
197
|
+
|
|
198
|
+
def get_message(self, response) -> str:
|
|
195
199
|
"""Retrieves message only from response
|
|
196
200
|
|
|
197
201
|
Args:
|
|
198
|
-
response (dict): Response generated by `self.ask`
|
|
202
|
+
response (dict or str): Response generated by `self.ask` or a string
|
|
199
203
|
|
|
200
204
|
Returns:
|
|
201
205
|
str: Message extracted
|
|
202
206
|
"""
|
|
203
|
-
|
|
204
|
-
|
|
207
|
+
if isinstance(response, dict):
|
|
208
|
+
return response.get("text", "") # Use .get for safety
|
|
209
|
+
elif isinstance(response, str):
|
|
210
|
+
return response
|
|
211
|
+
else:
|
|
212
|
+
raise TypeError(f"Unsupported response type: {type(response)}")
|
|
205
213
|
|
|
206
214
|
|
|
207
215
|
if __name__ == "__main__":
|
webscout/Provider/cerebras.py
CHANGED
webscout/Provider/koala.py
CHANGED
|
@@ -1,268 +1,170 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import
|
|
3
|
-
from typing import Union, Any, Dict,
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
from webscout.AIutel import
|
|
7
|
-
from webscout.AIbase import Provider
|
|
8
|
-
from webscout import exceptions
|
|
9
|
-
|
|
10
|
-
class KOALA(Provider):
|
|
11
|
-
"""
|
|
12
|
-
A class to interact with the Koala.sh API.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"gpt-4.1
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
self.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
172
|
-
f"Failed to generate response - ({response.status_code}, {response.reason})"
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
response_content = response.content.decode('utf-8')
|
|
176
|
-
data_parts = response_content.strip().split('\n\n')
|
|
177
|
-
formatted_response = ''.join([part.replace('data: ', '') for part in data_parts if part.startswith('data: ')])
|
|
178
|
-
|
|
179
|
-
# Remove extra quotes from the formatted response
|
|
180
|
-
formatted_response = formatted_response.replace('""', '')
|
|
181
|
-
|
|
182
|
-
# Split the response into lines and format with new lines before headers
|
|
183
|
-
lines = formatted_response.split('\n')
|
|
184
|
-
formatted_lines = []
|
|
185
|
-
for line in lines:
|
|
186
|
-
if line.startswith('###'):
|
|
187
|
-
formatted_lines.append('\n' + line)
|
|
188
|
-
else:
|
|
189
|
-
formatted_lines.append(line)
|
|
190
|
-
|
|
191
|
-
# Join the formatted lines back into a single string
|
|
192
|
-
final_response = '\n'.join(formatted_lines)
|
|
193
|
-
|
|
194
|
-
# self.last_response.update(dict(text=streaming_response))
|
|
195
|
-
self.conversation.update_chat_history(
|
|
196
|
-
prompt, final_response
|
|
197
|
-
)
|
|
198
|
-
return dict(text=final_response)
|
|
199
|
-
|
|
200
|
-
return for_stream() if stream else for_non_stream()
|
|
201
|
-
|
|
202
|
-
def chat(
|
|
203
|
-
self,
|
|
204
|
-
prompt: str,
|
|
205
|
-
stream: bool = False,
|
|
206
|
-
optimizer: str = None,
|
|
207
|
-
conversationally: bool = False,
|
|
208
|
-
) -> str:
|
|
209
|
-
"""Generate response `str`
|
|
210
|
-
Args:
|
|
211
|
-
prompt (str): Prompt to be send.
|
|
212
|
-
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
213
|
-
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
214
|
-
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
215
|
-
Returns:
|
|
216
|
-
str: Response generated
|
|
217
|
-
"""
|
|
218
|
-
|
|
219
|
-
def for_stream():
|
|
220
|
-
for response in self.ask(
|
|
221
|
-
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
222
|
-
):
|
|
223
|
-
yield self.get_message(response)
|
|
224
|
-
|
|
225
|
-
def for_non_stream():
|
|
226
|
-
return self.get_message(
|
|
227
|
-
self.ask(
|
|
228
|
-
prompt,
|
|
229
|
-
False,
|
|
230
|
-
optimizer=optimizer,
|
|
231
|
-
conversationally=conversationally,
|
|
232
|
-
)
|
|
233
|
-
)
|
|
234
|
-
|
|
235
|
-
return for_stream() if stream else for_non_stream()
|
|
236
|
-
|
|
237
|
-
def get_message(self, response: dict) -> str:
|
|
238
|
-
"""Retrieves message only from response
|
|
239
|
-
|
|
240
|
-
Args:
|
|
241
|
-
response (dict): Response generated by `self.ask`
|
|
242
|
-
|
|
243
|
-
Returns:
|
|
244
|
-
str: Message extracted
|
|
245
|
-
"""
|
|
246
|
-
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
247
|
-
return response["text"].replace('\\n', '\n').replace('\\n\\n', '\n\n')
|
|
248
|
-
if __name__ == '__main__':
|
|
249
|
-
print("-" * 80)
|
|
250
|
-
print(f"{'Model':<50} {'Status':<10} {'Response'}")
|
|
251
|
-
print("-" * 80)
|
|
252
|
-
|
|
253
|
-
for model in KOALA.AVAILABLE_MODELS:
|
|
254
|
-
try:
|
|
255
|
-
test_ai = KOALA(model=model, timeout=60)
|
|
256
|
-
response = test_ai.chat("Say 'Hello' in one word")
|
|
257
|
-
response_text = response
|
|
258
|
-
|
|
259
|
-
if response_text and len(response_text.strip()) > 0:
|
|
260
|
-
status = "✓"
|
|
261
|
-
# Truncate response if too long
|
|
262
|
-
display_text = response_text.strip()[:50] + "..." if len(response_text.strip()) > 50 else response_text.strip()
|
|
263
|
-
else:
|
|
264
|
-
status = "✗"
|
|
265
|
-
display_text = "Empty or invalid response"
|
|
266
|
-
print(f"{model:<50} {status:<10} {display_text}")
|
|
267
|
-
except Exception as e:
|
|
268
|
-
print(f"{model:<50} {'✗':<10} {str(e)}")
|
|
1
|
+
import requests
|
|
2
|
+
import re
|
|
3
|
+
from typing import Optional, Union, Any, Dict, Generator
|
|
4
|
+
from uuid import uuid4
|
|
5
|
+
|
|
6
|
+
from webscout.AIutel import Optimizers, Conversation, AwesomePrompts
|
|
7
|
+
from webscout.AIbase import Provider
|
|
8
|
+
from webscout import exceptions
|
|
9
|
+
|
|
10
|
+
class KOALA(Provider):
|
|
11
|
+
"""
|
|
12
|
+
A class to interact with the Koala.sh API, X0GPT-style, without sanitize_stream.
|
|
13
|
+
"""
|
|
14
|
+
AVAILABLE_MODELS = [
|
|
15
|
+
"gpt-4.1-mini",
|
|
16
|
+
"gpt-4.1",
|
|
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 = "gpt-4.1",
|
|
31
|
+
web_search: bool = True,
|
|
32
|
+
):
|
|
33
|
+
if model not in self.AVAILABLE_MODELS:
|
|
34
|
+
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
|
|
35
|
+
self.session = requests.Session()
|
|
36
|
+
self.is_conversation = is_conversation
|
|
37
|
+
self.max_tokens_to_sample = max_tokens
|
|
38
|
+
self.api_endpoint = "https://koala.sh/api/gpt/"
|
|
39
|
+
self.timeout = timeout
|
|
40
|
+
self.last_response = {}
|
|
41
|
+
self.model = model
|
|
42
|
+
self.headers = {
|
|
43
|
+
"accept": "text/event-stream",
|
|
44
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
45
|
+
"accept-language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
46
|
+
"content-type": "application/json",
|
|
47
|
+
"dnt": "1",
|
|
48
|
+
"flag-real-time-data": "true" if web_search else "false",
|
|
49
|
+
"origin": "https://koala.sh",
|
|
50
|
+
"referer": "https://koala.sh/chat",
|
|
51
|
+
"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 Edg/127.0.0.0",
|
|
52
|
+
}
|
|
53
|
+
self.session.headers.update(self.headers)
|
|
54
|
+
Conversation.intro = (
|
|
55
|
+
AwesomePrompts().get_act(
|
|
56
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
57
|
+
)
|
|
58
|
+
if act
|
|
59
|
+
else intro or Conversation.intro
|
|
60
|
+
)
|
|
61
|
+
self.conversation = Conversation(
|
|
62
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
63
|
+
)
|
|
64
|
+
self.conversation.history_offset = history_offset
|
|
65
|
+
self.session.proxies = proxies
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def _koala_extractor(line: str) -> Optional[str]:
|
|
69
|
+
# Koala returns lines like: data: "Hello" or data: "..."
|
|
70
|
+
match = re.match(r'data:\s*"(.*)"', line)
|
|
71
|
+
if match:
|
|
72
|
+
return match.group(1)
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
def ask(
|
|
76
|
+
self,
|
|
77
|
+
prompt: str,
|
|
78
|
+
stream: bool = False,
|
|
79
|
+
raw: bool = False,
|
|
80
|
+
optimizer: str = None,
|
|
81
|
+
conversationally: bool = False,
|
|
82
|
+
) -> Dict[str, Any]:
|
|
83
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
84
|
+
if optimizer:
|
|
85
|
+
if hasattr(Optimizers, optimizer):
|
|
86
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
87
|
+
conversation_prompt if conversationally else prompt
|
|
88
|
+
)
|
|
89
|
+
else:
|
|
90
|
+
raise Exception(f"Optimizer is not valid.")
|
|
91
|
+
payload = {
|
|
92
|
+
"input": conversation_prompt,
|
|
93
|
+
"inputHistory": [],
|
|
94
|
+
"outputHistory": [],
|
|
95
|
+
"model": self.model
|
|
96
|
+
}
|
|
97
|
+
def for_stream():
|
|
98
|
+
response = self.session.post(
|
|
99
|
+
self.api_endpoint, json=payload, headers=self.headers, stream=True, timeout=self.timeout
|
|
100
|
+
)
|
|
101
|
+
if not response.ok:
|
|
102
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
103
|
+
f"Failed to generate response - ({response.status_code}, {response.reason})"
|
|
104
|
+
)
|
|
105
|
+
streaming_response = ""
|
|
106
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
107
|
+
if not line:
|
|
108
|
+
continue
|
|
109
|
+
# Only process lines starting with data:
|
|
110
|
+
if line.startswith("data:"):
|
|
111
|
+
content = self._koala_extractor(line)
|
|
112
|
+
if content and content.strip():
|
|
113
|
+
streaming_response += content
|
|
114
|
+
yield dict(text=content) if not raw else content
|
|
115
|
+
# Only update chat history if response is not empty
|
|
116
|
+
if streaming_response.strip():
|
|
117
|
+
self.last_response = dict(text=streaming_response)
|
|
118
|
+
self.conversation.update_chat_history(
|
|
119
|
+
prompt, self.get_message(self.last_response)
|
|
120
|
+
)
|
|
121
|
+
def for_non_stream():
|
|
122
|
+
# Use streaming logic to collect the full response
|
|
123
|
+
full_text = ""
|
|
124
|
+
for chunk in for_stream():
|
|
125
|
+
if isinstance(chunk, dict):
|
|
126
|
+
full_text += chunk.get("text", "")
|
|
127
|
+
elif isinstance(chunk, str):
|
|
128
|
+
full_text += chunk
|
|
129
|
+
# Only update chat history if response is not empty
|
|
130
|
+
if full_text.strip():
|
|
131
|
+
self.last_response = dict(text=full_text)
|
|
132
|
+
self.conversation.update_chat_history(
|
|
133
|
+
prompt, self.get_message(self.last_response)
|
|
134
|
+
)
|
|
135
|
+
return self.last_response
|
|
136
|
+
return for_stream() if stream else for_non_stream()
|
|
137
|
+
|
|
138
|
+
def chat(
|
|
139
|
+
self,
|
|
140
|
+
prompt: str,
|
|
141
|
+
stream: bool = False,
|
|
142
|
+
optimizer: str = None,
|
|
143
|
+
conversationally: bool = False,
|
|
144
|
+
) -> Union[str, Generator[str, None, None]]:
|
|
145
|
+
def for_stream():
|
|
146
|
+
for response in self.ask(
|
|
147
|
+
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
148
|
+
):
|
|
149
|
+
yield self.get_message(response)
|
|
150
|
+
def for_non_stream():
|
|
151
|
+
return self.get_message(
|
|
152
|
+
self.ask(
|
|
153
|
+
prompt,
|
|
154
|
+
False,
|
|
155
|
+
optimizer=optimizer,
|
|
156
|
+
conversationally=conversationally,
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
return for_stream() if stream else for_non_stream()
|
|
160
|
+
|
|
161
|
+
def get_message(self, response: dict) -> str:
|
|
162
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
163
|
+
return response.get("text", "")
|
|
164
|
+
|
|
165
|
+
if __name__ == "__main__":
|
|
166
|
+
from rich import print
|
|
167
|
+
ai = KOALA(timeout=60)
|
|
168
|
+
response = ai.chat("Say 'Hello' in one word", stream=True)
|
|
169
|
+
for chunk in response:
|
|
170
|
+
print(chunk, end="", flush=True)
|
webscout/Provider/llmchat.py
CHANGED
|
@@ -22,6 +22,9 @@ class LLMChat(Provider):
|
|
|
22
22
|
"@cf/meta/llama-3.2-1b-instruct",
|
|
23
23
|
"@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
24
24
|
"@cf/deepseek-ai/deepseek-r1-distill-qwen-32b",
|
|
25
|
+
"@cf/meta/llama-4-scout-17b-16e-instruct",
|
|
26
|
+
"@cf/mistralai/mistral-small-3.1-24b-instruct",
|
|
27
|
+
"@cf/google/gemma-3-12b-it",
|
|
25
28
|
]
|
|
26
29
|
|
|
27
30
|
def __init__(
|