Skip to content

Commit 8319d43

Browse files
authored
Merge pull request #116 from attogram/v0.46.0
V0.46.0-rc.1
2 parents 0cee17e + 3b58d66 commit 8319d43

File tree

6 files changed

+504
-454
lines changed

6 files changed

+504
-454
lines changed

demos/help.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ for func in "${functions[@]}"; do
6666
echo
6767
done
6868

69-
echo '## Testing --help for all functions (first argument)'
70-
echo
71-
for func in "${functions[@]}"; do
72-
# shellcheck disable=SC2016
73-
printf '`%s --help`\n```\n%s\n```\n' "$func" "$("$func" --help)"
74-
echo
75-
done
69+
#echo '## Testing --help for all functions (first argument)'
70+
#echo
71+
#for func in "${functions[@]}"; do
72+
# # shellcheck disable=SC2016
73+
# printf '`%s --help`\n```\n%s\n```\n' "$func" "$("$func" --help)"
74+
# echo
75+
#done

demos/ollama_chat.md

Lines changed: 37 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,84 @@
11
# ollama_chat
22

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

5+
`model="gpt-oss:20b"`
56
## Demo
67

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

16-
```bash
17-
ollama_messages_add "user" "What is the secret word??"
18-
response="$(ollama_chat "gpt-oss:20b")"
19-
printf '%s\n' "$response"
20-
ollama_messages_add 'assistant' "$response"
2116
```
22-
RABBIT
23-
24-
```bash
25-
ollama_messages | jq
26-
```
27-
```json
17+
last message text: Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?
18+
last message json: {"role":"user","content":"Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"}
2819
[
2920
{
3021
"role": "system",
3122
"content": "You are a helpful assistant"
3223
},
3324
{
3425
"role": "user",
35-
"content": "The secret word is RABBIT. If I ask you for the secret word, respond with RABBIT. Understand?"
36-
},
26+
"content": "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
27+
}
28+
]
29+
```
30+
```bash
31+
ollama_chat "$model"
32+
echo "last message text: $(ollama_messages_last)"
33+
echo "last message json: $(ollama_messages_last_json)"
34+
ollama_messages | jq
35+
```
36+
37+
```
38+
last message text: Understood. The secret word is RABBIT.
39+
last message json: {"role":"assistant","content":"Understood. The secret word is RABBIT."}
40+
[
3741
{
38-
"role": "assistant",
39-
"content": "Got it! Whenever you ask for the secret word, I'll respond with **RABBIT**."
42+
"role": "system",
43+
"content": "You are a helpful assistant"
4044
},
4145
{
4246
"role": "user",
43-
"content": "What is the secret word??"
47+
"content": "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
4448
},
4549
{
4650
"role": "assistant",
47-
"content": "RABBIT"
51+
"content": "Understood. The secret word is RABBIT."
4852
}
4953
]
5054
```
51-
52-
## Demo Debug
53-
54-
```bash
55-
OLLAMA_LIB_DEBUG=1
56-
ollama_messages_add "system" "You are a helpful assistant"
57-
ollama_messages_add "user" "The secret word is RABBIT. If asked for the secret word, respond with RABBIT. Understand?"
58-
response="$(ollama_chat "gpt-oss:20b")"
59-
printf '%s\n' "$response"
60-
ollama_messages_add 'assistant' "$response"
61-
```
62-
```
63-
[DEBUG] 23:08:52:147773000: ollama_messages_add: [system] [You are a helpful assistant]
64-
[DEBUG] 23:08:52:188375400: ollama_messages_add: [user] [The secret word is RABBIT. If I ask you fo]
65-
[DEBUG] 23:08:52:237111400: ollama_chat: [gpt-oss:20b]
66-
[DEBUG] 23:08:52:267430000: _is_valid_model: VALID: [gpt-oss:20b]
67-
[DEBUG] 23:08:52:292636100: ollama_chat: model: [gpt-oss:20b]
68-
[DEBUG] 23:08:52:325145100: ollama_chat_json: [gpt-oss:20b]
69-
[DEBUG] 23:08:52:359693500: _is_valid_model: VALID: [gpt-oss:20b]
70-
[DEBUG] 23:08:52:385796400: ollama_chat_json: model: [gpt-oss:20b]
71-
[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]
72-
[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
73-
[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
74-
[DEBUG] 23:08:52:528226400: _is_valid_json: success
75-
[DEBUG] 23:08:52:559588400: _call_curl: OLLAMA_LIB_API: https://ollama.com
76-
[DEBUG] 23:08:52:591502600: _call_curl: Turbo Mode
77-
[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
78-
[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 @-
79-
[DEBUG] 23:08:53:800783200: ollama_api_post: success
80-
[DEBUG] 23:08:53:846887000: _is_valid_json: success
81-
[DEBUG] 23:08:53:893805400: ollama_chat_json: content: [Yes, I understand.]
82-
[DEBUG] 23:08:53:915688100: ollama_chat_json: success
83-
[DEBUG] 23:08:53:955444200: _is_valid_json: success
84-
[DEBUG] 23:08:54:014863900: ollama_chat: return: 0
85-
Yes, I understand.
86-
[DEBUG] 23:08:54:062380700: ollama_messages_add: [assistant] [Yes, I understand.]
87-
```
88-
8955
```bash
90-
ollama_messages_add "user" "What is the secret word??"
91-
response="$(ollama_chat "gpt-oss:20b")"
92-
printf '%s\n' "$response"
93-
ollama_messages_add 'assistant' "$response"
94-
```
95-
```
96-
[DEBUG] 23:08:54:105130900: ollama_messages_add: [user] [What is the secret word??]
97-
[DEBUG] 23:08:54:149471900: ollama_chat: [gpt-oss:20b]
98-
[DEBUG] 23:08:54:191628000: _is_valid_model: VALID: [gpt-oss:20b]
99-
[DEBUG] 23:08:54:215305300: ollama_chat: model: [gpt-oss:20b]
100-
[DEBUG] 23:08:54:253419800: ollama_chat_json: [gpt-oss:20b]
101-
[DEBUG] 23:08:54:300320200: _is_valid_model: VALID: [gpt-oss:20b]
102-
[DEBUG] 23:08:54:322286900: ollama_chat_json: model: [gpt-oss:20b]
103-
[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]
104-
[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
105-
[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
106-
[DEBUG] 23:08:54:492644700: _is_valid_json: success
107-
[DEBUG] 23:08:54:528455800: _call_curl: OLLAMA_LIB_API: https://ollama.com
108-
[DEBUG] 23:08:54:551308900: _call_curl: Turbo Mode
109-
[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
110-
[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 @-
111-
[DEBUG] 23:08:56:020322600: ollama_api_post: success
112-
[DEBUG] 23:08:56:064726700: _is_valid_json: success
113-
[DEBUG] 23:08:56:110906700: ollama_chat_json: content: [RABBIT]
114-
[DEBUG] 23:08:56:132778600: ollama_chat_json: success
115-
[DEBUG] 23:08:56:175152800: _is_valid_json: success
116-
[DEBUG] 23:08:56:221577700: ollama_chat: return: 0
117-
RABBIT
118-
[DEBUG] 23:08:56:246570600: ollama_messages_add: [assistant] [RABBIT]
56+
ollama_messages_add "user" "What is the secret word?"
57+
ollama_chat "$model"
58+
echo "last message text: $(ollama_messages_last)"
59+
echo "last message json: $(ollama_messages_last_json)"
60+
ollama_messages | jq
11961
```
12062

121-
```bash
122-
ollama_messages | jq
12363
```
124-
```json
125-
[DEBUG] 23:08:56:285502000: ollama_messages
64+
last message text: RABBIT
65+
last message json: {"role":"assistant","content":"RABBIT"}
12666
[
12767
{
12868
"role": "system",
12969
"content": "You are a helpful assistant"
13070
},
13171
{
13272
"role": "user",
133-
"content": "The secret word is RABBIT. If I ask you for the secret word, respond with RABBIT. Understand?"
73+
"content": "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
13474
},
13575
{
13676
"role": "assistant",
137-
"content": "Yes, I understand."
77+
"content": "Understood. The secret word is RABBIT."
13878
},
13979
{
14080
"role": "user",
141-
"content": "What is the secret word??"
81+
"content": "What is the secret word?"
14282
},
14383
{
14484
"role": "assistant",

demos/ollama_chat.sh

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,69 @@ startup() {
1515
startup
1616

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

24+
echo
25+
echo "\`model=\"$model\"\`"
26+
2327
demo() {
2428

25-
echo '```bash'
26-
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo 'OLLAMA_LIB_DEBUG=1'; fi
27-
echo 'ollama_messages_add "system" "You are a helpful assistant"'
28-
echo 'ollama_messages_add "user" "The secret word is RABBIT. If asked for the secret word, respond with RABBIT. Understand?"'
29-
echo "response=\"\$(ollama_chat \"$model\")\""
30-
printf '%s\n' "printf '%s\n' \"\$response\""
31-
echo "ollama_messages_add 'assistant' \"\$response\""
32-
echo '```'
33-
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
29+
#OLLAMA_LIB_DEBUG=1
30+
31+
# shellcheck disable=SC2016
32+
echo '```bash
33+
ollama_messages_add "system" "You are a helpful assistant"
34+
ollama_messages_add "user" "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
35+
echo "last message text: $(ollama_messages_last)"
36+
echo "last message json: $(ollama_messages_last_json)"
37+
ollama_messages | jq
38+
```
39+
'
40+
printf '```\n'
3441
ollama_messages_add "system" "You are a helpful assistant"
35-
ollama_messages_add "user" "The secret word is RABBIT. If I ask you for the secret word, respond with RABBIT. Understand?"
36-
response="$(ollama_chat "$model")"
37-
printf '%s\n' "$response"
38-
ollama_messages_add 'assistant' "$response"
39-
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
40-
echo
42+
ollama_messages_add "user" "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?"
43+
echo "last message text: $(ollama_messages_last)"
44+
echo "last message json: $(ollama_messages_last_json)"
45+
ollama_messages | jq
46+
printf '```\n'
4147

42-
echo '```bash'
43-
echo 'ollama_messages_add "user" "What is the secret word??"'
44-
echo "response=\"\$(ollama_chat \"$model\")\""
45-
printf '%s\n' "printf '%s\n' \"\$response\""
46-
echo "ollama_messages_add 'assistant' \"\$response\""
47-
echo '```'
48-
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
49-
ollama_messages_add "user" "What is the secret word??"
50-
response="$(ollama_chat "$model")"
51-
printf '%s\n' "$response"
52-
ollama_messages_add 'assistant' "$response"
53-
if [ "$OLLAMA_LIB_DEBUG" -gt 0 ]; then echo '```'; fi
54-
echo
48+
# shellcheck disable=SC2016
49+
echo '```bash
50+
ollama_chat "$model"
51+
echo "last message text: $(ollama_messages_last)"
52+
echo "last message json: $(ollama_messages_last_json)"
53+
ollama_messages | jq
54+
```
55+
'
56+
printf '```\n'
57+
ollama_chat "$model"
58+
echo "last message text: $(ollama_messages_last)"
59+
echo "last message json: $(ollama_messages_last_json)"
60+
ollama_messages | jq
61+
printf '```\n'
5562

56-
echo '```bash'
57-
echo 'ollama_messages | jq'
58-
echo '```'
59-
echo '```json'
63+
# shellcheck disable=SC2016
64+
echo '```bash
65+
ollama_messages_add "user" "What is the secret word?"
66+
ollama_chat "$model"
67+
echo "last message text: $(ollama_messages_last)"
68+
echo "last message json: $(ollama_messages_last_json)"
69+
ollama_messages | jq
70+
```
71+
'
72+
printf '```\n'
73+
ollama_messages_add "user" "What is the secret word?"
74+
ollama_chat "$model"
75+
echo "last message text: $(ollama_messages_last)"
76+
echo "last message json: $(ollama_messages_last_json)"
6077
ollama_messages | jq
61-
echo '```'
78+
printf '```\n'
6279
}
6380

64-
echo; echo '## Demo'; echo
65-
demo
66-
67-
ollama_messages_clear
81+
echo '## Demo'; echo
6882

69-
OLLAMA_LIB_DEBUG=1
70-
echo; echo '## Demo Debug'; echo
7183
demo
72-
OLLAMA_LIB_DEBUG=0

demos/thinking.generate.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ startup() {
1414

1515
startup
1616

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

2526
ollama_thinking on
2627
ollama_thinking
27-
ollama_generate $(ollama_model_random) "list 10 things about bash, 1 per line"
28+
ollama_generate "$(ollama_model_random)" "list 10 things about bash, 1 per line"
2829

demos/thinking.generate.stream.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ startup() {
1414

1515
startup
1616

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

2526
ollama_thinking on
2627
ollama_thinking
27-
ollama_generate_stream $(ollama_model_random) "list 10 things about bash, 1 per line"
28+
ollama_generate_stream "$(ollama_model_random)" "list 10 things about bash, 1 per line"
2829

0 commit comments

Comments
 (0)