Reference¶
Accessible imports for the panel_web_llm package.
ModelParam
¶
Bases: Parameterized
A class to represent model parameters including model name, size, and quantization.
This class provides methods to lookup model slugs based on mappings, convert parameters to dictionaries, and create instances from nested selects or model slugs.
Source code in src/panel_web_llm/models.py
model = param.String(doc='The model name.')
class-attribute
instance-attribute
¶
The name of the model.
quantization = param.String(doc='The quantization of the model.')
class-attribute
instance-attribute
¶
The quantization applied to the model, e.g., 'AWQ', 'GPTQ'.
size = param.String(doc='The size of the model.')
class-attribute
instance-attribute
¶
The size of the model, e.g., '7B', '13B', etc.
from_model_slug(model_slug)
classmethod
¶
Creates a ModelParam instance from a model slug string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_slug
|
str
|
The model slug string, e.g., 'llama-7B-AWQ'. |
required |
Returns¶
ModelParam: A ModelParam instance initialized with the parsed values from the model slug.
Source code in src/panel_web_llm/models.py
from_nested_select(nested_select)
classmethod
¶
Creates a ModelParam instance from a NestedSelect widget.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_select
|
NestedSelect
|
The NestedSelect widget containing the model parameters. |
required |
Returns¶
ModelParam: A ModelParam instance initialized with the values from the NestedSelect.
Source code in src/panel_web_llm/models.py
lookup_model_slug(model_mapping)
¶
Looks up the model slug based on the given model mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_mapping
|
dict
|
A nested dictionary mapping model name, size, and quantization to a model slug. |
required |
Returns¶
str: The model slug corresponding to the current model parameters.
Source code in src/panel_web_llm/models.py
to_dict(levels)
¶
Converts the model parameters to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
levels
|
list
|
A list of keys or dictionaries defining how the parameters should be structured in the output dictionary. If the levels are strings they will be used as keys. If the levels are dictionaries, the 'name' key will be used as key. |
required |
Returns¶
dict: A dictionary representation of the model parameters.
Source code in src/panel_web_llm/models.py
WebLLM
¶
Bases: JSComponent
A Panel component for interacting with WebLLM models.
This component provides an interface to load and interact with models served
by the web-llm
library. It manages model loading, chat completion,
and provides controls for model selection and temperature.
Source code in src/panel_web_llm/main.py
15 16 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 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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
history = param.Integer(default=10, bounds=(1, 100), doc='The number of previous messages to include in the completion.')
class-attribute
instance-attribute
¶
load_layout = param.Selector(default='row', objects=['row', 'column'], doc='\n The layout type of the widgets.')
class-attribute
instance-attribute
¶
load_model = param.Event(doc='Event to trigger model loading.')
class-attribute
instance-attribute
¶
load_status = param.Dict(default={'text': '', 'progress': 0})
class-attribute
instance-attribute
¶
loaded = param.Boolean(default=False, doc='Whether the model is loaded.')
class-attribute
instance-attribute
¶
loading = param.Boolean(default=False, doc='\n Whether the model is currently loading.')
class-attribute
instance-attribute
¶
menu
property
¶
model_mapping = param.Dict(default=MODEL_MAPPING, doc='Nested mapping of model names to slugs.')
class-attribute
instance-attribute
¶
model_slug = param.Selector(default='', doc='The model slug to load.')
class-attribute
instance-attribute
¶
multiple_loads = param.Boolean(default=True, doc='Whether to allow loading different models multiple times')
class-attribute
instance-attribute
¶
running = param.Boolean(default=False, doc='Whether the LLM is currently running.')
class-attribute
instance-attribute
¶
system = param.String(default='Be the most you can be; spread positivity!', doc='The system prompt for the model completion.')
class-attribute
instance-attribute
¶
temperature = param.Number(default=1, bounds=(0, 2), doc='The temperature for the model completion.')
class-attribute
instance-attribute
¶
callback(contents, user, instance)
async
¶
Callback function for chat completion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
contents
|
str
|
The current user message. |
required |
user
|
str
|
The username of the user sending the message. |
required |
instance
|
ChatInterface
|
The ChatInterface instance. |
required |
Yields¶
dict or str: Yields either the messages as dict or a markdown string
Raises¶
RuntimeError: If the model is not loaded
Source code in src/panel_web_llm/main.py
create_completion(messages)
async
¶
Creates a chat completion with the WebLLM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
list
|
A list of message dictionaries representing the chat history. |
required |
Yields¶
dict: The response chunks from the LLM.
Raises¶
RuntimeError: If the model is not loaded.
Source code in src/panel_web_llm/main.py
refresh_model_mapping()
¶
Refreshes the model mapping by fetching the latest from the mlc.ai website.
This method scrapes the mlc.ai website to get the available models and their parameters.
Requires bs4 and requests to be installed.
Source code in src/panel_web_llm/main.py
WebLLMComponentMixin
¶
Bases: Parameterized
A mixin class for integrating the WebLLM component with other components.
This mixin provides an easy way to add a WebLLM instance and its necessary attributes to other Panel components.
Source code in src/panel_web_llm/main.py
callback = self.web_llm.callback
instance-attribute
¶
header = pn.Column(self.web_llm.menu, self.web_llm)
instance-attribute
¶
load_on_init = param.Boolean(default=False, doc='Whether to load the model on initialization.')
class-attribute
instance-attribute
¶
model_slug = param.String(doc='The model slug to load.')
class-attribute
instance-attribute
¶
multiple_loads = param.Boolean(default=True, doc='Whether to allow loading different models multiple times.')
class-attribute
instance-attribute
¶
web_llm = WebLLM(model_slug=self.model_slug, multiple_loads=self.multiple_loads, **self.web_llm_kwargs)
instance-attribute
¶
web_llm_kwargs = param.Dict(default={}, doc='Keyword arguments to propagate to the WebLLM.')
class-attribute
instance-attribute
¶
WebLLMFeed
¶
Bases: ChatFeed
, WebLLMComponentMixin
See ChatFeed for params and usage.
Source code in src/panel_web_llm/main.py
WebLLMInterface
¶
Bases: ChatInterface
, WebLLMComponentMixin
See ChatInterface for params and usage.