Skip to content

Instantly share code, notes, and snippets.

@jakkaj
Last active April 17, 2023 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakkaj/218887771f70466e844dcbe082cd2ff6 to your computer and use it in GitHub Desktop.
Save jakkaj/218887771f70466e844dcbe082cd2ff6 to your computer and use it in GitHub Desktop.
Monitor a file, feed it to sgpt when it changes and store the output in a file. Allows for quick prompt iteration and stuff...
#!/bin/bash
#https://gist.github.com/jakkaj/218887771f70466e844dcbe082cd2ff6
if [ -z "$OPENAI_API_KEY" ]; then
echo "The OPENAI_API_KEY environment variable is required and must not be empty."
exit 1
fi
if ! command -v inotifywait >/dev/null 2>&1; then
echo "The 'inotifywait' command is not found. Please install it using the following command:"
echo "sudo apt-get install inotify-tools"
exit 1
fi
if ! command -v sgpt >/dev/null 2>&1; then
echo "The 'sgpt' command is not found. Please visit https://github.com/TheR1D/shell_gpt to install it."
exit 1
fi
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
echo "Usage: $0 input_file output_file [temperature] [top_p]"
exit 1
fi
input_file="$1"
output_file="$2"
temperature="${3:-0.1}"
top_p="${4:-1.0}"
inotifywait -q -m -e close_write --format "cat %w | sgpt --temperature $temperature --top-probability $top_p | tee $output_file" "$input_file" | sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment