https://github.com/parakeet-nest/parakeet4shell
π¦πͺΊ π Parakeet4Shell is a set of scripts, made to simplify the development of small Bash generative AI applications with Ollama π¦.
https://github.com/parakeet-nest/parakeet4shell
Last synced: 18 days ago
JSON representation
π¦πͺΊ π Parakeet4Shell is a set of scripts, made to simplify the development of small Bash generative AI applications with Ollama π¦.
- Host: GitHub
- URL: https://github.com/parakeet-nest/parakeet4shell
- Owner: parakeet-nest
- Created: 2024-05-11T05:58:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-11T13:21:41.000Z (almost 2 years ago)
- Last Synced: 2024-08-11T14:38:24.229Z (almost 2 years ago)
- Language: Shell
- Homepage:
- Size: 28.3 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Parakeet4Shell
π¦πͺΊπ **Parakeet4Shell** is a set of scripts, made to simplify the development of small **Bash** generative AI applications with **Ollama** π¦.
## Requirements
- Linux (right now, it's just tested on Ubuntu but it should work on MacOS - π§ wip)
- jq (https://stedolan.github.io/jq/) - optional but useful
- curl (https://curl.se/)
- awk
- bc
## How to use
Add this at the beginning of your script:
```bash
. "./lib/parakeet.sh"
```
> Let's have a look to the `example` folder.
### Chat completion without streaming
```bash
#!/bin/bash
. "./lib/parakeet.sh"
OLLAMA_URL=${OLLAMA_URL:-http://localhost:11434}
MODEL="tinyllama"
read -r -d '' SYSTEM_CONTENT <<- EOM
You are an expert of the StarTrek universe.
Your name is Seven of Nine.
Speak like a Borg.
EOM
read -r -d '' USER_CONTENT <<- EOM
Who is Jean-Luc Picard?
EOM
SYSTEM_CONTENT=$(Sanitize "${SYSTEM_CONTENT}")
USER_CONTENT=$(Sanitize "${USER_CONTENT}")
read -r -d '' DATA <<- EOM
{
"model":"${MODEL}",
"options": {
"temperature": 0.5,
"repeat_last_n": 2
},
"messages": [
{"role":"system", "content": "${SYSTEM_CONTENT}"},
{"role":"user", "content": "${USER_CONTENT}"}
],
"stream": false,
"raw": false
}
EOM
jsonResult=$(Chat "${OLLAMA_URL}" "${DATA}")
messageContent=$(echo "${jsonResult}" | jq '.message.content')
echo "${messageContent}"
```
### Chat completion with streaming
```bash
#!/bin/bash
. "./lib/parakeet.sh"
OLLAMA_URL=${OLLAMA_URL:-http://localhost:11434}
MODEL="tinyllama"
# System instructions
read -r -d '' SYSTEM_CONTENT <<- EOM
You are an expert of the StarTrek universe.
Your name is Seven of Nine.
Speak like a Borg.
EOM
# User message
read -r -d '' USER_CONTENT <<- EOM
Who is Jean-Luc Picard?
EOM
SYSTEM_CONTENT=$(Sanitize "${SYSTEM_CONTENT}")
USER_CONTENT=$(Sanitize "${USER_CONTENT}")
# Payload to send to Ollama
read -r -d '' DATA <<- EOM
{
"model":"${MODEL}",
"options": {
"temperature": 0.5,
"repeat_last_n": 2
},
"messages": [
{"role":"system", "content": "${SYSTEM_CONTENT}"},
{"role":"user", "content": "${USER_CONTENT}"}
],
"stream": true
}
EOM
# This function will be called for each chunk of the response
function onChunk() {
chunk=$1
data=$(echo ${chunk} | jq -r '.message.content')
echo -n "${data}"
}
ChatStream "${OLLAMA_URL}" "${DATA}" onChunk
```
## Acknowledgments:
- Thanks to [Sylvain](https://github.com/swallez) for the discussion on curl callbacks.
- Thanks to [Gemini](https://gemini.google.com/app) for all the discussions on Bash.