- You ask an LLM (ChatGPT, Mistral, Anthropic, etc) to generate code using your favorite library.
- The LLM generates code for you, but that code is pretty out of date. The lib has changed since the LLM has indexed it.
You can remedy this by pasting relevant parts of the lib's documentation into the LLM's context (aka, one-shot or few-shot training), and get way better code.
This can become time-consuming.
This CLI tool aims to make this process easier and faster by attempting to associate your prompt with the relevant docs.
- Install this tool
- Download the docs to any and all libraries you want to generate code for. Put them in ~/.llm-codegen/my-lib
- Run the CLI tool with your prompt and the library name (e.g.,
lg gen shadcn/form "a form for capturing patient medical information"
)
Result: up-to-date code generated by the LLM.
npm install -g llm-codegen
# or
pnpm add -g llm-codegen
# or
yarn global add llm-codegen
# or
bun install -g llm-codegen
- Run
lg keys set
to set your OpenAI API key. - Follow the instructions below to add docs from your favorite code libraries.
Note: More LLMs will be supported soon!
llm-codegen
looks for library documents in ~/.llm-codegen
. Add folders named after each library you want to generate code for. Generators will be created for each document you create, using a relative path with each file extension removed.
Let's use the following folder structure below (with the great shadcn-ui library as an example). I copied these docs right from the shadcn-ui GitHub repo.
~/.llm-codegen
└── shadcn
├── accordion.mdx
├── alert-dialog.mdx
├── alert.mdx
├── aspect-ratio.mdx
├── avatar.mdx
├── badge.mdx
├── breadcrumb.mdx
├── button.mdx
...
Running lg gen list
will now list the following generator names:
shadcn/accordion
shadcn/alert-dialog
shadcn/alert
shadcn/aspect-ratio
shadcn/avatar
shadcn/badge
shadcn/breadcrumb
shadcn/button
# ...
Which you can then use to generate code e.g.:
lg gen shadcn/accordion
# or
lg gen shadcn/accordion "with headings for each US state, with content for that states' capital, population, and area."
Lists all the available generators. These are read from your ~/.llm-codegen
directory.
Generates code for the specified model. If a prompt fragment is provided, it will be used to tailor the code appropriately. See the examples for details.
Configures your API key for the specified model. Only OpenAI supported currently - this will change soon.
List your key configuration.
# No prompt fragment; will likely give you code directly from the docs.
lg gen shadcn/form
# With a prompt fragment, will treat the docs code as a starting point and tailor it to your prompt.
lg gen shadcn/form "for inputting a business address"
lg gen shadcn/form "a form for capturing patient medical information"
- Support multiple models
- Add custom folder support
- Support config via env vars and CLI options
- Export as package
- Show spinner
- Stream output