|
1 | 1 | # ollama_chat |
2 | 2 |
|
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 |
4 | 4 |
|
| 5 | +`model="gpt-oss:20b"` |
5 | 6 | ## Demo |
6 | 7 |
|
7 | 8 | ```bash |
8 | 9 | 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 |
13 | 14 | ``` |
14 | | -Got it! Whenever you ask for the secret word, I'll respond with **RABBIT**. |
15 | 15 |
|
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" |
21 | 16 | ``` |
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?"} |
28 | 19 | [ |
29 | 20 | { |
30 | 21 | "role": "system", |
31 | 22 | "content": "You are a helpful assistant" |
32 | 23 | }, |
33 | 24 | { |
34 | 25 | "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 | +[ |
37 | 41 | { |
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" |
40 | 44 | }, |
41 | 45 | { |
42 | 46 | "role": "user", |
43 | | - "content": "What is the secret word??" |
| 47 | + "content": "Secret word is RABBIT. If asked for secret word, respond with RABBIT. Understand?" |
44 | 48 | }, |
45 | 49 | { |
46 | 50 | "role": "assistant", |
47 | | - "content": "RABBIT" |
| 51 | + "content": "Understood. The secret word is RABBIT." |
48 | 52 | } |
49 | 53 | ] |
50 | 54 | ``` |
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 | | - |
89 | 55 | ```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 |
119 | 61 | ``` |
120 | 62 |
|
121 | | -```bash |
122 | | -ollama_messages | jq |
123 | 63 | ``` |
124 | | -```json |
125 | | -[DEBUG] 23:08:56:285502000: ollama_messages |
| 64 | +last message text: RABBIT |
| 65 | +last message json: {"role":"assistant","content":"RABBIT"} |
126 | 66 | [ |
127 | 67 | { |
128 | 68 | "role": "system", |
129 | 69 | "content": "You are a helpful assistant" |
130 | 70 | }, |
131 | 71 | { |
132 | 72 | "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?" |
134 | 74 | }, |
135 | 75 | { |
136 | 76 | "role": "assistant", |
137 | | - "content": "Yes, I understand." |
| 77 | + "content": "Understood. The secret word is RABBIT." |
138 | 78 | }, |
139 | 79 | { |
140 | 80 | "role": "user", |
141 | | - "content": "What is the secret word??" |
| 81 | + "content": "What is the secret word?" |
142 | 82 | }, |
143 | 83 | { |
144 | 84 | "role": "assistant", |
|
0 commit comments