ollama command line assistant
examples:
~/ollama_req.sh "find cat girl pics"
~/ollama_req.sh "list directory contents"
~/ollama_req.sh "popular nostr client?"
ollama_req.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | if [ "$1" == "search:web" ]; then
curl -LsH "User-Agent: Firefox/122.0" "$2&t=web" | grep -oP 'href="\Khttps:\/\/[^\"]+' | grep -vP "qwant|chrome"
exit
fi
if [ "$1" == "search:images" ]; then
curl -LsH "User-Agent: Firefox/122.0" "$2&t=images" | grep -oP 'src="\Khttps:\/\/[^\"]+'
exit
fi
prompt=$(cat <<EOF
### System:
your response should be bash command. begin your answer with COMMAND:
your commands should be complete and not contain varibles etc that are not defined
### User:
Who is the president of Gabon?
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=president+of+Gabon"
### User:
Who is Julien Chaumond?
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=Julien+Chaumond"
### User:
what is 1 + 1?
### Assistant:
COMMAND: echo "1+1" | bc
### User:
What are the latest news?
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=news"
### User:
How to make a great cheesecake?
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=Cheesecake+recipe"
### User:
what is your favorite movie? do a short answer.
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=best+movies"
### User:
Explain the concept of artificial intelligence in one sentence
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=AI+definition"
### User:
find cat pics
### Assistant:
COMMAND: ./ollama_req.sh "search:images" "https://www.qwant.com/?q=cats"
### User:
find cat girls
### Assistant:
COMMAND: ./ollama_req.sh "search:images" "https://www.qwant.com/?q=cat+girl"
### User:
search pictures of mountains
### Assistant:
COMMAND: ./ollama_req.sh "search:images" "https://www.qwant.com/?q=mountains"
### User:
search images of dogs
### Assistant:
COMMAND: ./ollama_req.sh "search:images" "https://www.qwant.com/?q=dogs"
### User:
list directory contents
### Assistant:
COMMAND: ls
### User:
find tree pics
### Assistant:
COMMAND: ./ollama_req.sh "search:images" "https://www.qwant.com/?q=trees"
### User:
send message "hello world" to nostr
### Assistant:
COMMAND: torsocks noscl publish "hello world"
### User:
send message "this is a test" to nostr
### Assistant:
COMMAND: torsocks noscl publish "this is a test"
### User:
find cat pics and show them with feh
### Assistant:
COMMAND: ~/ollama_req.sh "find cat pics" > cat_girl_pics && feh \$(cat cat_girl_pics)
### User:
find mountain pictures and show them with feh
### Assistant:
COMMAND: ~/ollama_req.sh "find mountain pictures" > mountain_pics && feh \$(cat mountain_pics)
### User:
find website address of popular nostr client
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=nostr+client" | head -n 1
### User:
find website address of english wikipedia
### Assistant:
COMMAND: ./ollama_req.sh "search:web" "https://www.qwant.com/?q=english+wikipedia" | head -n 1
### User:
$1
[EOF]
EOF
)
req_str=$(cat <<EOF
{
"prompt": "",
"model":"sauerkrautlm-una-solar-instruct.Q3_K_S:latest",
"stream": false,
"raw":true,
"options":{
"top_p":0.4,
"top_k":10,
"temperature":1,
"repeat_penalty":1.2,
"num_predict":1024
}
}
EOF
)
req_str=$(echo "$req_str" | jq --arg p "$prompt" '.prompt = $p')
str2="\n"
req_str=$(echo "${req_str//"[EOF]"/$str2}" | jq -c)
res=$(curl -sX POST http://localhost:11434/api/generate -d "$req_str" | jq -r .response)
echo "$res" >> res
cmd=$(echo "$res" | grep -oP "COMMAND: \K.+")
echo "$cmd" >> ollama_req_commands
read -rep $'Run command (y/n)\n"'"${cmd}"$'"\ny/n?' c; [ "$c" != "y" ] && exit
eval "$cmd"
|