Replace file paths in markdown files with the contents of the files.
Project description
md_replace
A simple command-line tool to replace file paths in markdown files with the actual file contents. This is particularly useful for managing large prompts for Large Language Models (LLMs) where you need to include code snippets or extensive documentation.
Features
- Replaces file paths enclosed in double curly braces
{{filepath}}with the content of the specified file. Supports relative paths. - Handles
.mdfiles recursively within the current directory. - Creates new files with a specified suffix to avoid overwriting originals.
- Cross-platform compatibility (Windows, Linux, macOS).
- Installable via pip.
Installation
pip install md_replace
Usage
md_replace <suffix>
<suffix>: The suffix to be appended to the new markdown files. For example, if the suffix is_replaced,example.mdwill be processed and saved asexample_replaced.md.
Example
Let's say you have a markdown file prompt.md with the following content:
My prompt:
{{code.py}}
More text...
{{docs/design.md}}
Running md_replace _processed will create a new file prompt_processed.md where the file paths are replaced with the contents of code.py and docs/design.md.
Motivation and Comparison with Jinja2
This tool was created to streamline the process of managing long prompts for LLMs, specifically focusing on directly embedding file content into markdown files. While Jinja2 provides powerful templating capabilities, it often introduces complexities that are not necessary for this specific use case. md_replace prioritizes simplicity and ease of use, targeting the direct replacement of file paths with content without requiring familiarity with templating engines. Furthermore, using Jinja2 would require loading the entire files into memory to render the template whereas md_replace opens and processes the files individually, making it more memory-efficient for extremely large files.
md_replace
Markdownファイル内のファイルパスを実際のファイル内容に置換するシンプルなコマンドラインツールです。 これは、コードスニペットや大規模なドキュメントを含める必要のある大規模言語モデル(LLM)のプロンプトを管理するのに特に役立ちます。
機能
- ダブルカーリーブレース
{{ファイルパス}}で囲まれたファイルパスを、指定されたファイルの内容に置き換えます。相対パスをサポートします。 - 現在のディレクトリ内の
.mdファイルを再帰的に処理します。 - 元のファイルを上書きしないように、指定されたサフィックスで新しいファイルを作成します。
- クロスプラットフォーム互換性(Windows、Linux、macOS)。
- pip 経由でインストールできます。
インストール
pip install md_replace
使い方
md_replace <サフィックス>
<サフィックス>: 新しいMarkdownファイルに追加されるサフィックスです。たとえば、サフィックスが_replacedの場合、example.mdは処理され、example_replaced.mdとして保存されます。
例
prompt.md というMarkdownファイルに次の内容があるとします。
私のプロンプト:
{{code.py}}
さらにテキスト...
{{docs/design.md}}
md_replace _processed を実行すると、code.py と docs/design.md の内容でファイルパスが置き換えられた新しいファイル prompt_processed.md が作成されます。
Jinja2との比較と動機
このツールは、LLMの長いプロンプトを管理するプロセスを合理化するために作成されました。特に、ファイルの内容をMarkdownファイルに直接埋め込むことに焦点を当てています。Jinja2は強力なテンプレート機能を提供しますが、この特定のユースケースには必要のない複雑さを伴うことがよくあります。 md_replace はシンプルさと使いやすさを優先し、テンプレートエンジンに精通していなくても、ファイルパスをコンテンツに直接置き換えることを目的としています。 さらに、Jinja2 を使用するには、テンプレートをレンダリングするためにファイル全体をメモリにロードする必要がありますが、md_replace はファイルを個別に開いて処理するため、非常に大きなファイルに対してメモリ効率が高くなります。
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md_replace-1.0.1.tar.gz.
File metadata
- Download URL: md_replace-1.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7775185901fa4673d4c082c8bc506f8a10a0e5ef3efff2f76bc6b03c20de4c4c
|
|
| MD5 |
0e316812d79b81894972740ddbeb5863
|
|
| BLAKE2b-256 |
d24d8513c366dd578f97588fc6af7be43e3229eca9a547506af5d0b80a8b08c5
|
File details
Details for the file md_replace-1.0.1-py3-none-any.whl.
File metadata
- Download URL: md_replace-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0e3f0bdd12dbfe3cd9f3f658ee54d1573079ff8c336bcce09cb67586f44df4b
|
|
| MD5 |
27e7a3712ad2507734e8ec00814f609e
|
|
| BLAKE2b-256 |
3c0e08226e824e866a8455b097afd79e0eb14ea087ac5ea88cefa2bce6de6288
|