Skip to main content

No project description provided

Project description

Here's a revised version of your README.md with tighter prose, clearer structure, and minimal fluff. I've preserved all essential information while improving readability and precision.


cereproc.py

old/cereproc.py processes large documents by splitting them into chunks suitable for the Cerebras zai-glm-4.6 model, generating completions for each chunk, and reassembling the results while maintaining context.

Quick Start

export CEREBRAS_API_KEY="csk-..."
uv run old/cereproc.py --input_data document.md --output_data document.out.md

Add optional guidance using inline prompts or instruction files:

uv run old/cereproc.py \
  --input_data huge.md \
  --file_prompt prompts/style.md \
  --prompt "Write concise technical summaries." \
  -c code \
  --chunk_size 28000 \
  --sample_size 256 \
  --verbose

CLI

NAME
    cerebrate-file - Process large documents by chunking for Cerebras zai-glm-4.6

SYNOPSIS
    cerebrate-file INPUT_DATA <flags>

POSITIONAL ARGUMENTS
    INPUT_DATA
        Path to input file to process

FLAGS
    -o, --output_data=OUTPUT_DATA
        Output file path (default: overwrite input)
    -f, --file_prompt=FILE_PROMPT
        Path to file with initial instructions
    -p, --prompt=PROMPT
        Inline prompt text (appended after file_prompt)
    -c, --chunk_size=CHUNK_SIZE
        Target max chunk size in tokens (default: 32000)
    --max_tokens_ratio=MAX_TOKENS_RATIO
        Completion budget as % of chunk size (default: 100)
    --data_format=DATA_FORMAT
        Chunking strategy: text | semantic | markdown | code (default: markdown)
    -s, --sample_size=SAMPLE_SIZE
        Tokens from previous request/response to maintain context (default: 200)
    --temp=TEMP
        Model temperature (default: 0.7)
    --top_p=TOP_P
        Model top-p sampling (default: 0.8)
    --model=MODEL
        Override default model name (default: zai-glm-4.6)
    -v, --verbose
        Enable debug logging
    -e, --explain
        Parse and update frontmatter metadata
    --dry_run
        Show chunking details without calling the API

Streaming via STDIN/STDOUT

Use - to read from stdin or write to stdout:

cat huge.md | uv run cerebrate_file --input_data - --output_data - > processed.md

Processing Pipeline

  1. Load .env and validate CEREBRAS_API_KEY and CLI arguments.
  2. Construct base prompt from --file_prompt and --prompt, separated by two newlines. Count its tokens.
  3. Read input file, preserving frontmatter. Parse metadata if --explain is enabled.
  4. Split document body using one of these strategies:
    • text: line-based greedy splitting
    • semantic: paragraph-aware via semantic-text-splitter
    • markdown: structure-preserving Markdown splitting
    • code: regex-based source code boundaries
  5. For each chunk, optionally prepend/append continuity examples (--sample_size tokens each) from prior interactions, ensuring total tokens stay under the 131K limit.
  6. Stream responses from Cerebras, with automatic retry and backoff on transient errors (tenacity).
  7. Write final output atomically. Update frontmatter if --explain is active.

Explain Mode Metadata

When --explain is set, the script looks for frontmatter containing:

  • title
  • author
  • id
  • type
  • date

Missing fields are filled via a structured JSON query to the model. Use --dry_run to preview parsed metadata without making network calls.

Dry Run Workflow

Use --dry_run to inspect:

  • Chunk sizes
  • Token budgets
  • Message structure

No API calls are made in this mode.

Dependencies

Install with uv or your preferred package manager:

  • fire
  • loguru
  • python-dotenv
  • tenacity
  • cerebras-cloud-sdk
  • semantic-text-splitter
  • qwen-tokenizer
  • tqdm
  • python-frontmatter

Environment Setup

Set CEREBRAS_API_KEY before running. The tool will warn about placeholder keys and validate basic formatting. Use --verbose for extra runtime info and rate-limit headers.

Testing Tips

  1. Run with --dry_run to check chunking logic quickly.
  2. Test on a small sample file with --verbose to observe:
    • Context blending between chunks
    • Output statistics
  3. Only then run on larger inputs.

Let me know if you'd like this tailored further toward users, developers, or integration into a larger documentation system.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cerebrate_file-1.0.30.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cerebrate_file-1.0.30-py3-none-any.whl (57.8 kB view details)

Uploaded Python 3

File details

Details for the file cerebrate_file-1.0.30.tar.gz.

File metadata

  • Download URL: cerebrate_file-1.0.30.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for cerebrate_file-1.0.30.tar.gz
Algorithm Hash digest
SHA256 1b5750a1e84658f86a4e94391573681064f6e02ba3d71dba7ccbab3d2f8e1638
MD5 b220f710854bf476c11382474036808c
BLAKE2b-256 46c6bceb2864384508c26778259374a5ddbbc33e99d52eb61b65f35316705b5a

See more details on using hashes here.

File details

Details for the file cerebrate_file-1.0.30-py3-none-any.whl.

File metadata

File hashes

Hashes for cerebrate_file-1.0.30-py3-none-any.whl
Algorithm Hash digest
SHA256 44ad8f1dd06c0745e805b6e22bcffe10a22fb1aa1bea89e259bf8caad9fa0c19
MD5 7d10e294e6a65771dee78e7b502af5c0
BLAKE2b-256 85c44b73290b4b24f195b1a54688eb946023221c11587038cdbb1bf182c7e214

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page