Files
2025_Symposium/bin/run

87 lines
2.6 KiB
Bash
Executable File

#!/bin/zsh
# Primary helper script for generating output for 'tapes'.
######################### Options #########################
zparseopts -D -E -- \
-who-dis-guy=whoami \
-show-stats=showstats \
-gimme-more-reasons=reasons \
-show-history=showhistory \
-show-me-the-chillers=showchillers \
-ask-chat-gpt:=askgpt \
-output:=outputFile \
-show-hvac-characteristics=showhvac \
-copy-gpt-output:=copygpt \
-show-the-diff-yo=showdiff
######################### Helpers #########################
function boxed_quote {
gum style --foreground 212 --border double \
--align center --margin "1 2" --padding "2 4" \
"$1"
}
function spinner {
gum spin --title "$1" -- sleep "${2:-5}"
}
function getGptOutput {
local json=$1
echo "$(cat "files/$json" | jq '.["choices"][0]["message"]["content"]')"
}
function parseGpt {
local json=$1
local header=$2
local content=$(cat "files/$json" | jq '.["choices"][0]["message"]["content"]')
echo "$header\n$content" | gum format
}
function askChatGpt {
# note question needs to be json, this is generally prepared in the justfile.
local question=$1
local outputFile=$2
if [ ! -f "$outputFile" ]; then
# get ouptut from chat gpt, if file does not exists.
# this saves from calling gpt over and over when recreating tapes.
curl "https://api.openai.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
-d "$question" \
> "$outputFile"
fi
}
######################### MAIN #########################
if [ ! -z "$whoami" ]; then
boxed_quote 'Great Question!!!'
spinner "Googling..."
elif [ ! -z "$showstats" ]; then
spinner "Computing stats..."
cat files/ShowStats.md | gum format
elif [ ! -z "$reasons" ]; then
spinner "Generating reasons..." 3
echo "# More Reasons\n- Learn concepts / similarities\n- Pros vs. Cons\n" | gum format
elif [ ! -z "$showhistory" ]; then
content=$(cat files/history.json | jq '.["choices"][0]["message"]["content"]')
echo "# Hydronic History\n$content" | gum format
elif [ ! -z "$showchillers" ]; then
content="$(parseGpt "chillers.json" "# Define Chillers")"
echo $content > files/chillers.md
gum pager < files/chillers.md
elif [ ! -z "$askgpt" ]; then
local question="${askgpt[-1]}"
local file="${outputFile[-1]}"
spinner "Asking ChatGPT..."
askChatGpt $question $file
elif [ ! -z "$showhvac" ]; then
echo "$(parseGpt 'hvac.json' '# HVAC Components')" | gum format | gum pager
elif [ ! -z "$copygpt" ]; then
echo "$(getGptOutput ${copygpt[-1]})" | pbcopy
elif [ ! -z "$showdiff" ]; then
echo "$(parseGpt 'diff.json' '# Key Differences')" | gum format | gum pager
fi