LLM prompt/context preparation utility
Project description
contextualize
contextualize
is a package to quickly retrieve and format file contents for use with LLMs.
Installation
You can install the package using pip:
pip install contextualize
or pipx for using the CLI globally:
pipx install contextualize
Usage (reference.py
)
Define FileReference
objects for specified file paths and optional ranges.
- set
range
to a tuple of line numbers to include only a portion of the file, e.g.range=(1, 10)
- set
format
to "md" or "xml" to wrap file contents in Markdown code blocks or<file>
tags - set
label
to "relative" (default), "name", or "ext" to determine what label is affixed to the enclosing Markdown/XML string- "relative" will use the relative path from the current working directory
- "name" will use the file name only
- "ext" will use the file extension only
Retrieve wrapped contents from the output
attribute.
CLI
A CLI (cli.py
) is provided to print file contents to the console from the command line.
cat
: Prepare and concatenate file referencespaths
: Positional arguments for target file(s) or directories--ignore
: File(s) to ignore (optional)--format
: Output format (md
orxml
, default ismd
)--label
: Label style (relative
for relative file path,name
for file name only,ext
for file extension only; default isrelative
)
- Example usage:
contextualize cat README.md
will print the wrapped contents ofREADME.md
to the console with default settings (Markdown format, relative path label).contextualize cat README.md --format xml
will print the wrapped contents ofREADME.md
to the console with XML format.contextualize cat contextualize/ dev/ README.md --format xml
will prepare file references for files in thecontextualize/
anddev/
directories andREADME.md
, and print each file's contents (wrapped in corresponding XML tags) to the console.
Related projects
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
contextualize-0.0.2.tar.gz
(15.7 kB
view hashes)
Built Distribution
Close
Hashes for contextualize-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6403aae73f2f0c6987893693845703fa32c1b2a2ffd688fae5a343e0d22ddbc |
|
MD5 | 2495923dd5fac74a09aa4b1583a44f79 |
|
BLAKE2b-256 | 4b744539431772592b6933064e7fcdfdc326622714c46ca428b9224310f0fd8f |