gpt-cli

module
v0.0.0-...-73562f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2024 License: Unlicense

README

gpt-cli

Fast, simple, and powerful GPT CLI client written in Go.

  • Uses the streaming API for realtime output.
  • Keeps chat context throughout the session.
  • Supports reading input from stdin, for integration in command pipelines.

Install

go install github.com/bduffany/gpt-cli/cmd/gpt@latest

Usage

Generate an OpenAI API key then export it as an environment variable using the following commands:

echo >> ~/.bashrc 'export OPENAI_API_KEY=YOUR_API_KEY'
exec bash

Running just gpt will give you an interactive session:

$ gpt
you> You're a sorter. I give you a list, you reply only with the sorted list.
Understood, please provide the list you would like sorted.
you> b, c, a
a, b, c

You can also pipe a single prompt to stdin and get a single reply on stdout:

$ echo >prompt.txt 'Generate TS definitions from Go structs. Just the code, no backticks:'
$ echo >api.go 'type Foo struct { Bar string `json:"bar"` }'
$ cat prompt.txt api.go | gpt | tee api.ts
interface Foo {
  bar: string;
}

Alternatively, you can provide the prompt as arguments. This will generate a single reply on stdout:

$ gpt Write the ffmpeg command to trim screenrec.mp4 from 10s to 30s. Just the command, no backticks.
ffmpeg -i screenrec.mp4 -ss 00:00:10 -to 00:00:30 -c copy output.mp4

The default system prompt is "You are a helpful assistant." You can customize it with -system:

$ gpt -system="You're a coder. No comments. No blank lines. No backticks."
you> Fisher-Yates shuffle in JS
function fisherYatesShuffle(array) {
  let m = array.length, t, i;
  while (m) {
    i = Math.floor(Math.random() * m--);
    t = array[m];
    array[m] = array[i];
    array[i] = t;
  }
  return array;
}
you>

Directories

Path Synopsis
cmd
gpt
internal
api
log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL