From 601b97236a101e23558dddf76bc3cc36ac3b919d Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Sat, 7 Sep 2024 18:58:37 +0530 Subject: [PATCH] [scripts] ayo: merge llm related functionality into ayo --- scripts/.local/bin/random/,ai-summarize | 10 --- scripts/.local/bin/random/,g | 44 ---------- scripts/.local/bin/random/ayo | 112 +++++++++++++++++------- 3 files changed, 78 insertions(+), 88 deletions(-) delete mode 100755 scripts/.local/bin/random/,ai-summarize delete mode 100755 scripts/.local/bin/random/,g diff --git a/scripts/.local/bin/random/,ai-summarize b/scripts/.local/bin/random/,ai-summarize deleted file mode 100755 index a573927b..00000000 --- a/scripts/.local/bin/random/,ai-summarize +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -set -e - -chatgpt --clear-history >/dev/null -curl -Ls "$1" | readable - 2>/dev/null | - chatgpt "Summarize this article. Give a 2 line summary at the top with a point by point breakdown of the article (max 10 points). -Use markdown when necessary. Retain the relative order in which data is presented in the article. Use emojies to make it more engaging. -No need to have headers like Article summary or point by point breakdown." | - glow diff --git a/scripts/.local/bin/random/,g b/scripts/.local/bin/random/,g deleted file mode 100755 index f581a7f3..00000000 --- a/scripts/.local/bin/random/,g +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -# Using ChatGPT for various tasks - -set -e - -chatgpt -c -gptcli="chatgpt" # sgpt - -cmd="$1" -[ -z "$cmd" ] && cmd="$(echo " -summarize (summarize content of an article) -video-summary (summarize content of a video) -proofread (proofread a piece of text) -commit-message (write a commit message for the current diff) -declickbait (convert title to something less clickbaity)" | sed -e '/^$/d' | ,picker -p "Task: " | cut -d' ' -f1)" - -get_git_diff() { - if git diff --staged | grep -q .; then - git diff --staged - else - git diff - fi -} - -get_subtitle() { - filename="/tmp/,g/$(date '+%s')" - yt-dlp --write-auto-sub --skip-download "$1" -o "$filename" >/dev/null - /home/meain/.nix-profile/bin/ffmpeg -i "$filename".*.vtt "$filename.srt" >/dev/null 2>&1 - # TODO: Provide title for more context (maybe even trim out ad section using sponsorblock api) - # Adding a `tr -d '\n' was not giving useful output - sed -e '/^[0-9][0-9][0-9:,>]*/d;/^ *$/d' <"$filename.srt" | tr -d '\r' | uniq | - $gptcli "Summarize the details mentioned in the following subtitle content in bullet points" -} - - -case "$cmd" in -summarize) lynx -dump "$(pbpaste)" | chatgpt 'Summarize the following article. First write 2 or 3 lines with a quick summary. Then convert the article to major bullet points if possible and add a single emoji to represent each bullet point when useful.' ;; -commit-message) get_git_diff | $gptcli "Write a commit message header (limit to 80 chars) and a description for the following diff. The response should only contain the message and should not contain any extra markers or unnecessary quotes." ;; -declickbait) pbpaste | $gptcli "Make the following title less clickbaity, do not use quotes" ;; -video-summary) get_subtitle "$(pbpaste)" ;; -proofread) pbpaste | $gptcli "Proofread the following text for spelling grammar and readability:" ;; -*) echo "We don't do that here!" && exit 1 ;; -esac | tee /dev/stderr | pbcopy diff --git a/scripts/.local/bin/random/ayo b/scripts/.local/bin/random/ayo index 1b79bf5c..62f14ed6 100755 --- a/scripts/.local/bin/random/ayo +++ b/scripts/.local/bin/random/ayo @@ -2,41 +2,85 @@ set -e -chatgpt --clear-history >/dev/null - -if [ -n "$2" ]; then - chatgpt "$*" -else - # get the input text from stdin else ask for input - if [ -p /dev/stdin ]; then - input=$(cat) +get_git_diff() { + if git diff --staged | grep -q .; then + git diff --staged else - printf "Content: " >&2 - read -r input + git diff fi +} - echo "$input" | - case "$1" in - "professional") - chatgpt "Make this message sound more professional but not lame. This is a chat message and so no need for signing like in an email." - ;; - "lame") - chatgpt "Make this into a dead serious corporate sounding message. This is a chat message and so no need for signing like in an email." - ;; - "email") - chatgpt "Make this into a casual business email." - ;; - "summarize") - chatgpt "Can you summarize this message?" - ;; - "summary") - chatgpt "Can you summarize this message?" - ;; - "keypoints") - chatgpt "List the key points of this message." - ;; - *) - chatgpt "$1" - ;; - esac +get_youtube_subtitle() { + printf "Downloading subtitles from youtube...\r" >&2 + filename="/tmp/ayo/$(date '+%s')" + yt-dlp --write-auto-sub --skip-download "$1" -o "$filename" >/dev/null + ffmpeg -i "$filename".*.vtt "$filename.srt" >/dev/null 2>&1 + # todo: provide title for more context (maybe even trim out ad section using sponsorblock api) + # adding a `tr -d '\n' was not giving useful output + sed -e '/^[0-9][0-9][0-9:,>]*/d;/^ *$/d' <"$filename.srt" | tr -d '\r' | uniq +} + +# get the input text from stdin else ask for input +if [ -p /dev/stdin ]; then + input=$(cat) fi + +case "$1" in +professional) + echo "$input" | + aichat "Make this message sound more professional but not lame. This is a chat message and so no need for signing like in an email." + ;; +lame) + echo "$input" | + aichat "Make this into a dead serious corporate sounding message. This is a chat message and so no need for signing like in an email." + ;; +email) + echo "$input" | + aichat "Make this into a casual business email." + ;; +summarize | summary) + if [ -n "$input" ]; then + echo "$input" | + aichat "Summarize the given text." + elif [ -n "$2" ]; then + # if YouTube link then get subtitles and summarize that + if echo "$2" | grep -q youtube.com; then + get_youtube_subtitle "$2" | + aichat "Summarize the video using the subtitles provided." + else + printf "Downloading article from the web...\r" >&2 + readable "$2" 2>/dev/null | + aichat 'Summarize the given article.' + fi + fi + ;; +article-summary) + echo "$input" | + aichat "Summarize this article. Give a 2 line summary at the top with a point by point breakdown of the article (max 10 points). +Use markdown when necessary. Retain the relative order in which data is presented in the article. Use emojies to make it more engaging. +No need to have headers like Article summary or point by point breakdown." + ;; +keypoints) + echo "$input" | + aichat "List the key points of this message." + ;; +explain) + echo "$input" | + aichat "Can you explain this?" + ;; +commit-message) + get_git_diff | + aichat "Write a commit message header (limit to 80 chars) and a description for the following diff. The response should only contain the message and should not contain any extra markers or unnecessary quotes." + ;; +declickbait) + echo "$input" | + aichat "Can you make this less clickbaity?" + ;; +proofread) + echo "$input" | + aichat "Can you proofread this for spelling, grammar and readability?" + ;; +*) + aichat "$1" + ;; +esac