diff options
-rw-r--r-- | bashrc | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -49,15 +49,23 @@ source ~/Documents/Notes/todo/todo_completion complete -o default -o nospace -F _todo t # Functions + +################################################################### +# To output in cat, just call todj. +# To enable editing the files in vim, call todj vim. +# You can use less or any other tool to display the text if you wish +################################################################### todj () { - if [[ "$1" = "-v" ]]; then - CMD=vim - else - CMD=cat - fi - $CMD $(find /home/lemon/Documents/Notes/journal -name "*$(date '+%Y-%m-%d')*") + CMD=${1:-"cat"} + $CMD $(find /home/lemon/Documents/Notes/journal -name "*$(date '+%Y-%m-%d')*") } +################################################################################################### +# This function takes two arguments as strings. The idea is to enable +# passing file data into the function, such as a csv file or some code. +# Call like this openai_data "Please optimise the following function in python" "$(</path/to/file)" +# This is supposed to be a good way to read a file's contents in bash +################################################################################################### openai_data() { if [[ $# -ne 2 ]]; then echo "Give me two params!"; return; fi @@ -73,6 +81,11 @@ openai_data() { echo $gpt | jq -r '.choices[0].message.content' } +################################################################################ +# A straight forward request to the OpenAI GPT-3 model. +# Takes a single string argument and returns a simple response. +# hey_openai "What is the best way to open and interate through a file in Perl?" +################################################################################ hey_openai() { prompt="$1" local gpt=$(curl https://api.openai.com/v1/chat/completions -s \ |