vllm_mlx.gradio_app¶
Gradio Chatbot Interface for vllm-mlx.
View the complete module source at #L1-L411.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.gradio_app
¶
Gradio Chatbot Interface for vllm-mlx.
A multimodal chat interface that connects to the vllm-mlx server and supports text, images, and video files.
Usage
First start the server with a multimodal model:¶
vllm-mlx serve --served-model-name default mlx-community/Qwen3-VL-4B-Instruct-3bit --port 8000
Then run the app:¶
vllm-mlx-chat
Or with a different served-model name served on localhost:8000:¶
vllm-mlx-chat --served-model-name
Note
Query the /v1/models endpoint on localhost with curl and jq to see available models and their names:
vllm_mlx.gradio_app.encode_file_to_base64
¶
Encode a file to base64 data URL.
Returns:
-
tuple[str, str]–Tuple of (data_url, media_type) where media_type is 'image' or 'video'
Source code in vllm_mlx/gradio_app.py
vllm_mlx.gradio_app.build_message_content
¶
Build OpenAI-compatible message content with text and optional files.
Parameters:
-
text(str) –The text message
-
files(list[str] | None, default:None) –Optional list of file paths (images or videos)
Returns:
-
list | str–Content in OpenAI multimodal format
Source code in vllm_mlx/gradio_app.py
vllm_mlx.gradio_app.create_chat_function
¶
create_chat_function(server_url: str, max_tokens: int, temperature: float, served_model_name: str = 'default')
Create the chat function for Gradio ChatInterface.
Parameters:
-
server_url(str) –URL of the vllm-mlx server
-
max_tokens(int) –Maximum tokens to generate
-
temperature(float) –Sampling temperature
-
served_model_name(str, default:'default') –Model name to send in OpenAI-compatible requests
Returns:
-
–
Chat function compatible with gr.ChatInterface
Source code in vllm_mlx/gradio_app.py
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 | |
vllm_mlx.gradio_app.main
¶
Run the Gradio app.
Source code in vllm_mlx/gradio_app.py
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 | |
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.gradio_app.encode_file_to_base64 · function
Encode a file to base64 data URL.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[str, str] - Direct return expressions:
(f'data:{mime_type};base64,{data}', media_type)
Exceptions and behavior
Function encode_file_to_base64 calls Path, path.suffix.lower, open, base64.b64encode(f.read()).decode; returns (f'data:{mime_type};base64,{data}', media_type).
No direct raise statement appears in this definition.
vllm_mlx.gradio_app.build_message_content · function
Build OpenAI-compatible message content with text and optional files.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
The text message |
files |
list[str] \| None |
no |
None |
Optional list of file paths (images or videos) |
Returns
- Type:
list | str - Direct return expressions:
text;content if content else text
Exceptions and behavior
Function build_message_content calls content.append, encode_file_to_base64; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.gradio_app.create_chat_function · function
vllm_mlx.gradio_app.create_chat_function(server_url: str, max_tokens: int, temperature: float, served_model_name: str = 'default') -> not annotated
Create the chat function for Gradio ChatInterface.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
server_url |
str |
yes |
none |
URL of the vllm-mlx server |
max_tokens |
int |
yes |
none |
Maximum tokens to generate |
temperature |
float |
yes |
none |
Sampling temperature |
served_model_name |
str |
no |
'default' |
Model name to send in OpenAI-compatible requests |
Returns
- Type:
not annotated - Direct return expressions:
chat
Exceptions and behavior
Function create_chat_function returns chat.
No direct raise statement appears in this definition.
vllm_mlx.gradio_app.create_chat_function.chat · nested function
Process a multimodal message and return response.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
message |
dict |
yes |
none |
Dict with 'text' and optional 'files' keys |
history |
list |
yes |
none |
List of previous messages |
Returns
- Type:
str - Direct return expressions:
result['choices'][0]['message']['content'];'Error: Cannot connect to server. Make sure vllm-mlx is running.';'Error: Timeout - server took too long to respond.';f'Error: {str(e)}'
Exceptions and behavior
Nested Function create_chat_function.chat calls isinstance, message.get, print, len; has 4 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.gradio_app.main · function
Run the Gradio app.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, print.
No direct raise statement appears in this definition.
vllm_mlx.gradio_app.main.text_chat · nested function
Process a text-only message.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
message |
str |
yes |
none |
Required positional or keyword input. |
history |
list |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
result['choices'][0]['message']['content'];'Error: Cannot connect to server. Make sure vllm-mlx is running.';'Error: Timeout - server took too long to respond.';f'Error: {str(e)}'
Exceptions and behavior
Nested Function main.text_chat calls isinstance, msg.get, p.get, ' '.join; has 4 explicit return paths.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
encode_file_to_base64 |
function | encode_file_to_base64(file_path: str) -> tuple[str, str] |
Encode a file to base64 data URL. | #L33-L76 |
build_message_content |
function | build_message_content(text: str, files: list[str] \| None = None) -> list \| str |
Build OpenAI-compatible message content with text and optional files. | #L79-L108 |
create_chat_function |
function | create_chat_function(server_url: str, max_tokens: int, temperature: float, served_model_name: str = 'default') -> not annotated |
Create the chat function for Gradio ChatInterface. | #L111-L257 |
create_chat_function.chat |
nested function | create_chat_function.chat(message: dict, history: list) -> str |
Process a multimodal message and return response. | #L132-L255 |
main |
function | main() -> not annotated |
Run the Gradio app. | #L260-L407 |
main.text_chat |
nested function | main.text_chat(message: str, history: list) -> str |
Process a text-only message. | #L331-L368 |