This repository has been archived on 2025-04-03. You can view files and clone it, but cannot push or open issues or pull requests.
linux-bash-scripts/openai
2024-09-04 12:13:39 +02:00
..
README.md Added openai bash integration script 2024-08-23 10:12:09 +02:00
runai.sh Fixes and improvements for runai script 2024-09-04 12:13:39 +02:00

OpenAI API / ChatGPT bash integration

The script runai_alias.sh can be used to provide the runai command in bash. The command enabled you to generate commands directly in your terminal.

Requirements

This script only requires Python 3.7+ and the openai Python package to be installed.

Install Python and Pip on Debian/Ubuntu: sudo apt install python3 python3-pip Install Python and Pip on CentOS/RHEL-based: sudo yum install epel-release && sudo yum install python3-pip Install Python and Pip on ArchLinux: sudo pacman -Sy && sudo pacman -S python-pip Install Python and Pip in Fedora: sudo dnf install python3-pip Install via pip: pip install openai

Installing as alias command

Note: To keep the alias command working, the script must remain at the same location after setting the alias command.

Install the alias command using ./runai.sh -a

Example Usage as Script

user@host:~$ ./runai.sh scan my primary local network for online hosts
The generated command is:
nmap -sn $(ip route | awk '/default/ {print $3}' | awk -F. '{print $1"."$2"."$3".0/24"}')

Do you want to execute the command? [Y/n]: y

...

You always have the choice whether the command shall be executed or not, unless you pass -y as first parameter. When the command is executed, you can also access it later using your history.

Example Usage as Alias

user@host:~$ ./runai scan my primary local network for online hosts
The generated command is:
nmap -sn $(ip route | awk '/default/ {print $3}' | awk -F. '{print $1"."$2"."$3".0/24"}')

Do you want to execute the command? [Y/n]: y

...

Example Usage with ALL_YES set

WARNING: Allowing the script to just execute the generated command can be potentially dangerous. Use with care!

user@host:~$ ./runai -a scan my primary local network for online hosts
Running the command without asking for confirmation!
Running the command:
nmap -sn $(ip route | awk '/default/ {print $3}' | awk -F. '{print $1"."$2"."$3".0/24"}')

...

NOTE that you should never provide any sensitive data with your prompt!