webscout 8.3.3__py3-none-any.whl → 8.3.4__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 +221 -4
- webscout/Bard.py +2 -22
- webscout/Provider/AISEARCH/scira_search.py +24 -11
- webscout/Provider/Deepinfra.py +75 -57
- webscout/Provider/ExaChat.py +9 -5
- webscout/Provider/Flowith.py +1 -1
- webscout/Provider/FreeGemini.py +2 -2
- webscout/Provider/Gemini.py +3 -10
- webscout/Provider/GeminiProxy.py +31 -5
- webscout/Provider/LambdaChat.py +39 -31
- webscout/Provider/Netwrck.py +5 -8
- webscout/Provider/OLLAMA.py +8 -9
- webscout/Provider/OPENAI/README.md +1 -1
- webscout/Provider/OPENAI/__init__.py +1 -1
- webscout/Provider/OPENAI/autoproxy.py +1 -1
- webscout/Provider/OPENAI/copilot.py +73 -26
- webscout/Provider/OPENAI/deepinfra.py +54 -24
- webscout/Provider/OPENAI/exachat.py +9 -5
- webscout/Provider/OPENAI/monochat.py +3 -3
- webscout/Provider/OPENAI/netwrck.py +4 -7
- webscout/Provider/OPENAI/qodo.py +630 -0
- webscout/Provider/OPENAI/scirachat.py +82 -49
- webscout/Provider/OPENAI/textpollinations.py +13 -12
- webscout/Provider/OPENAI/typegpt.py +3 -3
- webscout/Provider/Qodo.py +454 -0
- webscout/Provider/TTI/monochat.py +3 -3
- webscout/Provider/TextPollinationsAI.py +13 -12
- webscout/Provider/__init__.py +4 -4
- webscout/Provider/copilot.py +58 -61
- webscout/Provider/freeaichat.py +64 -55
- webscout/Provider/monochat.py +275 -0
- webscout/Provider/scira_chat.py +111 -21
- webscout/Provider/typegpt.py +2 -2
- webscout/Provider/x0gpt.py +325 -315
- webscout/__init__.py +7 -2
- webscout/auth/routes.py +20 -3
- webscout/version.py +1 -1
- {webscout-8.3.3.dist-info → webscout-8.3.4.dist-info}/METADATA +1 -2
- {webscout-8.3.3.dist-info → webscout-8.3.4.dist-info}/RECORD +43 -43
- webscout/Provider/AI21.py +0 -177
- webscout/Provider/HuggingFaceChat.py +0 -469
- webscout/Provider/OPENAI/freeaichat.py +0 -363
- {webscout-8.3.3.dist-info → webscout-8.3.4.dist-info}/WHEEL +0 -0
- {webscout-8.3.3.dist-info → webscout-8.3.4.dist-info}/entry_points.txt +0 -0
- {webscout-8.3.3.dist-info → webscout-8.3.4.dist-info}/licenses/LICENSE.md +0 -0
- {webscout-8.3.3.dist-info → webscout-8.3.4.dist-info}/top_level.txt +0 -0
webscout/AIutel.py
CHANGED
|
@@ -12,6 +12,7 @@ from typing import (
|
|
|
12
12
|
List,
|
|
13
13
|
Literal,
|
|
14
14
|
Optional,
|
|
15
|
+
Pattern,
|
|
15
16
|
Union,
|
|
16
17
|
)
|
|
17
18
|
|
|
@@ -20,6 +21,36 @@ EncodingType = Literal['utf-8', 'utf-16', 'utf-32', 'ascii', 'latin1', 'cp1252',
|
|
|
20
21
|
'iso-8859-2', 'windows-1250', 'windows-1251', 'windows-1252', 'gbk', 'big5',
|
|
21
22
|
'shift_jis', 'euc-jp', 'euc-kr']
|
|
22
23
|
|
|
24
|
+
def _compile_regexes(patterns: Optional[List[Union[str, Pattern[str]]]]) -> Optional[List[Pattern[str]]]:
|
|
25
|
+
"""
|
|
26
|
+
Compile regex patterns from strings or return compiled patterns as-is.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
patterns: List of regex patterns as strings or compiled Pattern objects.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
List of compiled Pattern objects, or None if input is None.
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
ValueError: If any pattern is invalid.
|
|
36
|
+
"""
|
|
37
|
+
if not patterns:
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
compiled_patterns = []
|
|
41
|
+
for i, pattern in enumerate(patterns):
|
|
42
|
+
try:
|
|
43
|
+
if isinstance(pattern, str):
|
|
44
|
+
compiled_patterns.append(re.compile(pattern))
|
|
45
|
+
elif isinstance(pattern, Pattern):
|
|
46
|
+
compiled_patterns.append(pattern)
|
|
47
|
+
else:
|
|
48
|
+
raise ValueError(f"Pattern at index {i} must be a string or compiled regex pattern, got {type(pattern)}")
|
|
49
|
+
except re.error as e:
|
|
50
|
+
raise ValueError(f"Invalid regex pattern at index {i}: '{pattern}' - {str(e)}")
|
|
51
|
+
|
|
52
|
+
return compiled_patterns
|
|
53
|
+
|
|
23
54
|
def _process_chunk(
|
|
24
55
|
chunk: str,
|
|
25
56
|
intro_value: str,
|
|
@@ -28,6 +59,8 @@ def _process_chunk(
|
|
|
28
59
|
strip_chars: Optional[str],
|
|
29
60
|
yield_raw_on_error: bool,
|
|
30
61
|
error_handler: Optional[Callable[[Exception, str], Optional[Any]]] = None,
|
|
62
|
+
skip_regexes: Optional[List[Pattern[str]]] = None,
|
|
63
|
+
extract_regexes: Optional[List[Pattern[str]]] = None,
|
|
31
64
|
) -> Union[str, Dict[str, Any], None]:
|
|
32
65
|
"""
|
|
33
66
|
Sanitizes and potentially parses a single chunk of text.
|
|
@@ -36,6 +69,8 @@ def _process_chunk(
|
|
|
36
69
|
- Removes a specified prefix (`intro_value`).
|
|
37
70
|
- Strips leading/trailing characters (`strip_chars`).
|
|
38
71
|
- Skips chunks matching specific markers (`skip_markers`).
|
|
72
|
+
- Skips chunks matching regex patterns (`skip_regexes`).
|
|
73
|
+
- Extracts content using regex capturing groups (`extract_regexes`).
|
|
39
74
|
- Optionally parses the chunk as JSON (`to_json`).
|
|
40
75
|
- Handles JSON parsing errors with an optional callback (`error_handler`).
|
|
41
76
|
|
|
@@ -48,6 +83,8 @@ def _process_chunk(
|
|
|
48
83
|
yield_raw_on_error (bool): If True, returns the raw chunk when JSON parsing fails; otherwise, returns None.
|
|
49
84
|
error_handler (Optional[Callable[[Exception, str], Optional[Any]]]): An optional callback function that is called when JSON parsing fails.
|
|
50
85
|
It receives the exception and the sanitized chunk as arguments. It should return a value to yield instead of the raw chunk, or None to ignore.
|
|
86
|
+
skip_regexes (Optional[List[Pattern[str]]]): A list of compiled regex patterns; chunks matching any of these are skipped.
|
|
87
|
+
extract_regexes (Optional[List[Pattern[str]]]): A list of compiled regex patterns for extracting content using capturing groups.
|
|
51
88
|
|
|
52
89
|
"""
|
|
53
90
|
if not isinstance(chunk, str):
|
|
@@ -73,6 +110,28 @@ def _process_chunk(
|
|
|
73
110
|
if not sanitized_chunk or any(marker == sanitized_chunk for marker in skip_markers):
|
|
74
111
|
return None
|
|
75
112
|
|
|
113
|
+
# Apply regex-based extraction first (if provided)
|
|
114
|
+
if extract_regexes:
|
|
115
|
+
for regex in extract_regexes:
|
|
116
|
+
match = regex.search(sanitized_chunk)
|
|
117
|
+
if match:
|
|
118
|
+
# If there are capturing groups, return the first group or all groups as a tuple
|
|
119
|
+
if match.groups():
|
|
120
|
+
if len(match.groups()) == 1:
|
|
121
|
+
sanitized_chunk = match.group(1)
|
|
122
|
+
else:
|
|
123
|
+
# Multiple groups - return as tuple converted to string for JSON compatibility
|
|
124
|
+
sanitized_chunk = str(match.groups())
|
|
125
|
+
else:
|
|
126
|
+
# No capturing groups, return the full match
|
|
127
|
+
sanitized_chunk = match.group(0)
|
|
128
|
+
break # Use first matching extraction regex
|
|
129
|
+
|
|
130
|
+
# Apply regex-based skipping (after extraction)
|
|
131
|
+
if skip_regexes:
|
|
132
|
+
if any(regex.search(sanitized_chunk) for regex in skip_regexes):
|
|
133
|
+
return None
|
|
134
|
+
|
|
76
135
|
# JSON parsing with optimized error handling
|
|
77
136
|
if to_json:
|
|
78
137
|
try:
|
|
@@ -226,13 +285,15 @@ def _sanitize_stream_sync(
|
|
|
226
285
|
buffer_size: int = 8192,
|
|
227
286
|
line_delimiter: Optional[str] = None,
|
|
228
287
|
error_handler: Optional[Callable[[Exception, str], Optional[Any]]] = None,
|
|
288
|
+
skip_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
289
|
+
extract_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
229
290
|
) -> Generator[Any, None, None]:
|
|
230
291
|
"""
|
|
231
292
|
Processes a stream of data (strings or bytes) in real-time, applying various transformations and filtering.
|
|
232
293
|
|
|
233
294
|
This function is designed to handle streaming data, allowing for operations such as
|
|
234
|
-
prefix removal, JSON parsing, skipping lines based on markers,
|
|
235
|
-
It also supports custom error handling for JSON parsing failures.
|
|
295
|
+
prefix removal, JSON parsing, skipping lines based on markers, regex-based filtering,
|
|
296
|
+
and extracting specific content. It also supports custom error handling for JSON parsing failures.
|
|
236
297
|
|
|
237
298
|
Args:
|
|
238
299
|
data: String, iterable of strings, or iterable of bytes to process.
|
|
@@ -251,14 +312,21 @@ def _sanitize_stream_sync(
|
|
|
251
312
|
uses ``str.splitlines()``.
|
|
252
313
|
error_handler: Callback invoked with ``(Exception, str)`` when JSON
|
|
253
314
|
parsing fails. If the callback returns a value, it is yielded instead of the raw line.
|
|
315
|
+
skip_regexes: List of regex patterns (strings or compiled) for skipping lines that match.
|
|
316
|
+
extract_regexes: List of regex patterns (strings or compiled) for extracting content using capturing groups.
|
|
254
317
|
|
|
255
318
|
Yields:
|
|
256
319
|
Any: Processed data, which can be a string, a dictionary (if `to_json` is True), or the result of `content_extractor`.
|
|
257
320
|
|
|
258
321
|
Raises:
|
|
259
322
|
TypeError: If the input `data` is not a string or an iterable.
|
|
323
|
+
ValueError: If any regex pattern is invalid.
|
|
260
324
|
"""
|
|
261
325
|
effective_skip_markers = skip_markers or []
|
|
326
|
+
# Compile regex patterns
|
|
327
|
+
compiled_skip_regexes = _compile_regexes(skip_regexes)
|
|
328
|
+
compiled_extract_regexes = _compile_regexes(extract_regexes)
|
|
329
|
+
|
|
262
330
|
processing_active = start_marker is None
|
|
263
331
|
buffer = ""
|
|
264
332
|
found_start = False if start_marker else True
|
|
@@ -343,6 +411,8 @@ def _sanitize_stream_sync(
|
|
|
343
411
|
strip_chars,
|
|
344
412
|
yield_raw_on_error,
|
|
345
413
|
error_handler,
|
|
414
|
+
compiled_skip_regexes,
|
|
415
|
+
compiled_extract_regexes,
|
|
346
416
|
)
|
|
347
417
|
if result is None:
|
|
348
418
|
continue
|
|
@@ -373,6 +443,8 @@ def _sanitize_stream_sync(
|
|
|
373
443
|
strip_chars,
|
|
374
444
|
yield_raw_on_error,
|
|
375
445
|
error_handler,
|
|
446
|
+
compiled_skip_regexes,
|
|
447
|
+
compiled_extract_regexes,
|
|
376
448
|
)
|
|
377
449
|
if result is None:
|
|
378
450
|
continue
|
|
@@ -408,14 +480,16 @@ async def _sanitize_stream_async(
|
|
|
408
480
|
buffer_size: int = 8192,
|
|
409
481
|
line_delimiter: Optional[str] = None,
|
|
410
482
|
error_handler: Optional[Callable[[Exception, str], Optional[Any]]] = None,
|
|
483
|
+
skip_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
484
|
+
extract_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
411
485
|
) -> AsyncGenerator[Any, None]:
|
|
412
486
|
"""
|
|
413
487
|
Asynchronously processes a stream of data (strings or bytes), applying transformations and filtering.
|
|
414
488
|
|
|
415
489
|
This function is the asynchronous counterpart to `_sanitize_stream_sync`. It handles
|
|
416
490
|
streaming data, allowing for operations such as prefix removal, JSON parsing,
|
|
417
|
-
skipping lines based on markers, and extracting specific content.
|
|
418
|
-
custom error handling for JSON parsing failures.
|
|
491
|
+
skipping lines based on markers, regex-based filtering, and extracting specific content.
|
|
492
|
+
It also supports custom error handling for JSON parsing failures.
|
|
419
493
|
|
|
420
494
|
Args:
|
|
421
495
|
data: String, iterable of strings, or iterable of bytes to process.
|
|
@@ -432,6 +506,8 @@ async def _sanitize_stream_async(
|
|
|
432
506
|
buffer_size: Buffer size for byte decoding.
|
|
433
507
|
line_delimiter: Delimiter used to split incoming text into lines. ``None`` uses ``str.splitlines()``.
|
|
434
508
|
error_handler: Callback invoked with ``(Exception, str)`` when JSON parsing fails. If the callback returns a value, it is yielded in place of the raw line.
|
|
509
|
+
skip_regexes: List of regex patterns (strings or compiled) for skipping lines that match.
|
|
510
|
+
extract_regexes: List of regex patterns (strings or compiled) for extracting content using capturing groups.
|
|
435
511
|
"""
|
|
436
512
|
if isinstance(data, str):
|
|
437
513
|
for item in _sanitize_stream_sync(
|
|
@@ -449,6 +525,8 @@ async def _sanitize_stream_async(
|
|
|
449
525
|
buffer_size=buffer_size,
|
|
450
526
|
line_delimiter=line_delimiter,
|
|
451
527
|
error_handler=error_handler,
|
|
528
|
+
skip_regexes=skip_regexes,
|
|
529
|
+
extract_regexes=extract_regexes,
|
|
452
530
|
):
|
|
453
531
|
yield item
|
|
454
532
|
return
|
|
@@ -470,11 +548,17 @@ async def _sanitize_stream_async(
|
|
|
470
548
|
buffer_size=buffer_size,
|
|
471
549
|
line_delimiter=line_delimiter,
|
|
472
550
|
error_handler=error_handler,
|
|
551
|
+
skip_regexes=skip_regexes,
|
|
552
|
+
extract_regexes=extract_regexes,
|
|
473
553
|
):
|
|
474
554
|
yield item
|
|
475
555
|
return
|
|
476
556
|
|
|
477
557
|
effective_skip_markers = skip_markers or []
|
|
558
|
+
# Compile regex patterns
|
|
559
|
+
compiled_skip_regexes = _compile_regexes(skip_regexes)
|
|
560
|
+
compiled_extract_regexes = _compile_regexes(extract_regexes)
|
|
561
|
+
|
|
478
562
|
processing_active = start_marker is None
|
|
479
563
|
buffer = ""
|
|
480
564
|
found_start = False if start_marker else True
|
|
@@ -543,6 +627,8 @@ async def _sanitize_stream_async(
|
|
|
543
627
|
strip_chars,
|
|
544
628
|
yield_raw_on_error,
|
|
545
629
|
error_handler,
|
|
630
|
+
compiled_skip_regexes,
|
|
631
|
+
compiled_extract_regexes,
|
|
546
632
|
)
|
|
547
633
|
if result is None:
|
|
548
634
|
continue
|
|
@@ -576,6 +662,8 @@ async def _sanitize_stream_async(
|
|
|
576
662
|
strip_chars,
|
|
577
663
|
yield_raw_on_error,
|
|
578
664
|
error_handler,
|
|
665
|
+
compiled_skip_regexes,
|
|
666
|
+
compiled_extract_regexes,
|
|
579
667
|
)
|
|
580
668
|
if result is None:
|
|
581
669
|
continue
|
|
@@ -621,12 +709,15 @@ def sanitize_stream(
|
|
|
621
709
|
buffer_size: int = 8192,
|
|
622
710
|
line_delimiter: Optional[str] = None,
|
|
623
711
|
error_handler: Optional[Callable[[Exception, str], Optional[Any]]] = None,
|
|
712
|
+
skip_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
713
|
+
extract_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
624
714
|
object_mode: Literal["as_is", "json", "str"] = "json",
|
|
625
715
|
raw: bool = False,
|
|
626
716
|
) -> Union[Generator[Any, None, None], AsyncGenerator[Any, None]]:
|
|
627
717
|
"""
|
|
628
718
|
Processes streaming data (strings or bytes) in either synchronous or asynchronous mode.
|
|
629
719
|
Now supports non-iterable and miscellaneous input types (dict, list, int, float, bool, None).
|
|
720
|
+
Includes regex-based content filtering and extraction capabilities.
|
|
630
721
|
|
|
631
722
|
Args:
|
|
632
723
|
data: The data to be processed. Can be a string, bytes, a synchronous iterable of strings or bytes,
|
|
@@ -648,6 +739,10 @@ def sanitize_stream(
|
|
|
648
739
|
error_handler (Optional[Callable[[Exception, str], Optional[Any]]]):
|
|
649
740
|
Callback invoked with ``(Exception, str)`` when JSON parsing fails.
|
|
650
741
|
If the callback returns a value, it is yielded in place of the raw line. Defaults to None.
|
|
742
|
+
skip_regexes (Optional[List[Union[str, Pattern[str]]]]): List of regex patterns (strings or compiled)
|
|
743
|
+
for skipping lines that match any pattern. Defaults to None.
|
|
744
|
+
extract_regexes (Optional[List[Union[str, Pattern[str]]]]): List of regex patterns (strings or compiled)
|
|
745
|
+
for extracting content using capturing groups. If multiple groups are captured, they are returned as a tuple string. Defaults to None.
|
|
651
746
|
object_mode (Literal["as_is", "json", "str"]): How to handle non-string, non-iterable objects.
|
|
652
747
|
"json" (default) yields as JSON string, "str" yields as str(obj), "as_is" yields the object as-is.
|
|
653
748
|
raw (bool): If True, yields the raw response as returned by the API, chunk by chunk (no splitting or joining).
|
|
@@ -655,6 +750,9 @@ def sanitize_stream(
|
|
|
655
750
|
Returns:
|
|
656
751
|
Union[Generator[Any, None, None], AsyncGenerator[Any, None]]:
|
|
657
752
|
A generator or an asynchronous generator yielding the processed data, or raw data if raw=True.
|
|
753
|
+
|
|
754
|
+
Raises:
|
|
755
|
+
ValueError: If any regex pattern is invalid.
|
|
658
756
|
""" # --- RAW MODE: yield each chunk exactly as returned by the API ---
|
|
659
757
|
if raw:
|
|
660
758
|
def _raw_passthrough_sync(source_iter):
|
|
@@ -713,6 +811,7 @@ def sanitize_stream(
|
|
|
713
811
|
payload, intro_value, to_json, skip_markers, strip_chars,
|
|
714
812
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
715
813
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
814
|
+
skip_regexes, extract_regexes,
|
|
716
815
|
)
|
|
717
816
|
|
|
718
817
|
# Handle string directly
|
|
@@ -721,6 +820,7 @@ def sanitize_stream(
|
|
|
721
820
|
data, intro_value, to_json, skip_markers, strip_chars,
|
|
722
821
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
723
822
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
823
|
+
skip_regexes, extract_regexes,
|
|
724
824
|
)
|
|
725
825
|
|
|
726
826
|
# Handle dict, list, int, float, bool (non-iterable, non-string/bytes)
|
|
@@ -734,6 +834,7 @@ def sanitize_stream(
|
|
|
734
834
|
str(data), intro_value, to_json, skip_markers, strip_chars,
|
|
735
835
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
736
836
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
837
|
+
skip_regexes, extract_regexes,
|
|
737
838
|
)
|
|
738
839
|
else: # "json"
|
|
739
840
|
try:
|
|
@@ -744,6 +845,7 @@ def sanitize_stream(
|
|
|
744
845
|
json_str, intro_value, to_json, skip_markers, strip_chars,
|
|
745
846
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
746
847
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
848
|
+
skip_regexes, extract_regexes,
|
|
747
849
|
)
|
|
748
850
|
|
|
749
851
|
# Handle file-like objects (optional, treat as string if .read exists)
|
|
@@ -756,6 +858,7 @@ def sanitize_stream(
|
|
|
756
858
|
file_content, intro_value, to_json, skip_markers, strip_chars,
|
|
757
859
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
758
860
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
861
|
+
skip_regexes, extract_regexes,
|
|
759
862
|
)
|
|
760
863
|
except Exception:
|
|
761
864
|
pass # fallback to next
|
|
@@ -767,6 +870,7 @@ def sanitize_stream(
|
|
|
767
870
|
payload, intro_value, to_json, skip_markers, strip_chars,
|
|
768
871
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
769
872
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
873
|
+
skip_regexes, extract_regexes,
|
|
770
874
|
)
|
|
771
875
|
elif isinstance(content_attr, bytes):
|
|
772
876
|
try:
|
|
@@ -777,6 +881,7 @@ def sanitize_stream(
|
|
|
777
881
|
payload, intro_value, to_json, skip_markers, strip_chars,
|
|
778
882
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
779
883
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
884
|
+
skip_regexes, extract_regexes,
|
|
780
885
|
)
|
|
781
886
|
|
|
782
887
|
# Handle async iterables
|
|
@@ -785,6 +890,7 @@ def sanitize_stream(
|
|
|
785
890
|
data, intro_value, to_json, skip_markers, strip_chars,
|
|
786
891
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
787
892
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
893
|
+
skip_regexes, extract_regexes,
|
|
788
894
|
)
|
|
789
895
|
# Handle sync iterables (but not strings/bytes)
|
|
790
896
|
if hasattr(data, "__iter__"):
|
|
@@ -792,13 +898,124 @@ def sanitize_stream(
|
|
|
792
898
|
data, intro_value, to_json, skip_markers, strip_chars,
|
|
793
899
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
794
900
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
901
|
+
skip_regexes, extract_regexes,
|
|
795
902
|
)
|
|
796
903
|
# Fallback: treat as string
|
|
797
904
|
return _sanitize_stream_sync(
|
|
798
905
|
str(data), intro_value, to_json, skip_markers, strip_chars,
|
|
799
906
|
start_marker, end_marker, content_extractor, yield_raw_on_error,
|
|
800
907
|
encoding, encoding_errors, buffer_size, line_delimiter, error_handler,
|
|
908
|
+
skip_regexes, extract_regexes,
|
|
801
909
|
)
|
|
910
|
+
|
|
911
|
+
# --- Decorator version of sanitize_stream ---
|
|
912
|
+
import functools
|
|
913
|
+
from typing import overload
|
|
914
|
+
|
|
915
|
+
def _sanitize_stream_decorator(
|
|
916
|
+
_func=None,
|
|
917
|
+
*,
|
|
918
|
+
intro_value: str = "data:",
|
|
919
|
+
to_json: bool = True,
|
|
920
|
+
skip_markers: Optional[List[str]] = None,
|
|
921
|
+
strip_chars: Optional[str] = None,
|
|
922
|
+
start_marker: Optional[str] = None,
|
|
923
|
+
end_marker: Optional[str] = None,
|
|
924
|
+
content_extractor: Optional[Callable[[Union[str, Dict[str, Any]]], Optional[Any]]] = None,
|
|
925
|
+
yield_raw_on_error: bool = True,
|
|
926
|
+
encoding: EncodingType = "utf-8",
|
|
927
|
+
encoding_errors: str = "replace",
|
|
928
|
+
buffer_size: int = 8192,
|
|
929
|
+
line_delimiter: Optional[str] = None,
|
|
930
|
+
error_handler: Optional[Callable[[Exception, str], Optional[Any]]] = None,
|
|
931
|
+
skip_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
932
|
+
extract_regexes: Optional[List[Union[str, Pattern[str]]]] = None,
|
|
933
|
+
object_mode: Literal["as_is", "json", "str"] = "json",
|
|
934
|
+
raw: bool = False,
|
|
935
|
+
):
|
|
936
|
+
"""
|
|
937
|
+
Decorator for sanitize_stream. Can be used as @sanitize_stream or @sanitize_stream(...).
|
|
938
|
+
All arguments are the same as sanitize_stream().
|
|
939
|
+
"""
|
|
940
|
+
def decorator(func):
|
|
941
|
+
if asyncio.iscoroutinefunction(func):
|
|
942
|
+
@functools.wraps(func)
|
|
943
|
+
async def async_wrapper(*args, **kwargs):
|
|
944
|
+
result = await func(*args, **kwargs)
|
|
945
|
+
return sanitize_stream(
|
|
946
|
+
result,
|
|
947
|
+
intro_value=intro_value,
|
|
948
|
+
to_json=to_json,
|
|
949
|
+
skip_markers=skip_markers,
|
|
950
|
+
strip_chars=strip_chars,
|
|
951
|
+
start_marker=start_marker,
|
|
952
|
+
end_marker=end_marker,
|
|
953
|
+
content_extractor=content_extractor,
|
|
954
|
+
yield_raw_on_error=yield_raw_on_error,
|
|
955
|
+
encoding=encoding,
|
|
956
|
+
encoding_errors=encoding_errors,
|
|
957
|
+
buffer_size=buffer_size,
|
|
958
|
+
line_delimiter=line_delimiter,
|
|
959
|
+
error_handler=error_handler,
|
|
960
|
+
skip_regexes=skip_regexes,
|
|
961
|
+
extract_regexes=extract_regexes,
|
|
962
|
+
object_mode=object_mode,
|
|
963
|
+
raw=raw,
|
|
964
|
+
)
|
|
965
|
+
return async_wrapper
|
|
966
|
+
else:
|
|
967
|
+
@functools.wraps(func)
|
|
968
|
+
def sync_wrapper(*args, **kwargs):
|
|
969
|
+
result = func(*args, **kwargs)
|
|
970
|
+
return sanitize_stream(
|
|
971
|
+
result,
|
|
972
|
+
intro_value=intro_value,
|
|
973
|
+
to_json=to_json,
|
|
974
|
+
skip_markers=skip_markers,
|
|
975
|
+
strip_chars=strip_chars,
|
|
976
|
+
start_marker=start_marker,
|
|
977
|
+
end_marker=end_marker,
|
|
978
|
+
content_extractor=content_extractor,
|
|
979
|
+
yield_raw_on_error=yield_raw_on_error,
|
|
980
|
+
encoding=encoding,
|
|
981
|
+
encoding_errors=encoding_errors,
|
|
982
|
+
buffer_size=buffer_size,
|
|
983
|
+
line_delimiter=line_delimiter,
|
|
984
|
+
error_handler=error_handler,
|
|
985
|
+
skip_regexes=skip_regexes,
|
|
986
|
+
extract_regexes=extract_regexes,
|
|
987
|
+
object_mode=object_mode,
|
|
988
|
+
raw=raw,
|
|
989
|
+
)
|
|
990
|
+
return sync_wrapper
|
|
991
|
+
if _func is None:
|
|
992
|
+
return decorator
|
|
993
|
+
else:
|
|
994
|
+
return decorator(_func)
|
|
995
|
+
|
|
996
|
+
# Alias for decorator usage
|
|
997
|
+
LITSTREAM = sanitize_stream
|
|
998
|
+
|
|
999
|
+
# Decorator aliases
|
|
1000
|
+
sanitize_stream_decorator = _sanitize_stream_decorator
|
|
1001
|
+
lit_streamer = _sanitize_stream_decorator
|
|
1002
|
+
|
|
1003
|
+
# Allow @sanitize_stream and @lit_streamer as decorators
|
|
1004
|
+
import asyncio
|
|
1005
|
+
sanitize_stream.__decorator__ = _sanitize_stream_decorator
|
|
1006
|
+
LITSTREAM.__decorator__ = _sanitize_stream_decorator
|
|
1007
|
+
lit_streamer.__decorator__ = _sanitize_stream_decorator
|
|
1008
|
+
|
|
1009
|
+
def __getattr__(name):
|
|
1010
|
+
if name == 'sanitize_stream':
|
|
1011
|
+
return sanitize_stream
|
|
1012
|
+
if name == 'LITSTREAM':
|
|
1013
|
+
return LITSTREAM
|
|
1014
|
+
if name == 'sanitize_stream_decorator':
|
|
1015
|
+
return _sanitize_stream_decorator
|
|
1016
|
+
if name == 'lit_streamer':
|
|
1017
|
+
return _sanitize_stream_decorator
|
|
1018
|
+
raise AttributeError(f"module {__name__} has no attribute {name}")
|
|
802
1019
|
from .conversation import Conversation # noqa: E402,F401
|
|
803
1020
|
from .Extra.autocoder import AutoCoder # noqa: E402,F401
|
|
804
1021
|
from .optimizers import Optimizers # noqa: E402,F401
|
webscout/Bard.py
CHANGED
|
@@ -81,21 +81,11 @@ class Model(Enum):
|
|
|
81
81
|
model_header (dict): Additional headers required for the model.
|
|
82
82
|
advanced_only (bool): Whether the model is available only for advanced users.
|
|
83
83
|
"""
|
|
84
|
-
#
|
|
84
|
+
# Only the specified models
|
|
85
85
|
UNSPECIFIED = ("unspecified", {}, False)
|
|
86
|
-
G_2_0_FLASH = (
|
|
87
|
-
"gemini-2.0-flash",
|
|
88
|
-
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"f299729663a2343f"]'},
|
|
89
|
-
False,
|
|
90
|
-
)
|
|
91
|
-
G_2_0_FLASH_THINKING = (
|
|
92
|
-
"gemini-2.0-flash-thinking",
|
|
93
|
-
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"7ca48d02d802f20a"]'},
|
|
94
|
-
False,
|
|
95
|
-
)
|
|
96
86
|
G_2_5_FLASH = (
|
|
97
87
|
"gemini-2.5-flash",
|
|
98
|
-
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"
|
|
88
|
+
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"71c2d248d3b102ff"]'},
|
|
99
89
|
False,
|
|
100
90
|
)
|
|
101
91
|
G_2_5_PRO = (
|
|
@@ -103,16 +93,6 @@ class Model(Enum):
|
|
|
103
93
|
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"2525e3954d185b3c"]'},
|
|
104
94
|
False,
|
|
105
95
|
)
|
|
106
|
-
G_2_0_EXP_ADVANCED = (
|
|
107
|
-
"gemini-2.0-exp-advanced",
|
|
108
|
-
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"b1e46a6037e6aa9f"]'},
|
|
109
|
-
True,
|
|
110
|
-
)
|
|
111
|
-
G_2_5_EXP_ADVANCED = (
|
|
112
|
-
"gemini-2.5-exp-advanced",
|
|
113
|
-
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"203e6bb81620bcfe"]'},
|
|
114
|
-
True,
|
|
115
|
-
)
|
|
116
96
|
|
|
117
97
|
def __init__(self, name, header, advanced_only):
|
|
118
98
|
"""
|
|
@@ -43,17 +43,30 @@ class Scira(AISearch):
|
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
45
|
AVAILABLE_MODELS = {
|
|
46
|
-
"scira-default": "
|
|
47
|
-
"scira-
|
|
48
|
-
"scira-
|
|
49
|
-
"scira-
|
|
50
|
-
"scira-
|
|
51
|
-
"scira-
|
|
52
|
-
"scira-
|
|
53
|
-
"scira-
|
|
54
|
-
"scira-
|
|
55
|
-
"scira-
|
|
56
|
-
"scira-
|
|
46
|
+
"scira-default": "grok-3-mini", # thinking model
|
|
47
|
+
"scira-x-fast-mini": "grok-3-mini-fast",
|
|
48
|
+
"scira-x-fast": "grok-3-fast",
|
|
49
|
+
"scira-nano": "gpt-4.1-nano",
|
|
50
|
+
"scira-grok-3": "grok-3",
|
|
51
|
+
"scira-grok-4": "grok-4",
|
|
52
|
+
"scira-vision": "grok-2-vision-1212",
|
|
53
|
+
"scira-g2": "grok-2-latest",
|
|
54
|
+
"scira-4o-mini": "gpt-4o-mini",
|
|
55
|
+
"scira-o4-mini": "o4-mini-2025-04-16",
|
|
56
|
+
"scira-o3": "o3",
|
|
57
|
+
"scira-qwen-32b": "qwen/qwen3-32b",
|
|
58
|
+
"scira-qwen-30b": "qwen3-30b-a3b",
|
|
59
|
+
"scira-deepseek-v3": "deepseek-v3-0324",
|
|
60
|
+
"scira-haiku": "claude-3-5-haiku-20241022",
|
|
61
|
+
"scira-mistral": "mistral-small-latest",
|
|
62
|
+
"scira-google-lite": "gemini-2.5-flash-lite-preview-06-17",
|
|
63
|
+
"scira-google": "gemini-2.5-flash",
|
|
64
|
+
"scira-google-pro": "gemini-2.5-pro",
|
|
65
|
+
"scira-anthropic": "claude-sonnet-4-20250514",
|
|
66
|
+
"scira-anthropic-thinking": "claude-sonnet-4-20250514",
|
|
67
|
+
"scira-opus": "claude-4-opus-20250514",
|
|
68
|
+
"scira-opus-pro": "claude-4-opus-20250514",
|
|
69
|
+
"scira-llama-4": "meta-llama/llama-4-maverick-17b-128e-instruct",
|
|
57
70
|
}
|
|
58
71
|
def __init__(
|
|
59
72
|
self,
|