Sgpt
SGPT is a command-line tool that provides a convenient way to interact with OpenAI models, enabling users to run queries, generate shell commands and produce code directly from the terminal.
Install / Use
/learn @tbckr/SgptQuality Score
Category
Development & EngineeringSupported Platforms
README
SGPT
SGPT (aka shell-gpt) is a powerful command-line interface (CLI) tool designed for seamless interaction with OpenAI models directly from your terminal. Effortlessly run queries, generate shell commands or code, create images from text, and more, using simple commands. Streamline your workflow and enhance productivity with this powerful and user-friendly CLI tool.
Developed with the help of SGPT.
This is a Go implementation. For the original Python implementation, visit shell-gpt. Please keep this in mind when reporting issues.
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- param::isNotitle::true:: -->- Features
- Installation
- Usage Guide
- Getting started: Obtaining an OpenAI API Key
- Querying OpenAI Models
- GPT-4o and GPT-4 Vision API Support
- o1 API Support
- OpenRouter API Support
- Chat Capabilities
- Generating and Executing Shell Commands
- Interactive Shell Sessions
- Code Generation Capabilities
- Prompt Templating
- Enhancing Your Workflow with Bash Aliases and Functions
- Acknowledgements
Features
- Instant Answers: Obtain quick and accurate responses to simple questions directly in your shell, streamlining your workflow.
- GPT-4o Integration: Access the capabilities of the GPT-4o API to generate detailed and informative responses.
- GPT-4 Vision API: Leverage the capabilities of the GPT-4 Vision API to analyze and generate insights from images.
- Shell Commands Generation: Effortlessly generate and execute shell commands, simplifying complex tasks and enhancing productivity.
- Code Production: Generate code snippets in various programming languages, making it easier to learn new languages or find solutions to coding problems.
- ChatGPT Integration: Utilize ChatGPT's interactive chat capabilities to refine your prompts and achieve more precise results, benefiting from the powerful language model.
- Bash Functions and Aliases: Seamlessly integrate SGPT responses into custom bash functions and aliases, optimizing your workflows and making your daily tasks more efficient.
- OpenRouter Support: Use OpenRouter to access various large language models (LLMs) via a single API, providing flexibility and convenience in your interactions with different models.
- Prompt Templating: Inject structured data into prompts using Go
text/templatesyntax. Pipe YAML or JSON variables via stdin to build dynamic, reusable prompt patterns.
By offering these versatile features, SGPT serves as a powerful tool to enhance your overall productivity, streamline your workflow, and simplify complex tasks.
Installation
Linux
SGPT has been tested on Ubuntu LTS releases and is expected to be compatible with the following Linux distributions:
- Debian
- Ubuntu
- Arch Linux
- Fedora
To install, download the latest release from the release page and use the package manager specific to your distribution.
macOS
For users with Homebrew as their package manager, run the following command in the terminal:
brew install tbckr/tap/sgpt
Windows
For users with Scoop as their package manager, execute these commands in PowerShell:
scoop bucket add tbckr https://github.com/tbckr/scoop-bucket.git
scoop install tbckr/sgpt
Using Go
To install SGPT with Go, based on the git tag, use this command:
go install github.com/tbckr/sgpt/v2/cmd/sgpt@latest
Docker
To run SGPT with Docker, use the following command to pull the latest image:
docker pull ghcr.io/tbckr/sgpt:latest
Examples on how to use SGPT with Docker can be found here.
Ansible
To install SGPT with Ansible, you can use the following ansible playbook as your base and adapt accordingly:
---
- hosts: all
tasks:
- name: Get latest sgpt release
uri:
url: "https://api.github.com/repos/tbckr/sgpt/releases/latest"
return_content: yes
register: sgpt_release
- name: Set latest version of sgpt
set_fact:
sgpt_latest_version: "{{ sgpt_release.json.tag_name }}"
- name: Install sgpt for debian based, amd64 systems
ansible.builtin.apt:
deb: https://github.com/tbckr/sgpt/releases/download/{{ sgpt_latest_version }}/sgpt_{{ sgpt_latest_version[1:] }}_amd64.deb
allow_unauthenticated: true
The playbook can be run with the following command:
ansible-playbook -i <inventory> <playbook>.yml
The latest version of the playbook can be found here.
Other platforms
For other platforms, visit the GitHub release page and download the latest release suitable for your system.
Usage Guide
See the documentation for detailed usage instructions.
Getting started: Obtaining an OpenAI API Key
To use the OpenAI API, you must first obtain an API key.
- Visit https://platform.openai.com/overview and sign up for an account.
- Navigate to https://platform.openai.com/account/api-keys and generate a new API key.
- On Linux or macOS: Update your
.bashrcor.zshrcfile to include the following export statement adding your API key as the value:
export OPENAI_API_KEY="sk-..."
- On Windows: Update your environment variables to
include the
OPENAI_API_KEYvariable with your API key as the value.
After completing these steps, you'll have an OpenAI API key that can be used to interact with the OpenAI models through the SGPT tool.
[!IMPORTANT] Your API key is sensitive information. Do not share it with anyone.
Querying OpenAI Models
SGPT allows you to ask simple questions and receive informative answers. For example:
$ sgpt "mass of sun"
The mass of the sun is approximately 1.989 x 10^30 kilograms.
You can also pass prompts to SGPT using pipes:
$ echo -n "mass of sun" | sgpt
The mass of the sun is approximately 1.989 x 10^30 kilograms.
You can also add another prompt to the piped data by specifying the stdin modifier and then specifying the prompt:
$ echo "Say: Hello World!" | sgpt stdin 'Replace every "World" word with "ChatGPT"'
Hello ChatGPT!
If you want to stream the completion to the command line, you can add the --stream flag. This will stream the output
to the command line as it is generated.
GPT-4o and GPT-4 Vision API Support
SGPT additionally facilitates the utilization of the GPT-4o and GPT-4 Vision API. Include input images using the -i
or --input flag, supporting both URLs and local images.
$ sgpt -m "gpt-4o" -i pkg/fs/testdata/marvin.jpg "what can you see on the picture?"
The picture shows a robot with a large, round head and an expressive, downward-slanting triangular eye. The body of the robot is designed with a sleek, somewhat shiny, metallic structure and it is pointing with its right hand. The design appears to be humanoid with distinct arms, legs, and a segmented torso.
$ sgpt -m "gpt-4-vision-preview" -i "https://upload.wikimedia.org/wikipedia/en/c/cb/Marvin_%28HHGG%29.jpg" "what can you see on the picture?"
The image shows a figure resembling a robot with a humanoid form. It has a
It is also possible to combine URLs and local images:
$ sgpt -m "gpt-4o" -i "https://upload.wikimedia.org/wikipedia/en/c/cb/Marvin_%28HHGG%29.jpg" -i pkg/fs/testdata/marvin.jpg "what is the difference between those two pictures"
The two pi
