Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clevercli/clevercli
ChatGPT powered CLI utilities. Easily add new prompt types in ~/.clevercli/
https://github.com/clevercli/clevercli
chatgpt cli gpt gpt-3 openai
Last synced: about 1 month ago
JSON representation
ChatGPT powered CLI utilities. Easily add new prompt types in ~/.clevercli/
- Host: GitHub
- URL: https://github.com/clevercli/clevercli
- Owner: clevercli
- License: mit
- Created: 2023-03-07T23:04:25.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-03-26T17:16:56.000Z (over 1 year ago)
- Last Synced: 2024-06-19T03:11:45.461Z (3 months ago)
- Topics: chatgpt, cli, gpt, gpt-3, openai
- Language: TypeScript
- Homepage:
- Size: 585 KB
- Stars: 113
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cli-apps - clevercli - ChatGPT powered CLI utilities. Easily add new prompt types. (<a name="ai"></a>AI / ChatGPT)
- awesome-cli-apps - clevercli - Collection of ChatGPT powered utilities. (Utilities / Calendars)
- awesome-chatgpt - clevercli - ChatGPT-powered command-line utilities. (CLI tools / Examples)
- cli-apps - clevercli - ChatGPT powered CLI utilities. Easily add new prompt types. (<a name="ai"></a>AI / ChatGPT)
- fucking-awesome-cli-apps - clevercli - Collection of ChatGPT powered utilities. (Utilities / Calendars)
- awesome-chatgpt - clevercli - ChatGPT-powered command-line utilities. (CLI tools / Examples)
- jimsghstars - clevercli/clevercli - ChatGPT powered CLI utilities. Easily add new prompt types in ~/.clevercli/ (TypeScript)
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:
```console
$ $(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
```console
$ npm install -g @clevercli/cli
```Requires Node v16+.
## Usage
```console
$ clevercli
```Or using `stdin`:
```console
$ echo "" | clevercli
```List available prompt types:
```
$ clevercli --list
```Requires an [OpenAI API key](https://platform.openai.com/account/api-keys). Add `export OPENAI_API_KEY=""` to your shell script (e.g. `~/.bashrc`).
## Examples
```console
$ 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](https://github.com/charmbracelet/glow) to get a nicer rendering:
```console
$ clevercli ask "in node.js, how to check if stdin is open?" | glow
```![glow-example](./images/glow-example.png)
## Built-in prompts
- [ask](./src/prompts/ask.ts) Just passes through the input directly to ChatGPT.
Example: `clevercli ask "in node.js, how to check if stdin is open?"`
- [eli5](./src/prompts/eli5.ts): Explain Me Like I'm 5.
Example: `clevercli eli5 "why is the sky blue?"`
- [joke](./src/prompts/joke.ts): Tells a joke about the topic.
Example: `clevercli joke "git being difficult to learn"`
- [refactor](./src/prompts/refactor.ts): Asks ChatGPT to refactor code in a file.
Example: `clevercli refactor < index.ts`
- [poem](./src/prompts/poem.ts): Asks ChatGPT to write a small poem on the topic.
Example: `clevercli poem "hacker news"`
- [recipe](./src/prompts/recipe.ts): Outputs recipe suggestions given a list of available ingredients.
Example: `clevercli recipe "ham, cheese, bread"`
- [summarize](./src/prompts/summarize.ts) Outputs a short summary of the text.
Example: `clevercli summarize < README.md`
- [synonyms](./src/prompts/synonyms.ts): List synonyms for the input words.
Example: `clevercli synonyms "cat"`
- [convert-to-rust](./src/prompts/convert-to-rust.ts): Converts file to Rust
Example: `clevercli convert-to-rust < index.ts > main.rs`
- [convert-to-typescript](./src/prompts/convert-to-typescript.ts): Converts file to TypeScript
Example: `clevercli convert-to-typescript < index.js > main.ts`
- [unix-command](./src/prompts/unix-command.ts): Outputs a UNIX command based on the input description.
Example: `bash -c $(clevercli unix-command "list all .md files")`
- [regex](./src/prompts/regex.ts): Outputs a JavaScript-compatible RegEx that matches the input examples.
Example `clevercli regex "http://google.com https://news.ycombinator.com/some/path"`
- [jsdoc](./src/prompts/jsdoc.ts): Adds JSDoc comments to exported functions.
Example `clevercli jsdoc < index.js`
See [./src/prompts/](./src/prompts) for the list of available prompts.
See [Adding a built-in prompt](#adding-a-built-in-prompt) for adding an official prompt.
## Adding a prompt
Create a file `~/.clevercli/.mjs` which returns an object that follows the `PromptConfiguration` interface.
```typescript
export interface PromptConfiguration {
createPrompt(input: string): string;
model?: string;
description?: string;
}
```For example:
```javascript
// 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/](./src/prompts/). You can use the [eli5](./src/prompts/eli5.ts) prompt configuration as a base.
3. Send a pull request!
Here's a sample prompt configuration:
```typescript
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)