Loading repository data…
Loading repository data…
tbckr / repository
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.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
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.
text/template syntax. 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.
SGPT has been tested on Ubuntu LTS releases and is expected to be compatible with the following Linux distributions:
To install, download the latest release from the release page and use the package manager specific to your distribution.
For users with Homebrew as their package manager, run the following command in the terminal:
brew install tbckr/tap/sgpt
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
To install SGPT with Go, based on the git tag, use this command:
go install github.com/tbckr/sgpt/v2/cmd/sgpt@latest
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.
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.
For other platforms, visit the GitHub release page and download the latest release suitable for your system.
See the documentation for detailed usage instructions.
To use the OpenAI API, you must first obtain an API key.
.bashrc or .zshrc file to include the following export statement adding your API
key as the value:export OPENAI_API_KEY="sk-..."
OPENAI_API_KEY variable 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.
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.
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 pictures you provided appear to be identical. There are no visible differences between them. Both show the same character in the same pose with the same lighting and background.
You can also set the default model to GPT-4o or GPT-4 Vision by setting it in the configuration file.
Important: The GPT-4o and GPT-4-vision API integration is currently in beta and may change in the future.
If you are already whitelisted for the o1 API, you can use it by specifying the model with the -m flag. You must also
provide the --stream=false flag to not stream the output as it is not supported by the o1 API (this is only necessary,
if you have provided the stream option via the config file).
Example:
$ sgpt -m "o1-preview" --stream=false "how many rs are in strawberry?"
There are three "r"s in the word "strawberry".
You can also create a bash alias to use the o1 API more easily. For example, add the following line to your .bashrc:
alias sgpt-o1="sgpt -m \"o1-preview\" --stream=false"
Then you can use the alias like this:
$ sgpt-o1 "how many rs are in strawberry?"
There are three "r"s in the word "strawberry".
Important: The o1 API does not support personas.
SGPT seamlessly integrates with the OpenRouter API, giving you access to a wide range of AI models beyond OpenAI's offerings.
Set the OpenRouter API base URL environment variable:
export OPENAI_API_BASE="https://openrouter.ai/api/v1"
Create an API key at OpenRouter and set it as your environment variable:
export OPENAI_API_KEY="your_openrouter_api_key"
Once configured, you can specify any OpenRouter-supported model with the -m flag:
$ sgpt -m "