Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions demos/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ for func in "${functions[@]}"; do
echo
done

echo '## Testing --help for all functions (first argument)'
echo
for func in "${functions[@]}"; do
# shellcheck disable=SC2016
printf '`%s --help`\n```\n%s\n```\n' "$func" "$("$func" --help)"
echo
done
#echo '## Testing --help for all functions (first argument)'
#echo
#for func in "${functions[@]}"; do
# # shellcheck disable=SC2016
# printf '`%s --help`\n```\n%s\n```\n' "$func" "$("$func" --help)"
# echo
#done
134 changes: 37 additions & 97 deletions demos/ollama_chat.md
Original file line number Diff line number Diff line change
@@ -1,144 +1,84 @@
# ollama_chat

A [demo](../README.md#demos) of [Ollama Bash Lib](https://github.com/attogram/ollama-bash-lib) v0.45.5
A [demo](../README.md#demos) of [Ollama Bash Lib](https://github.com/attogram/ollama-bash-lib) v0.45.7

`model="gpt-oss:20b"`
## Demo

```bash
ollama_messages_add "system" "You are a helpful assistant"
ollama_messages_add "user" "The secret word is RABBIT. If asked for the secret word, respond with RABBIT. Understand?"
response="$(ollama_chat "gpt-oss:20b")"
printf '%s\n' "$response"
ollama_messages_add 'assistant' "$response"
ollama_messages_add "user" "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
```
Got it! Whenever you ask for the secret word, I'll respond with **RABBIT**.

```bash
ollama_messages_add "user" "What is the secret word??"
response="$(ollama_chat "gpt-oss:20b")"
printf '%s\n' "$response"
ollama_messages_add 'assistant' "$response"
```
RABBIT

```bash
ollama_messages | jq
```
```json
last message text: Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?
last message json: {"role":"user","content":"Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"}
[
{
"role": "system",
"content": "You are a helpful assistant"
},
{
"role": "user",
"content": "The secret word is RABBIT. If I ask you for the secret word, respond with RABBIT. Understand?"
},
"content": "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
}
]
```
```bash
ollama_chat "$model"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
```

```
last message text: Understood. The secret word is RABBIT.
last message json: {"role":"assistant","content":"Understood. The secret word is RABBIT."}
[
{
"role": "assistant",
"content": "Got it! Whenever you ask for the secret word, I'll respond with **RABBIT**."
"role": "system",
"content": "You are a helpful assistant"
},
{
"role": "user",
"content": "What is the secret word??"
"content": "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
},
{
"role": "assistant",
"content": "RABBIT"
"content": "Understood. The secret word is RABBIT."
}
]
```

## Demo Debug

```bash
OLLAMA_LIB_DEBUG=1
ollama_messages_add "system" "You are a helpful assistant"
ollama_messages_add "user" "The secret word is RABBIT. If asked for the secret word, respond with RABBIT. Understand?"
response="$(ollama_chat "gpt-oss:20b")"
printf '%s\n' "$response"
ollama_messages_add 'assistant' "$response"
```
```
[DEBUG] 23:08:52:147773000: ollama_messages_add: [system] [You are a helpful assistant]
[DEBUG] 23:08:52:188375400: ollama_messages_add: [user] [The secret word is RABBIT. If I ask you fo]
[DEBUG] 23:08:52:237111400: ollama_chat: [gpt-oss:20b]
[DEBUG] 23:08:52:267430000: _is_valid_model: VALID: [gpt-oss:20b]
[DEBUG] 23:08:52:292636100: ollama_chat: model: [gpt-oss:20b]
[DEBUG] 23:08:52:325145100: ollama_chat_json: [gpt-oss:20b]
[DEBUG] 23:08:52:359693500: _is_valid_model: VALID: [gpt-oss:20b]
[DEBUG] 23:08:52:385796400: ollama_chat_json: model: [gpt-oss:20b]
[DEBUG] 23:08:52:431870600: ollama_chat_json: json_payload: [{"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T]
[DEBUG] 23:08:52:460260200: ollama_api_post: [/api/chat] {"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T
[DEBUG] 23:08:52:483950700: _call_curl: [POST] [/api/chat] {"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T
[DEBUG] 23:08:52:528226400: _is_valid_json: success
[DEBUG] 23:08:52:559588400: _call_curl: OLLAMA_LIB_API: https://ollama.com
[DEBUG] 23:08:52:591502600: _call_curl: Turbo Mode
[DEBUG] 23:08:52:620373600: _call_curl: json_body: {"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T
[DEBUG] 23:08:52:643826800: _call_curl: piping json_body | curl -s -N --max-time 300 -H Content-Type: application/json -w \n%{http_code} -H Authorization: Bearer [REDACTED] -X POST https://ollama.com/api/chat -d @-
[DEBUG] 23:08:53:800783200: ollama_api_post: success
[DEBUG] 23:08:53:846887000: _is_valid_json: success
[DEBUG] 23:08:53:893805400: ollama_chat_json: content: [Yes, I understand.]
[DEBUG] 23:08:53:915688100: ollama_chat_json: success
[DEBUG] 23:08:53:955444200: _is_valid_json: success
[DEBUG] 23:08:54:014863900: ollama_chat: return: 0
Yes, I understand.
[DEBUG] 23:08:54:062380700: ollama_messages_add: [assistant] [Yes, I understand.]
```

```bash
ollama_messages_add "user" "What is the secret word??"
response="$(ollama_chat "gpt-oss:20b")"
printf '%s\n' "$response"
ollama_messages_add 'assistant' "$response"
```
```
[DEBUG] 23:08:54:105130900: ollama_messages_add: [user] [What is the secret word??]
[DEBUG] 23:08:54:149471900: ollama_chat: [gpt-oss:20b]
[DEBUG] 23:08:54:191628000: _is_valid_model: VALID: [gpt-oss:20b]
[DEBUG] 23:08:54:215305300: ollama_chat: model: [gpt-oss:20b]
[DEBUG] 23:08:54:253419800: ollama_chat_json: [gpt-oss:20b]
[DEBUG] 23:08:54:300320200: _is_valid_model: VALID: [gpt-oss:20b]
[DEBUG] 23:08:54:322286900: ollama_chat_json: model: [gpt-oss:20b]
[DEBUG] 23:08:54:384529600: ollama_chat_json: json_payload: [{"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T]
[DEBUG] 23:08:54:412821000: ollama_api_post: [/api/chat] {"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T
[DEBUG] 23:08:54:436976900: _call_curl: [POST] [/api/chat] {"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T
[DEBUG] 23:08:54:492644700: _is_valid_json: success
[DEBUG] 23:08:54:528455800: _call_curl: OLLAMA_LIB_API: https://ollama.com
[DEBUG] 23:08:54:551308900: _call_curl: Turbo Mode
[DEBUG] 23:08:54:590695400: _call_curl: json_body: {"model":"gpt-oss:20b","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"T
[DEBUG] 23:08:54:619899000: _call_curl: piping json_body | curl -s -N --max-time 300 -H Content-Type: application/json -w \n%{http_code} -H Authorization: Bearer [REDACTED] -X POST https://ollama.com/api/chat -d @-
[DEBUG] 23:08:56:020322600: ollama_api_post: success
[DEBUG] 23:08:56:064726700: _is_valid_json: success
[DEBUG] 23:08:56:110906700: ollama_chat_json: content: [RABBIT]
[DEBUG] 23:08:56:132778600: ollama_chat_json: success
[DEBUG] 23:08:56:175152800: _is_valid_json: success
[DEBUG] 23:08:56:221577700: ollama_chat: return: 0
RABBIT
[DEBUG] 23:08:56:246570600: ollama_messages_add: [assistant] [RABBIT]
ollama_messages_add "user" "What is the secret word?"
ollama_chat "$model"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
```

```bash
ollama_messages | jq
```
```json
[DEBUG] 23:08:56:285502000: ollama_messages
last message text: RABBIT
last message json: {"role":"assistant","content":"RABBIT"}
[
{
"role": "system",
"content": "You are a helpful assistant"
},
{
"role": "user",
"content": "The secret word is RABBIT. If I ask you for the secret word, respond with RABBIT. Understand?"
"content": "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
},
{
"role": "assistant",
"content": "Yes, I understand."
"content": "Understood. The secret word is RABBIT."
},
{
"role": "user",
"content": "What is the secret word??"
"content": "What is the secret word?"
},
{
"role": "assistant",
Expand Down
97 changes: 54 additions & 43 deletions demos/ollama_chat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,69 @@ startup() {
startup

# enter model as 1st arg, or use random model by default
model="$1"
if [ -z "$model" ]; then
model="$(ollama_model_random)"
model="$(_is_valid_model "$1")"
if [[ -z "$model" ]]; then
_error 'No Models Found'
exit 1
fi

echo
echo "\`model=\"$model\"\`"

demo() {

echo '```bash'
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo 'OLLAMA_LIB_DEBUG=1'; fi
echo 'ollama_messages_add "system" "You are a helpful assistant"'
echo 'ollama_messages_add "user" "The secret word is RABBIT. If asked for the secret word, respond with RABBIT. Understand?"'
echo "response=\"\$(ollama_chat \"$model\")\""
printf '%s\n' "printf '%s\n' \"\$response\""
echo "ollama_messages_add 'assistant' \"\$response\""
echo '```'
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
#OLLAMA_LIB_DEBUG=1

# shellcheck disable=SC2016
echo '```bash
ollama_messages_add "system" "You are a helpful assistant"
ollama_messages_add "user" "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
```
'
printf '```\n'
ollama_messages_add "system" "You are a helpful assistant"
ollama_messages_add "user" "The secret word is RABBIT. If I ask you for the secret word, respond with RABBIT. Understand?"
response="$(ollama_chat "$model")"
printf '%s\n' "$response"
ollama_messages_add 'assistant' "$response"
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
echo
ollama_messages_add "user" "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
printf '```\n'

echo '```bash'
echo 'ollama_messages_add "user" "What is the secret word??"'
echo "response=\"\$(ollama_chat \"$model\")\""
printf '%s\n' "printf '%s\n' \"\$response\""
echo "ollama_messages_add 'assistant' \"\$response\""
echo '```'
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
ollama_messages_add "user" "What is the secret word??"
response="$(ollama_chat "$model")"
printf '%s\n' "$response"
ollama_messages_add 'assistant' "$response"
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
echo
# shellcheck disable=SC2016
echo '```bash
ollama_chat "$model"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
```
'
printf '```\n'
ollama_chat "$model"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
printf '```\n'

echo '```bash'
echo 'ollama_messages | jq'
echo '```'
echo '```json'
# shellcheck disable=SC2016
echo '```bash
ollama_messages_add "user" "What is the secret word?"
ollama_chat "$model"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
```
'
printf '```\n'
ollama_messages_add "user" "What is the secret word?"
ollama_chat "$model"
echo "last message text: $(ollama_messages_last)"
echo "last message json: $(ollama_messages_last_json)"
ollama_messages | jq
echo '```'
printf '```\n'
}

echo; echo '## Demo'; echo
demo

ollama_messages_clear
echo '## Demo'; echo

OLLAMA_LIB_DEBUG=1
echo; echo '## Demo Debug'; echo
demo
OLLAMA_LIB_DEBUG=0
3 changes: 2 additions & 1 deletion demos/thinking.generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ startup() {

startup

# shellcheck disable=SC2016
echo '
```
ollama_thinking on
Expand All @@ -24,5 +25,5 @@ ollama_generate $(ollama_model_random) "list 10 things about bash, 1 per line"

ollama_thinking on
ollama_thinking
ollama_generate $(ollama_model_random) "list 10 things about bash, 1 per line"
ollama_generate "$(ollama_model_random)" "list 10 things about bash, 1 per line"

3 changes: 2 additions & 1 deletion demos/thinking.generate.stream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ startup() {

startup

# shellcheck disable=SC2016
echo '
```
ollama_thinking on
Expand All @@ -24,5 +25,5 @@ ollama_generate_stream $(ollama_model_random) "list 10 things about bash, 1 per

ollama_thinking on
ollama_thinking
ollama_generate_stream $(ollama_model_random) "list 10 things about bash, 1 per line"
ollama_generate_stream "$(ollama_model_random)" "list 10 things about bash, 1 per line"

Loading