webscout 6.0__py3-none-any.whl → 6.1__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/Agents/Onlinesearcher.py +22 -10
- webscout/Agents/functioncall.py +2 -2
- webscout/Bard.py +21 -21
- webscout/Local/__init__.py +6 -7
- webscout/Local/formats.py +404 -194
- webscout/Local/model.py +1074 -477
- webscout/Local/samplers.py +108 -144
- webscout/Local/thread.py +251 -410
- webscout/Local/ui.py +401 -0
- webscout/Local/utils.py +308 -131
- webscout/Provider/Amigo.py +1 -1
- webscout/Provider/NinjaChat.py +200 -0
- webscout/Provider/TTI/Nexra.py +3 -3
- webscout/Provider/TTI/__init__.py +2 -1
- webscout/Provider/TTI/aiforce.py +2 -2
- webscout/Provider/TTI/imgninza.py +136 -0
- webscout/Provider/Youchat.py +1 -1
- webscout/Provider/__init__.py +8 -1
- webscout/Provider/aimathgpt.py +193 -0
- webscout/Provider/felo_search.py +1 -1
- webscout/Provider/gaurish.py +168 -0
- webscout/Provider/geminiprorealtime.py +160 -0
- webscout/Provider/julius.py +4 -0
- webscout/exceptions.py +5 -1
- webscout/utils.py +3 -0
- webscout/version.py +1 -1
- webscout/webscout_search.py +154 -123
- {webscout-6.0.dist-info → webscout-6.1.dist-info}/METADATA +123 -120
- {webscout-6.0.dist-info → webscout-6.1.dist-info}/RECORD +33 -28
- webscout/Local/rawdog.py +0 -946
- {webscout-6.0.dist-info → webscout-6.1.dist-info}/LICENSE.md +0 -0
- {webscout-6.0.dist-info → webscout-6.1.dist-info}/WHEEL +0 -0
- {webscout-6.0.dist-info → webscout-6.1.dist-info}/entry_points.txt +0 -0
- {webscout-6.0.dist-info → webscout-6.1.dist-info}/top_level.txt +0 -0
webscout/Local/samplers.py
CHANGED
|
@@ -1,161 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
from ._version import __version__, __llama_cpp_version__
|
|
3
|
-
|
|
4
|
-
"""Submodule containing SamplerSettings class and some preset samplers"""
|
|
5
|
-
|
|
1
|
+
from typing import Optional
|
|
6
2
|
from sys import maxsize
|
|
7
3
|
|
|
4
|
+
from .utils import assert_type, NoneType
|
|
8
5
|
|
|
9
6
|
MAX_TEMP = float(maxsize)
|
|
10
7
|
|
|
11
8
|
class SamplerSettings:
|
|
12
9
|
"""
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
Specifies sampling parameters for controlling text generation.
|
|
11
|
+
|
|
12
|
+
This class allows you to fine-tune the behavior of text generation
|
|
13
|
+
models by adjusting various sampling parameters. These settings are
|
|
14
|
+
passed as an optional parameter to functions like `Thread.__init__()`,
|
|
15
|
+
`Model.generate()`, `Model.stream()`, and `Model.stream_print()`.
|
|
16
|
+
|
|
17
|
+
If a parameter is unspecified, the default value from llama.cpp is used.
|
|
18
|
+
If all parameters are unspecified, the behavior is equivalent to
|
|
19
|
+
`DefaultSampling`.
|
|
20
|
+
|
|
21
|
+
Setting a parameter explicitly to `None` disables it. When all samplers
|
|
22
|
+
are disabled, it's equivalent to `NoSampling` (unmodified probability
|
|
23
|
+
distribution).
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
max_len_tokens (Optional[int]): Maximum number of tokens to generate.
|
|
27
|
+
Defaults to -1 (no limit).
|
|
28
|
+
top_k (Optional[int]): Number of highest probability tokens to consider.
|
|
29
|
+
Defaults to 40. Set to `None` to disable.
|
|
30
|
+
top_p (Optional[float]): Nucleus sampling threshold (0.0 - 1.0).
|
|
31
|
+
Defaults to 0.95. Set to `None` to disable.
|
|
32
|
+
min_p (Optional[float]): Minimum probability threshold (0.0 - 1.0).
|
|
33
|
+
Defaults to 0.05. Set to `None` to disable.
|
|
34
|
+
temp (Optional[float]): Temperature for sampling (0.0 - inf).
|
|
35
|
+
Defaults to 0.8. Set to `None` to disable.
|
|
36
|
+
frequency_penalty (Optional[float]): Penalty for repeating tokens.
|
|
37
|
+
Defaults to 0.0.
|
|
38
|
+
presence_penalty (Optional[float]): Penalty for generating new tokens.
|
|
39
|
+
Defaults to 0.0.
|
|
40
|
+
repeat_penalty (Optional[float]): Penalty for repeating token sequences.
|
|
41
|
+
Defaults to 1.0.
|
|
42
|
+
|
|
43
|
+
Presets:
|
|
44
|
+
- `GreedyDecoding`: Always chooses the most likely token.
|
|
45
|
+
- `DefaultSampling`: Uses default parameters from llama.cpp.
|
|
46
|
+
- `NoSampling`: Unmodified probability distribution (all parameters disabled).
|
|
47
|
+
- `ClassicSampling`: Reflects old llama.cpp defaults.
|
|
48
|
+
- `SemiSampling`: Halfway between DefaultSampling and SimpleSampling.
|
|
49
|
+
- `TikTokenSampling`: For models with large vocabularies.
|
|
50
|
+
- `LowMinPSampling`, `MinPSampling`, `StrictMinPSampling`: Use `min_p` as the only active sampler.
|
|
51
|
+
- `ContrastiveSearch`, `WarmContrastiveSearch`: Implement contrastive search.
|
|
52
|
+
- `RandomSampling`: Outputs completely random tokens (useless).
|
|
53
|
+
- `LowTempSampling`: Default sampling with reduced temperature.
|
|
54
|
+
- `HighTempSampling`: Default sampling with increased temperature.
|
|
55
|
+
- `LowTopPSampling`, `TopPSampling`, `StrictTopPSampling`: Use `top_p` as the primary sampler.
|
|
56
|
+
- `MidnightMiqu`: For sophosympatheia/Midnight-Miqu-70B-v1.5 model.
|
|
57
|
+
- `Llama3`: For meta-llama/Meta-Llama-3.1-8B-Instruct model.
|
|
58
|
+
- `Nemo`: For mistralai/Mistral-Nemo-Instruct-2407 model.
|
|
15
59
|
"""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'max_len_tokens':
|
|
19
|
-
'
|
|
20
|
-
'top_p':
|
|
21
|
-
'min_p':
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
60
|
+
|
|
61
|
+
param_types: dict[str, tuple[type]] = {
|
|
62
|
+
'max_len_tokens': (int, NoneType),
|
|
63
|
+
'top_k': (int, NoneType),
|
|
64
|
+
'top_p': (float, NoneType),
|
|
65
|
+
'min_p': (float, NoneType),
|
|
66
|
+
'temp': (float, NoneType),
|
|
67
|
+
'frequency_penalty': (float, NoneType),
|
|
68
|
+
'presence_penalty': (float, NoneType),
|
|
69
|
+
'repeat_penalty': (float, NoneType)
|
|
26
70
|
}
|
|
27
71
|
|
|
28
72
|
def __init__(
|
|
29
73
|
self,
|
|
30
|
-
max_len_tokens:
|
|
31
|
-
|
|
32
|
-
top_p:
|
|
33
|
-
min_p:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
74
|
+
max_len_tokens: Optional[int] = -1,
|
|
75
|
+
top_k: Optional[int] = 40,
|
|
76
|
+
top_p: Optional[float] = 0.95,
|
|
77
|
+
min_p: Optional[float] = 0.05,
|
|
78
|
+
temp: Optional[float] = 0.8,
|
|
79
|
+
frequency_penalty: Optional[float] = 0.0,
|
|
80
|
+
presence_penalty: Optional[float] = 0.0,
|
|
81
|
+
repeat_penalty: Optional[float] = 1.0
|
|
38
82
|
):
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
83
|
+
self.max_len_tokens = max_len_tokens if max_len_tokens is not None else -1
|
|
84
|
+
self.top_k = top_k if top_k is not None else -1
|
|
85
|
+
self.top_p = top_p if top_p is not None else 1.0
|
|
86
|
+
self.min_p = min_p if min_p is not None else 0.0
|
|
87
|
+
self.temp = temp if temp is not None else 1.0
|
|
88
|
+
self.frequency_penalty = frequency_penalty if frequency_penalty is not None else 0.0
|
|
89
|
+
self.presence_penalty = presence_penalty if presence_penalty is not None else 0.0
|
|
90
|
+
self.repeat_penalty = repeat_penalty if repeat_penalty is not None else 1.0
|
|
91
|
+
|
|
92
|
+
# Validate parameters using param_types dictionary
|
|
93
|
+
for param_name, param_value in self.__dict__.items():
|
|
94
|
+
assert_type(param_value, self.param_types[param_name],
|
|
95
|
+
f'{param_name} parameter', 'SamplerSettings')
|
|
42
96
|
|
|
43
|
-
self.max_len_tokens = max_len_tokens
|
|
44
|
-
self.temp = temp
|
|
45
|
-
self.top_p = top_p
|
|
46
|
-
self.min_p = min_p
|
|
47
|
-
self.frequency_penalty = frequency_penalty
|
|
48
|
-
self.presence_penalty = presence_penalty
|
|
49
|
-
self.repeat_penalty = repeat_penalty
|
|
50
|
-
self.top_k = top_k
|
|
51
|
-
|
|
52
|
-
for sampler_param in SamplerSettings.ParamTypes:
|
|
53
|
-
expected_type = SamplerSettings.ParamTypes[sampler_param]
|
|
54
|
-
actual_type = type(getattr(self, sampler_param))
|
|
55
|
-
if actual_type != expected_type:
|
|
56
|
-
raise TypeError(
|
|
57
|
-
f"wrong type for SamplerSettings parameter '{sampler_param}'"
|
|
58
|
-
f" - expected {expected_type}, got {actual_type}"
|
|
59
|
-
)
|
|
60
|
-
|
|
61
97
|
def __repr__(self) -> str:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
repr_str += f'min_p={self.min_p}, '
|
|
67
|
-
repr_str += f'frequency_penalty={self.frequency_penalty}, '
|
|
68
|
-
repr_str += f'presence_penalty={self.presence_penalty}, '
|
|
69
|
-
repr_str += f'repeat_penalty={self.repeat_penalty}, '
|
|
70
|
-
repr_str += f'top_k={self.top_k})'
|
|
71
|
-
return repr_str
|
|
72
|
-
|
|
73
|
-
# most likely token is always chosen
|
|
74
|
-
GreedyDecoding = SamplerSettings(
|
|
75
|
-
temp = 0.0,
|
|
76
|
-
)
|
|
98
|
+
params = ', '.join(
|
|
99
|
+
f'{name}={value}' for name, value in self.__dict__.items()
|
|
100
|
+
)
|
|
101
|
+
return f'SamplerSettings({params})'
|
|
77
102
|
|
|
78
|
-
#
|
|
103
|
+
# Predefined sampler settings
|
|
104
|
+
GreedyDecoding = SamplerSettings(temp=0.0)
|
|
79
105
|
DefaultSampling = SamplerSettings()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
top_k=80
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
# for models with large vocabulary, which tend to run hot
|
|
104
|
-
TikTokenSampling = SamplerSettings(
|
|
105
|
-
temp=0.6,
|
|
106
|
-
repeat_penalty=1.1
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
# use min_p as the only active sampler (more permissive)
|
|
110
|
-
LowMinPSampling = SamplerSettings(
|
|
111
|
-
temp = 1.0,
|
|
112
|
-
top_p = 1.0,
|
|
113
|
-
min_p = 0.05,
|
|
114
|
-
top_k = -1
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
# use min_p as the only active sampler (moderate)
|
|
118
|
-
MinPSampling = SamplerSettings(
|
|
119
|
-
temp = 1.0,
|
|
120
|
-
top_p = 1.0,
|
|
121
|
-
min_p = 0.1,
|
|
122
|
-
top_k = -1
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
# use min_p as the only active sampler (more restrictive)
|
|
126
|
-
StrictMinPSampling = SamplerSettings(
|
|
127
|
-
temp = 1.0,
|
|
128
|
-
top_p = 1.0,
|
|
129
|
-
min_p = 0.2,
|
|
130
|
-
top_k = -1
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
# https://arxiv.org/abs/2210.14140
|
|
134
|
-
ContrastiveSearch = SamplerSettings(
|
|
135
|
-
temp = 0.0,
|
|
136
|
-
presence_penalty = 0.4
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
# https://arxiv.org/abs/2210.14140
|
|
140
|
-
WarmContrastiveSearch = SamplerSettings(
|
|
141
|
-
temp = 0.0,
|
|
142
|
-
presence_penalty = 0.8
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
# outputs completely random tokens from vocab (useless)
|
|
146
|
-
RandomSampling = SamplerSettings(
|
|
147
|
-
temp = MAX_TEMP,
|
|
148
|
-
top_p = 1.0,
|
|
149
|
-
min_p = 0.0,
|
|
150
|
-
top_k = -1
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
# default sampling with reduced temperature
|
|
154
|
-
LowTempSampling = SamplerSettings(
|
|
155
|
-
temp = 0.4
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
# default sampling with increased temperature
|
|
159
|
-
HighTempSampling = SamplerSettings(
|
|
160
|
-
temp = 1.2
|
|
161
|
-
)
|
|
106
|
+
NoSampling = SimpleSampling = SamplerSettings(top_k=None, top_p=None, min_p=None, temp=None)
|
|
107
|
+
ClassicSampling = SamplerSettings(min_p=None, repeat_penalty=1.1)
|
|
108
|
+
SemiSampling = SamplerSettings(top_k=80, top_p=0.975, min_p=0.025, temp=0.9)
|
|
109
|
+
TikTokenSampling = SamplerSettings(temp=0.65)
|
|
110
|
+
LowMinPSampling = SamplerSettings(top_k=None, top_p=None, min_p=0.01, temp=None)
|
|
111
|
+
MinPSampling = SamplerSettings(top_k=None, top_p=None, min_p=0.075, temp=None)
|
|
112
|
+
StrictMinPSampling = SamplerSettings(top_k=None, top_p=None, min_p=0.2, temp=None)
|
|
113
|
+
ContrastiveSearch = SamplerSettings(top_k=None, top_p=None, min_p=None, temp=0.0, presence_penalty=0.6)
|
|
114
|
+
WarmContrastiveSearch = SamplerSettings(top_k=None, top_p=None, min_p=None, temp=0.0, presence_penalty=1.0)
|
|
115
|
+
RandomSampling = SamplerSettings(top_k=None, top_p=None, min_p=None, temp=MAX_TEMP)
|
|
116
|
+
LowTempSampling = SamplerSettings(temp=0.4)
|
|
117
|
+
HighTempSampling = SamplerSettings(temp=1.1)
|
|
118
|
+
LowTopPSampling = SamplerSettings(top_k=None, top_p=0.98, min_p=None, temp=None)
|
|
119
|
+
TopPSampling = SamplerSettings(top_k=None, top_p=0.9, min_p=None, temp=None)
|
|
120
|
+
StrictTopPSampling = SamplerSettings(top_k=None, top_p=0.7, min_p=None, temp=None)
|
|
121
|
+
|
|
122
|
+
# Model-specific samplers
|
|
123
|
+
MidnightMiqu = SamplerSettings(top_k=None, top_p=None, min_p=0.12, temp=1.0, repeat_penalty=1.05) # sophosympatheia/Midnight-Miqu-70B-v1.5
|
|
124
|
+
Llama3 = SamplerSettings(top_k=None, top_p=0.9, min_p=None, temp=0.6) # meta-llama/Meta-Llama-3.1-8B-Instruct
|
|
125
|
+
Nemo = MistralNemo = MistralSmall = SamplerSettings(top_k=None, top_p=0.85, min_p=None, temp=0.7) # mistralai/Mistral-Nemo-Instruct-2407
|