Skip to content

Ayubjon/llm-extract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

llm-extract

Zero-dependency CLI + library that pulls structured output out of messy LLM / markdown text:

  • files — parse fenced ``` code blocks and write them to real files, inferring the filename from hints: `**app.js**`, ```js title="app.js", ```app.js, a leading // app.js comment, or `src/path.ext` on the line before the block.
  • json — find and print the first JSON value embedded in prose or a ```json fence (balanced-brace scan + trailing-comma repair).

No API key, no network, no dependencies — just Node 18+.

Run

npx llm-extract --help
# or, from a clone:
node bin/llm-extract.js --help

Usage

# Materialize an LLM's multi-file answer into ./generated
pbpaste | llm-extract files --out ./generated

# Pull the JSON out of a chatty response
cat reply.md | llm-extract json

files writes every block that has a detectable filename (others are skipped with a note) and refuses paths that escape the output directory.

Use as a library

import { parseBlocks, extractJson } from 'llm-extract';

parseBlocks('**a.js**\n```js\nx\n```');
// [{ lang: 'js', code: 'x', filename: 'a.js' }]

extractJson('Sure! {"a": 1, "b": [1, 2,] }');
// { a: 1, b: [1, 2] }

Development

npm test   # node --test

License

MIT

Support

If this project is useful to you, you can support its development with a crypto tip — thank you!

USDT — Ethereum (ERC-20):

0xad39bdf2df0b8dd6991150fcea0a156150ed19b8

View / verify on Etherscan

Send only on the Ethereum (ERC-20) network.

About

Zero-dependency CLI + library to extract code blocks (into files) and JSON from messy LLM/markdown output.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors