node-red-contrib-ollama 0.1.10 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,6 +10,8 @@ A Node-RED module that wraps the [ollama.js](https://github.com/ollama/ollama-js
10
10
 
11
11
  ## Requirements
12
12
 
13
+ This module requires Node.js version 18 or higher.
14
+
13
15
  To use it, you need to have Node-RED installed on your system. For more information on how to install Node-RED, refer to the official [Node-RED documentation](https://nodered.org/docs/getting-started/).
14
16
 
15
17
  You also need Ollama running on the same or a different system. For detailed instructions on how to install Ollama, please refer to the official [Ollama site](https://ollama.com/).
@@ -46,12 +48,14 @@ The module provides a set of nodes that can be used to interact with the ollama.
46
48
  - **Copy**: Copy a model. Creates a model with another name from an existing model.
47
49
  - **Create**: Create a model from a [Modelfile](https://github.com/ollama/ollama/blob/main/docs/modelfile.md).
48
50
  - **Delete**: Delete a model and its data.
49
- - **Embeddings**: Generate embeddings from a model.
51
+ - **Embed**: Generate embeddings from a model.
50
52
  - **Generate**: Generate a response for a given prompt with a provided model.
51
53
  - **List**: List models that are available locally.
52
54
  - **Pull**: Download a model from the [ollama library](https://ollama.com/library).
53
55
  - **Push**: Upload a model to a model library. Requires registering for ollama.ai and adding a public key first.
54
56
  - **Show**: Show information about a model including details, modelfile, template, parameters, license, and system prompt.
57
+ - **Ps**: List models that are currently loaded into memory.
58
+ - **Abort**: This method will abort all streamed generations currently running.
55
59
 
56
60
  Each node has its own set of configuration options that can be used to customize its behavior. For more information on how to use each node, refer to the help text provided in the Node-RED editor.
57
61
 
@@ -0,0 +1,53 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType( 'ollama-abort', {
3
+ category: 'AI',
4
+ color: 'rgb(186 230 253)',
5
+ defaults: {
6
+ name: { value: 'Ollama Abort' },
7
+ server: { value: '', type: 'ollama-config-server', required: false }
8
+ },
9
+ inputs: 1,
10
+ outputs: 1,
11
+ icon: 'ollama.png',
12
+ label: function() {
13
+ return this.name || 'ollama-abort';
14
+ },
15
+ } )
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="ollama-abort">
19
+ <div class="form-row">
20
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
21
+ <input type="text" id="node-input-name" placeholder="Name" />
22
+ </div>
23
+
24
+ <div class="form-row">
25
+ <label for="node-input-server"><i class="fa fa-server"></i> Server</label>
26
+ <input type="text" id="node-input-server" />
27
+ </div>
28
+ </script>
29
+
30
+ <script type="text/html" data-help-name="ollama-abort">
31
+ <p>This method will abort all streamed generations currently running. All asynchronous threads listening to streams (typically the for await (const part of response)) will throw an AbortError exception.</p>
32
+
33
+ <h3>Inputs</h3>
34
+
35
+ <dl class="message-properties">
36
+ <dt class="optional">
37
+ payload <span class="property-type">object</span>
38
+ </dt>
39
+ <dd>
40
+ The payload object.
41
+
42
+ <dl class="message-properties">
43
+ <dt class="optional">
44
+ payload.host <span class="property-type">string</span>
45
+ </dt>
46
+ <dd>
47
+ The host of the Ollama instance.<br />
48
+ <em>Alternative to the <code>Server</code> field.</em>
49
+ </dd>
50
+ </dl>
51
+ </dd>
52
+ </dl>
53
+ </script>
@@ -0,0 +1,30 @@
1
+ module.exports = function( RED ) {
2
+ const { Ollama } = require( 'ollama' )
3
+
4
+ function OllamaAbortNode( config ) {
5
+ RED.nodes.createNode( this, config )
6
+ const node = this
7
+
8
+ node.on( 'input', async function( msg ) {
9
+ const {
10
+ host: payloadHost
11
+ } = msg.payload
12
+
13
+ const server = RED.nodes.getNode( config.server )
14
+
15
+ const host = ( server ) ? server.host + ':' + server.port : payloadHost
16
+
17
+ const ollama = new Ollama( { host } )
18
+
19
+ const response = await ollama.abort()
20
+ .catch( error => {
21
+ node.error( error )
22
+ } )
23
+
24
+ msg.payload = response
25
+ node.send( msg )
26
+ } )
27
+ }
28
+
29
+ RED.nodes.registerType( 'ollama-abort', OllamaAbortNode )
30
+ }
@@ -3,7 +3,8 @@
3
3
  category: 'AI',
4
4
  color: 'rgb(186 230 253)',
5
5
  defaults: {
6
- name: { value: '' }
6
+ name: { value: 'Ollama Chat' },
7
+ server: { value: '', type: 'ollama-config-server', required: false }
7
8
  },
8
9
  inputs: 1,
9
10
  outputs: 1,
@@ -17,7 +18,12 @@
17
18
  <script type="text/html" data-template-name="ollama-chat">
18
19
  <div class="form-row">
19
20
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
20
- <input type="text" id="node-input-name" placeholder="Name" />
21
+ <input type="text" id="node-input-name" placeholder="Node Name" />
22
+ </div>
23
+
24
+ <div class="form-row">
25
+ <label for="node-input-server"><i class="fa fa-server"></i> Server</label>
26
+ <input type="text" id="node-input-server" />
21
27
  </div>
22
28
  </script>
23
29
 
@@ -27,277 +33,232 @@
27
33
  <h3>Inputs</h3>
28
34
 
29
35
  <dl class="message-properties">
30
- <dt>
31
- payload.host
32
-
33
- <span class="property-type">string</span>
34
- </dt>
35
- <dd>The host of the Ollama instance.</dd>
36
-
37
- <dt>
38
- payload.model
39
-
40
- <span class="property-type">string</span>
41
- </dt>
42
- <dd>The model to use for generating the next message.</dd>
43
-
44
- <dt>
45
- payload.messages
46
-
47
- <span class="property-type">array</span>
48
- </dt>
49
- <dd>
50
- The chat history to use for generating the next message.<br />
51
-
52
- <h4>Message</h4>
53
- <dl class="message-properties">
54
- <dt>
55
- role
56
-
57
- <span class="property-type">string</span>
58
- </dt>
59
- <dd>The role of the message sender ('user', 'system', or 'assistant').</dd>
60
-
61
- <dt>
62
- content
63
-
64
- <span class="property-type">string</span>
65
- </dt>
66
- <dd>The content of the message.</dd>
67
-
68
- <dt>
69
- images
70
-
71
- <span class="property-type">array</span>
72
- </dt>
73
- <dd>The images attached to the message, either as Uint8Array or base64 encoded strings.</dd>
74
- </dl>
75
- </dd>
76
-
77
- <dt class="optional">
78
- payload.format
79
-
80
- <span class="property-type">string</span>
81
- </dt>
82
- <dd>The format of the response (only <code>json</code> for now).</dd>
83
-
84
- <dt class="optional">
85
- payload.stream
86
-
87
- <span class="property-type">boolean</span>
88
- </dt>
89
- <dd>When true an AsyncGenerator is returned.</dd>
90
-
91
36
  <dt class="optional">
92
- payload.keep_alive
93
-
94
- <span class="property-type">string | number</span>
37
+ payload <span class="property-type">object</span>
95
38
  </dt>
96
- <dd>How long to keep the model loaded.</dd>
97
39
 
98
- <dt class="optional">
99
- payload.options
100
-
101
- <span class="property-type">object</span>
102
- </dt>
103
40
  <dd>
104
- Options to configure the runtime.<br />
41
+ The payload object.
105
42
 
106
- <h4>Options</h4>
107
43
  <dl class="message-properties">
108
- <dt>
109
- numa
110
-
111
- <span class="property-type">boolean</span>
44
+ <dt class="optional">
45
+ payload.host <span class="property-type">string</span>
112
46
  </dt>
113
- <dd>Use NUMA for the runtime.</dd>
47
+ <dd>
48
+ The host of the Ollama instance.<br />
49
+ <em>Alternative to the <code>Server</code> field.</em>
50
+ </dd>
114
51
 
115
52
  <dt>
116
- num_ctx
117
-
118
- <span class="property-type">number</span>
53
+ payload.model <span class="property-type">string</span>
119
54
  </dt>
120
- <dd>The number of contexts to use.</dd>
55
+ <dd>The model to use for generating the next message.</dd>
121
56
 
122
57
  <dt>
123
- num_batch
124
-
125
- <span class="property-type">number</span>
58
+ payload.messages <span class="property-type">array</span>
126
59
  </dt>
127
- <dd>The number of batches to use.</dd>
128
-
129
- <dt>
130
- main_gpu
60
+ <dd>
61
+ The chat history to use for generating the next message.<br />
131
62
 
132
- <span class="property-type">number</span>
133
- </dt>
134
- <dd>The main GPU to use.</dd>
63
+ <h4>Message</h4>
64
+ <dl class="message-properties">
65
+ <dt>
66
+ role <span class="property-type">string</span>
67
+ </dt>
68
+ <dd>The role of the message sender ('user', 'system', or 'assistant').</dd>
135
69
 
136
- <dt>
137
- low_vram
70
+ <dt>
71
+ content <span class="property-type">string</span>
72
+ </dt>
73
+ <dd>The content of the message.</dd>
138
74
 
139
- <span class="property-type">boolean</span>
140
- </dt>
141
- <dd>Use low VRAM.</dd>
75
+ <dt>
76
+ images <span class="property-type">array</span>
77
+ </dt>
78
+ <dd>The images attached to the message, either as Uint8Array or base64 encoded strings.</dd>
142
79
 
143
- <dt>
144
- f16_kv
80
+ <dt>
81
+ tool_calls <span class="property-type">array</span>
82
+ </dt>
83
+ <dd>A list of tools the model wants to use.</dd>
84
+ </dl>
85
+ </dd>
145
86
 
146
- <span class="property-type">boolean</span>
87
+ <dt class="optional">
88
+ payload.format <span class="property-type">string</span>
147
89
  </dt>
148
- <dd>Use f16 key-value.</dd>
149
-
150
- <dt>
151
- logits_all
152
-
153
- <span class="property-type">boolean</span>
154
- </dt>
155
- <dd>Return all logits.</dd>
156
-
157
- <dt>
158
- vocab_only
159
-
160
- <span class="property-type">boolean</span>
161
- </dt>
162
- <dd>Return only the vocabulary.</dd>
163
-
164
- <dt>
165
- use_nmap
166
-
167
- <span class="property-type">boolean</span>
168
- </dt>
169
- <dd>Use NMAP.</dd>
170
-
171
- <dt>
172
- use_mlock
173
-
174
- <span class="property-type">boolean</span>
175
- </dt>
176
- <dd>Use mlock.</dd>
177
-
178
- <dt>
179
- embedding_only
180
-
181
- <span class="property-type">boolean</span>
182
- </dt>
183
- <dd>Return only the embeddings.</dd>
184
-
185
- <dt>
186
- num_thread
187
-
188
- <span class="property-type">number</span>
189
- </dt>
190
- <dd>The number of threads to use.</dd>
191
-
192
- <dt>
193
- num_keep
194
-
195
- <span class="property-type">number</span>
196
- </dt>
197
- <dd>The number of models to keep.</dd>
198
-
199
- <dt>
200
- seed
201
-
202
- <span class="property-type">number</span>
203
- </dt>
204
- <dd>The seed to use.</dd>
205
-
206
- <dt>
207
- num_predict
208
-
209
- <span class="property-type">number</span>
210
- </dt>
211
- <dd>The number of predictions to use.</dd>
212
-
213
- <dt>
214
- top_k
215
-
216
- <span class="property-type">number</span>
217
- </dt>
218
- <dd>The top k to use.</dd>
219
-
220
- <dt>
221
- top_p
222
-
223
- <span class="property-type">number</span>
224
- </dt>
225
- <dd>The top p to use.</dd>
226
-
227
- <dt>
228
- typical_p
229
-
230
- <span class="property-type">number</span>
231
- </dt>
232
- <dd>The typical p to use.</dd>
233
-
234
- <dt>
235
- repeat_last_n
236
-
237
- <span class="property-type">number</span>
238
- </dt>
239
- <dd>The repeat last n to use.</dd>
240
-
241
- <dt>
242
- temperature
243
-
244
- <span class="property-type">number</span>
245
- </dt>
246
- <dd>The temperature to use.</dd>
247
-
248
- <dt>
249
- repeat_pentalty
250
-
251
- <span class="property-type">number</span>
252
- </dt>
253
- <dd>The repeat pentalty to use.</dd>
254
-
255
- <dt>
256
- presence_penalty
257
-
258
- <span class="property-type">number</span>
259
- </dt>
260
- <dd>The presence penalty to use.</dd>
261
-
262
- <dt>
263
- frequency_penalty
264
-
265
- <span class="property-type">number</span>
266
- </dt>
267
- <dd>The frequency penalty to use.</dd>
268
-
269
- <dt>
270
- mirostat
271
-
272
- <span class="property-type">boolean</span>
273
- </dt>
274
- <dd>Use mirostat.</dd>
275
-
276
- <dt>
277
- mirostat_tau
278
-
279
- <span class="property-type">number</span>
280
- </dt>
281
-
282
- <dt>
283
- mirostat_eta
284
-
285
- <span class="property-type">number</span>
286
- </dt>
287
-
288
- <dt>
289
- penalize_newline
290
-
291
- <span class="property-type">boolean</span>
292
- </dt>
293
- <dd>Penalize newline.</dd>
294
-
295
- <dt>
296
- stop
297
-
298
- <span class="property-type">array</span>
90
+ <dd>The format of the response (only <code>json</code> for now).</dd>
91
+
92
+ <dt class="optional">
93
+ payload.stream <span class="property-type">boolean</span>
299
94
  </dt>
300
- <dd>The stop to use.</dd>
95
+ <dd>When true an AsyncGenerator is returned.</dd>
96
+
97
+ <dt class="optional">
98
+ payload.keep_alive <span class="property-type">array</span>
99
+ </dt>
100
+ <dd>How long to keep the model loaded.</dd>
101
+
102
+ <dt class="optional">
103
+ payload.tools <span class="property-type">array</span>
104
+ </dt>
105
+ <dd>
106
+ Tools for the model to use if supported.<br />
107
+ Requires <code>stream</code> to be set to <code>false</code>.
108
+
109
+ <p>
110
+ For more information, see the Ollama API documentation:<br />
111
+ <a href="https://github.com/ollama/ollama/blob/main/docs/api.md#chat-request-with-tools" target="_blank">Chat request with tools</a>
112
+ </p>
113
+ </dd>
114
+
115
+ <dt class="optional">
116
+ payload.options <span class="property-type">object</span>
117
+ </dt>
118
+ <dd>
119
+ Options to configure the runtime.<br />
120
+
121
+ <h4>Options</h4>
122
+ <dl class="message-properties">
123
+ <dt>
124
+ numa <span class="property-type">boolean</span>
125
+ </dt>
126
+ <dd>Use NUMA for the runtime.</dd>
127
+
128
+ <dt>
129
+ num_ctx <span class="property-type">number</span>
130
+ </dt>
131
+ <dd>The number of contexts to use.</dd>
132
+
133
+ <dt>
134
+ num_batch <span class="property-type">number</span>
135
+ </dt>
136
+ <dd>The number of batches to use.</dd>
137
+
138
+ <dt>
139
+ main_gpu <span class="property-type">number</span>
140
+ </dt>
141
+ <dd>The main GPU to use.</dd>
142
+
143
+ <dt>
144
+ low_vram <span class="property-type">boolean</span>
145
+ </dt>
146
+ <dd>Use low VRAM.</dd>
147
+
148
+ <dt>
149
+ f16_kv <span class="property-type">boolean</span>
150
+ </dt>
151
+ <dd>Use f16 key-value.</dd>
152
+
153
+ <dt>
154
+ logits_all <span class="property-type">boolean</span>
155
+ </dt>
156
+ <dd>Return all logits.</dd>
157
+
158
+ <dt>
159
+ vocab_only <span class="property-type">boolean</span>
160
+ </dt>
161
+ <dd>Return only the vocabulary.</dd>
162
+
163
+ <dt>
164
+ use_nmap <span class="property-type">boolean</span>
165
+ </dt>
166
+ <dd>Use NMAP.</dd>
167
+
168
+ <dt>
169
+ use_mlock <span class="property-type">boolean</span>
170
+ </dt>
171
+ <dd>Use mlock.</dd>
172
+
173
+ <dt>
174
+ embedding_only <span class="property-type">boolean</span>
175
+ </dt>
176
+ <dd>Return only the embeddings.</dd>
177
+
178
+ <dt>
179
+ num_thread <span class="property-type">number</span>
180
+ </dt>
181
+ <dd>The number of threads to use.</dd>
182
+
183
+ <dt>
184
+ num_keep <span class="property-type">number</span>
185
+ </dt>
186
+ <dd>The number of models to keep.</dd>
187
+
188
+ <dt>
189
+ seed <span class="property-type">number</span>
190
+ </dt>
191
+ <dd>The seed to use.</dd>
192
+
193
+ <dt>
194
+ num_predict <span class="property-type">number</span>
195
+ </dt>
196
+ <dd>The number of predictions to use.</dd>
197
+
198
+ <dt>
199
+ top_k <span class="property-type">number</span>
200
+ </dt>
201
+ <dd>The top k to use.</dd>
202
+
203
+ <dt>
204
+ top_p <span class="property-type">number</span>
205
+ </dt>
206
+ <dd>The top p to use.</dd>
207
+
208
+ <dt>
209
+ typical_p <span class="property-type">number</span>
210
+ </dt>
211
+ <dd>The typical p to use.</dd>
212
+
213
+ <dt>
214
+ repeat_last_n <span class="property-type">number</span>
215
+ </dt>
216
+ <dd>The repeat last n to use.</dd>
217
+
218
+ <dt>
219
+ temperature <span class="property-type">number</span>
220
+ </dt>
221
+ <dd>The temperature to use.</dd>
222
+
223
+ <dt>
224
+ repeat_pentalty <span class="property-type">number</span>
225
+ </dt>
226
+ <dd>The repeat pentalty to use.</dd>
227
+
228
+ <dt>
229
+ presence_penalty <span class="property-type">number</span>
230
+ </dt>
231
+ <dd>The presence penalty to use.</dd>
232
+
233
+ <dt>
234
+ frequency_penalty <span class="property-type">number</span>
235
+ </dt>
236
+ <dd>The frequency penalty to use.</dd>
237
+
238
+ <dt>
239
+ mirostat <span class="property-type">boolean</span>
240
+ </dt>
241
+ <dd>Use mirostat.</dd>
242
+
243
+ <dt>
244
+ mirostat_tau <span class="property-type">number</span>
245
+ </dt>
246
+
247
+ <dt>
248
+ mirostat_eta <span class="property-type">number</span>
249
+ </dt>
250
+
251
+ <dt>
252
+ penalize_newline <span class="property-type">boolean</span>
253
+ </dt>
254
+ <dd>Penalize newline.</dd>
255
+
256
+ <dt>
257
+ stop <span class="property-type">array</span>
258
+ </dt>
259
+ <dd>The stop to use.</dd>
260
+ </dl>
261
+ </dd>
301
262
  </dl>
302
263
  </dd>
303
264
  </dl>
@@ -6,11 +6,32 @@ module.exports = function( RED ) {
6
6
  const node = this
7
7
 
8
8
  node.on( 'input', async function( msg ) {
9
- const { host, model, messages, format, stream, keep_alive, options } = msg.payload
9
+ const {
10
+ host: payloadHost,
11
+ model,
12
+ messages,
13
+ format,
14
+ stream,
15
+ keep_alive,
16
+ tools,
17
+ options
18
+ } = msg.payload
19
+
20
+ const server = RED.nodes.getNode( config.server )
21
+
22
+ const host = ( server ) ? server.host + ':' + server.port : payloadHost
10
23
 
11
24
  const ollama = new Ollama( { host } )
12
25
 
13
- const response = await ollama.chat( { model, messages, format, stream, keep_alive, options } )
26
+ const response = await ollama.chat( {
27
+ model,
28
+ messages,
29
+ format,
30
+ stream,
31
+ keep_alive,
32
+ tools,
33
+ options
34
+ } )
14
35
  .catch( error => {
15
36
  node.error( error )
16
37
  } )
@@ -0,0 +1,24 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType( 'ollama-config-server', {
3
+ category: 'config',
4
+ defaults: {
5
+ host: { value: 'localhost', required: true },
6
+ port: { value: 11434, required: true, validate: RED.validators.number() }
7
+ },
8
+ label: function() {
9
+ return this.host + ':' + this.port;
10
+ }
11
+ } )
12
+ </script>
13
+
14
+ <script type="text/html" data-template-name="ollama-config-server">
15
+ <div class="form-row">
16
+ <label for="node-config-input-host"><i class="fa fa-server"></i> Host</label>
17
+ <input type="text" id="node-config-input-host" placeholder="localhost" />
18
+ </div>
19
+
20
+ <div class="form-row">
21
+ <label for="node-config-input-port"><i class="fa fa-port"></i> Port</label>
22
+ <input type="text" id="node-config-input-port" placeholder="11434" />
23
+ </div>
24
+ </script>