npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

llm-codegen

v0.1.0

Published

A CLI tool using LLMs + code library docs to generate higher-quality code.

Downloads

4

Readme

lg: a CLI tool that makes AI write better code.

Problem:

  1. You ask an LLM (ChatGPT, Mistral, Anthropic, etc) to generate code using your favorite library.
  2. 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.

Solution:

This CLI tool aims to make this process easier and faster by attempting to associate your prompt with the relevant docs.

How it works:

  1. Install this tool
  2. Download the docs to any and all libraries you want to generate code for. Put them in ~/.llm-codegen/my-lib
  3. 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.

Installation

  npm install -g llm-codegen

  # or

  pnpm add -g llm-codegen

  # or

  yarn global add llm-codegen

  # or

  bun install -g llm-codegen

Setup

  1. Run lg keys set to set your OpenAI API key.
  2. Follow the instructions below to add docs from your favorite code libraries.

Note: More LLMs will be supported soon!

Adding library documents

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."

Commands

1. lg gen list

Lists all the available generators. These are read from your ~/.llm-codegen directory.

1. lg gen <model> [prompt]

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.

1. lg keys set <model>

Configures your API key for the specified model. Only OpenAI supported currently - this will change soon.

2. lg keys list

List your key configuration.

Examples

# 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"

TODOs

  • [ ] Support multiple models
  • [ ] Add custom folder support
  • [x] Support config via env vars and CLI options
  • [x] Export as package
  • [x] Show spinner
  • [x] Stream output