chunklet.cli
Functions:
-
chunk_command–Chunk text or files based on specified parameters.
-
split_command–Split text or a single file into sentences
-
visualize_command–Start the web-based chunk visualizer interface for interactive text and code chunking.
chunk_command
chunk_command(
text: Optional[str] = typer.Argument(
None,
help="The input text to chunk. If not provided, --source must be used.",
),
source: Optional[List[Path]] = typer.Option(
None,
"--source",
"-s",
help="Path(s) to one or more files or directories to read input from. Overrides the 'text' argument.",
),
code: bool = typer.Option(
False,
"--code",
help="Use CodeChunker for code files.",
),
doc: bool = typer.Option(
False,
"--doc",
help="Use DocumentChunker for document files.",
),
destination: Optional[Path] = typer.Option(
None,
"--destination",
"-d",
help="Path to a file (for single output) or a directory (for batch output) to write the chunks.",
),
lang: str = typer.Option(
"auto",
"--lang",
help="Language of the text (e.g., 'en', 'fr', 'auto'). (default: auto)",
),
max_tokens: int = typer.Option(
None,
"--max-tokens",
help="Maximum number of tokens per chunk. Applies to all chunking strategies. (must be >= 12)",
),
max_sentences: int = typer.Option(
None,
"--max-sentences",
help="Maximum number of sentences per chunk. Applies to PlainTextChunker and DocumentChunker. (must be >= 1)",
),
max_section_breaks: Optional[int] = typer.Option(
None,
"--max-section-breaks",
help="Maximum number of section breaks per chunk. Applies to PlainTextChunker and DocumentChunker. (must be >= 1)",
),
overlap_percent: float = typer.Option(
20.0,
"--overlap-percent",
help="Percentage of overlap between chunks (0-85). Applies to PlainTextChunker and DocumentChunker. (default: 20)",
),
offset: int = typer.Option(
0,
"--offset",
help="Starting sentence offset for chunking. Applies to PlainTextChunker and DocumentChunker. (default: 0)",
),
verbose: bool = typer.Option(
False,
"--verbose",
"-v",
help="Enable verbose logging.",
),
tokenizer_command: Optional[str] = typer.Option(
None,
"--tokenizer-command",
help="A shell command to use for token counting. The command should take text as stdin and output the token count as a number.",
),
metadata: bool = typer.Option(
False,
"--metadata",
help="Include metadata in the output. If --destination is a directory, metadata is saved as separate .json files; otherwise, it's included inline in the output.",
),
n_jobs: Optional[int] = typer.Option(
None,
"--n-jobs",
help="Number of parallel jobs for batch chunking. (default: None, uses all available cores)",
),
on_errors: OnError = typer.Option(
OnError.raise_,
"--on-errors",
help="How to handle errors during processing: 'raise', 'skip' or 'break'",
),
max_lines: int = typer.Option(
None,
"--max-lines",
help="Maximum number of lines per chunk. Applies to CodeChunker only. (must be >= 5)",
),
max_functions: int = typer.Option(
None,
"--max-functions",
help="Maximum number of functions per chunk. Applies to CodeChunker only. (must be >= 1)",
),
docstring_mode: DocstringMode = typer.Option(
DocstringMode.all_,
"--docstring-mode",
help="Docstring processing strategy for CodeChunker: 'summary', 'all', or 'excluded'. Applies to CodeChunker only.",
),
strict: bool = typer.Option(
True,
"--strict",
help="If True, raise error when structural blocks exceed max_tokens in CodeChunker. If False, split oversized blocks. Applies to CodeChunker only.",
),
include_comments: bool = typer.Option(
True,
"--include-comments",
help="Include comments in output chunks for CodeChunker. Applies to CodeChunker only.",
),
)
Chunk text or files based on specified parameters.
Source code in src/chunklet/cli.py
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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
split_command
split_command(
text: Optional[str] = typer.Argument(
None,
help="The input text to split. If not provided, --source must be used.",
),
source: Optional[Path] = typer.Option(
None,
"--source",
"-s",
help="Path to a single file to read input from. Cannot be a directory or multiple files.",
),
destination: Optional[Path] = typer.Option(
None,
"--destination",
"-d",
help="Path to a single file to write the segmented sentences (separated by \\n). Cannot be a directory.",
),
lang: str = typer.Option(
"auto",
"--lang",
help="Language of the text (e.g., 'en', 'fr', 'auto').",
),
verbose: bool = typer.Option(
False,
"--verbose",
"-v",
help="Enable verbose logging.",
),
)
Split text or a single file into sentences
Source code in src/chunklet/cli.py
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 | |
visualize_command
visualize_command(
host: str = typer.Option(
"127.0.0.1",
"--host",
help="Host IP to bind the visualizer server. (default: 127.0.0.1)",
),
port: int = typer.Option(
8000,
"--port",
"-p",
help="Port number to run the visualizer server. (default: 8000)",
),
tokenizer_command: Optional[str] = typer.Option(
None,
"--tokenizer-command",
help="A shell command to use for token counting in the visualizer. The command should take text as stdin and output the token count as a number.",
),
headless: bool = typer.Option(
False,
"--headless",
help="Run visualizer in headless mode (don't open browser automatically).",
),
)
Start the web-based chunk visualizer interface for interactive text and code chunking.
Source code in src/chunklet/cli.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | |