Basic Usage Examples

In this section, you will find examples of how to use the ai command line program.

  1. Start a new conversations:
$ ai --new Write a Go program that counts the number of lines in a file passed using command line.

  Sure, here's a short Go program that does that:

    package main

    import (
        "bufio"
        "fmt"
        "os"
    )

    func main() {
        if len(os.Args) != 2 {
            fmt.Fprintf(os.Stderr, "Usage: %s <file>\n", os.Args[0])
            os.Exit(1)
        }

    (...)
    
  In this program,  os.Args  provides command line arguments. It first checks
  whether exactly one argument (the file name) is provided. Then, it opens the
  file and counts the lines using a scanner. If any errors occur (like the
  file not existing), it reports these on the standard error output.
    
  1. Continue the last conversation:
$ ai Update the program so it also counts the number of characters.

  Certainly, I would add another variable to keep a track of the characters.
  Each time a line is read, its length in terms of characters can be easily
  added. Here's the updated code:

    package main
    
    (...)
    
  1. Append a file to your prompt:
$ ai --new --inline README.md Summarize the following document:
  1. List your conversations:
$ ai --list
• ba91b74 Summarize following document:
• 74b3901 Write a Go program that counts number of lines in a file passed ...
  1. Switch to and continue a different conversation:
$ ai --convo 74b3 "Update the program, so that it also counts words"

  Sure, here's the updated Go program that counts both the number of lines and
  words in a given file:

    package main
    
  (...)
  1. Regenerate the model’s last response:
$ ai --regenerate
  1. Edit the last prompt and regenerate the model’s response (this starts your $EDITOR or vim):
$ ai --regenerate --edit
  1. Read data from standard input, then edit a prompt in the editor before submitting it to the model:
$ git diff | ai --new --edit "Summarize following changes:"
  1. Select a different model:
$ ai --new --model gpt-3.5-turbo Tell me a joke.
  1. Delete a conversation:
$ ai --delete 9d1d510
  1. Dump the last message from the current conversation:
$ ai --show
  1. Dump the last 5 messages from a specific conversation:
$ ai --show 5 --convo 74b3901
  1. Dump all messages:
$ ai --show 0
  1. Also dump system messages and function calls:
$ ai --show-all 
  1. Dump raw responses (without any fromating):
$ ai --show --fmt raw

For a comprehensive reference of the command line interface for the ai program, please refer to the “CLI Reference” chapter.