Skip to content

Commit

Permalink
chore: Add Tour of Cogni and basic usage to README.md
Browse files Browse the repository at this point in the history
leoshimo committed Dec 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7efd43e commit 5d27ac2
Showing 1 changed file with 82 additions and 1 deletion.
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -52,6 +52,87 @@ export OPENAI_API_KEY=sk-DEADBEEF

---

## Basic Usage

See `cogni --help` for documentation

```sh
# Via stdin
$ echo "How do I read from stdin?" | cogni

# Via file
$ echo "What is 50 + 50?" > input.txt
$ cogni input.txt
50 + 50 equals 100.


# Via flags:
# -s, --system <MSG> Sets system prompt (Always first)
# -a, --assistant <MSG> Appends assistant message
# -u, --user <MSG> Appends user message
$ cogni --system "Solve the following math problem" --user "50 + 50"
50 + 50 equals 100.

# Few-shot prompting with multiple messages
$ cogni --system "Solve the following math problem" \
-u "1 + 1" \
-a "2" \
-u "22 + 20" \
-a "42" \
-u "50 + 50"
100

# Via flags AND stdin - flag messages come before stdin / file
$ echo "50 + 50" | cogni --system "Solve the following math problem" \
-u "1 + 1" \
-a "2" \
-u "22 + 20" \
-a "42"
100
```

---

## Tour of cogni

🚧 WIP

An gallery of examples to get the inspiration flowing

### In the Shell

```sh
# Creating Summary of Meeting Transcripts
$ cat meeting_saved_chat.txt | cogni -s "Extract the links mentioned in this transcript, and provide a high level summary of the discussion points"

# Narrate Weather Summary
$ curl -s "wttr.in/?1" | cogni -s "Summarize today's weather using the output. Respond in 1 short sentence." | say

# Create a ffmpeg cheatsheet from man page
$ man ffmpeg | cogni -T 300 -s "Create a cheatsheet given a man page. Output should be in Markdown, and should be a set of example usages under headings." > cheatsheet.md
```

### In Emacs

Emacs can leverage `shell-command-on-region` to define an interactive command on region.

For example, the following defines a command that plumbs region to `cogni`, optionally replacing original contents:

```emacs-lisp
(defun leoshimo/cogni-on-region (start end prompt replace)
"Run cogni on region. Prefix arg means replace region, instead of separate output buffer"
(interactive "r\nsPrompt: \nP")
(shell-command-on-region start end
(format "cogni -s \"%s\"" prompt)
nil replace))
(global-set-key (kbd "M-c") #'leoshimo/cogni-on-region)
```

### In Vim

Vim can run external shell commands on entire buffer or visual selection. See `h :!` in vim.

This allows workflows like:
1. Select a list of fruits in visual mode
2. Type `:!cogni -s "Sort this list by color"`
3. Selection is replaces - list of fruits is sorted by color

0 comments on commit 5d27ac2

Please sign in to comment.