Skip to content
/ gptcmd Public

A command line AI client for Windows/Linux/ARM written in Go using the Open-AI API

License

Notifications You must be signed in to change notification settings

MLeidel/gptcmd

Repository files navigation

gptcmd

A command line AI chat client for windows
and linux written in Go using the OpenAI API

Requires 2 Environment Variables:

GPTKEY="your OpenAI key" (required)
GPTMOD="engine model" (required)
GPTWRAP="line wrap length" (optional)
GPTTMP="temperature" (optional)

Type your prompt on the command-line.

  $> gptcmd Hello my prompt is everything I type after gptcmd ...

A log of requests is kept in file HOME/gptcmd.log
for Windows USERPROFILE/gptcmd.log

Compiled versions are offered here to use at your own risk.
The source is here as well. Install Golang and compile yourself:

  $> GOOS=linux GOARCH=386 go build gptcmd.go   # linux
  $> GOOS=windows GOARCH=386 go build gptcmd.go   # windows
  $> GOOS=linux GOARCH=arm GOARM=5 go build gptcmd.go   # raspberry pi

gptcmd, GptCLI, and gptcom are basically
go, c, and python versions of the following bash script:

#!/bin/bash

MODEL="gpt-4"

read -p "Enter prompt: " PROMPT

RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${GPTKEY}" \
  -d '{
    "model": "'"$MODEL"'",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "'"$PROMPT"'"
      }
    ]
  }')

  date
  echo "You said: ${PROMPT}"
  echo "-------"
  echo $RESPONSE | jq -r '.choices[0].message.content'

About

A command line AI client for Windows/Linux/ARM written in Go using the Open-AI API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages