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

@clevercli/cli

v0.0.16

Published

clevercli is a CLI that queries OpenAI models (e.g. ChatGPT). New prompt types can easily be added and there is a growing list of community maintained prompts.

Downloads

24

Readme

clevercli

clevercli is a CLI that queries OpenAI models (e.g. ChatGPT). New prompt types can easily be added and there is a growing list of community maintained prompts.

Some examples:

$ $(clevercli unix-command "undo the last commit")
$ clevercli unix-command "add a collaborator to a npm package"
$ clevercli eli5 "why is the sky blue?"
$ man du | clevercli summarize
$ clevercli convert-to-rust < index.ts > main.rs
$ clevercli ask "in node.js, how to check if stdin is open?"

Install

$ npm install -g @clevercli/cli

Requires Node v16+.

Usage

$ clevercli <prompt_type> <prompt_input>

Or using stdin:

$ echo "<prompt_input>" | clevercli <prompt_type>

List available prompt types:

$ clevercli --list

Requires an OpenAI API key. Add export OPENAI_API_KEY="<your OpenAI api key>" to your shell script (e.g. ~/.bashrc).

Examples

$ clevercli joke "banana"
Why did the banana go to the doctor? Because it wasn't peeling well!
$ echo "what is stdin?" | clevercli eli5
...
$ man du | clevercli summarize
...
$ clevercli convert-to-rust < index.ts > main.rs

Tip: since many answers use markdown, you can pipe to glow to get a nicer rendering:

$ clevercli ask "in node.js, how to check if stdin is open?" | glow

glow-example

Built-in prompts

  • ask Just passes through the input directly to ChatGPT.

Example: clevercli ask "in node.js, how to check if stdin is open?"

  • eli5: Explain Me Like I'm 5.

Example: clevercli eli5 "why is the sky blue?"

  • joke: Tells a joke about the topic.

Example: clevercli joke "git being difficult to learn"

  • refactor: Asks ChatGPT to refactor code in a file.

Example: clevercli refactor < index.ts

  • poem: Asks ChatGPT to write a small poem on the topic.

Example: clevercli poem "hacker news"

  • recipe: Outputs recipe suggestions given a list of available ingredients.

Example: clevercli recipe "ham, cheese, bread"

  • summarize Outputs a short summary of the text.

Example: clevercli summarize < README.md

  • synonyms: List synonyms for the input words.

Example: clevercli synonyms "cat"

Example: clevercli convert-to-rust < index.ts > main.rs

Example: clevercli convert-to-typescript < index.js > main.ts

  • unix-command: Outputs a UNIX command based on the input description.

Example: bash -c $(clevercli unix-command "list all .md files")

  • regex: Outputs a JavaScript-compatible RegEx that matches the input examples.

Example clevercli regex "http://google.com https://news.ycombinator.com/some/path"

  • jsdoc: Adds JSDoc comments to exported functions.

Example clevercli jsdoc < index.js

See ./src/prompts/ for the list of available prompts.

See Adding a built-in prompt for adding an official prompt.

Adding a prompt

Create a file ~/.clevercli/<prompt name>.mjs which returns an object that follows the PromptConfiguration interface.

export interface PromptConfiguration {
  createPrompt(input: string): string;
  model?: string;
  description?: string;
}

For example:

// eli5.mjs
export default {
  createPrompt(input) {
    return `Provide a very detailed explanation but like I am 5 years old (ELI5) on this topic: ${input}.\n###\n`;
  },
};

Adding a built-in prompt

  1. Fork the repository.

  2. Create a new prompt configuration in ./src/prompts/. You can use the eli5 prompt configuration as a base.

  3. Send a pull request!

Here's a sample prompt configuration:

import { ParsedResponse, PromptConfiguration } from "../types.js";

const promptConfiguration: PromptConfiguration = {
  createPrompt(input: string) {
    return `Provide a very detailed explanation but like I am 5 years old (ELI5) on this topic: ${input}.\n###\n`;
  },
  parseResponse(response: string): ParsedResponse {
    return { message: response };
  },
};

export default promptConfiguration;

Cache

Query results are cached on your filesystem's cache directory.

Debugging

DEBUG="clevercli:*" clevercli eli5 "friendship"

TODO

  • [x] Streaming API.
  • [ ] Proper CLI arg parsing and options
  • [ ] GH workflow + tests
  • [ ] Support older Node.js versions?
  • [ ] Interactively prompt OpenAI API key and save to filesystem (when OPENAPI_KEY is not set)
  • [ ] Distributed cache (not just local)