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

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"
Edit
Pub: 28 Jan 2024 01:07 UTC
Edit: 28 Jan 2024 03:46 UTC
Views: 40