node-red-contrib-ollama 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Jakub Burkiewicz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ <p align="center">
2
+ <img src="node-red-contrib-ollama-logo.png" alt="Logo">
3
+ </p>
4
+
5
+ # node-red-contrib-ollama
6
+
7
+ A Node-RED module that wraps the [ollama.js](https://github.com/ollama/ollama-js) library, offering its functionalities as configurable nodes for easy integration into flows.
8
+
9
+ ## Requirements
10
+
11
+ 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/).
12
+
13
+ Also you need to install the Ollama on the same system. For more information on how to install Ollama, refer to the official [Ollama site](https://ollama.com/).
14
+
15
+ ## Installation
16
+
17
+ To install the module, you can use the Node-RED editor or the Node-RED command-line tool.
18
+
19
+ ### Node-RED Editor
20
+
21
+ 1. Open the Node-RED editor.
22
+ 2. Click on the menu button in the top-right corner.
23
+ 3. Select "Manage palette".
24
+ 4. Go to the "Install" tab.
25
+ 5. Search for "node-red-contrib-ollama".
26
+ 6. Click on the "Install" button.
27
+
28
+ ### Node-RED Command-Line Tool
29
+
30
+ 1. Open a terminal.
31
+ 2. Run the following command:
32
+
33
+ ```bash
34
+ npm install node-red-contrib-ollama
35
+ ```
36
+
37
+ After installing the module, you need to restart Node-RED to apply the changes.
38
+
39
+ ## Usage
40
+
41
+ The module provides a set of nodes that can be used to interact with the ollama.js library. The nodes are:
42
+
43
+ - **Chat**: Generate the next message in a chat with a provided model.
44
+ - **Copy**: Copy a model. Creates a model with another name from an existing model.
45
+ - **Create**: Create a model from a [Modelfile](https://github.com/ollama/ollama/blob/main/docs/modelfile.md).
46
+ - **Delete**: Delete a model and its data.
47
+ - **Embeddings**: Generate embeddings from a model.
48
+ - **Generate**: Generate a response for a given prompt with a provided model.
49
+ - **List**: List models that are available locally.
50
+ - **Pull**: Download a model from the [ollama library](https://ollama.com/library).
51
+ - **Push**: Upload a model to a model library. Requires registering for ollama.ai and adding a public key first.
52
+ - **Show**: Show information about a model including details, modelfile, template, parameters, license, and system prompt.
53
+
54
+ 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.
55
+
56
+ ## License
57
+
58
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Binary file
@@ -0,0 +1,396 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType( 'ollama-chat', {
3
+ category: 'AI',
4
+ color: 'rgb(186 230 253)',
5
+ defaults: {
6
+ name: { value: '' }
7
+ },
8
+ inputs: 1,
9
+ outputs: 1,
10
+ icon: 'ollama.png',
11
+ label: function() {
12
+ return this.name || 'ollama-chat';
13
+ },
14
+ } )
15
+ </script>
16
+
17
+ <script type="text/html" data-template-name="ollama-chat">
18
+ <div class="form-row">
19
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
20
+ <input type="text" id="node-input-name" placeholder="Name" />
21
+ </div>
22
+ </script>
23
+
24
+ <script type="text/html" data-help-name="ollama-chat">
25
+ <p>Generate the next message in a chat with a provided model.</p>
26
+
27
+ <h3>Inputs</h3>
28
+
29
+ <dl class="message-properties">
30
+ <dt>
31
+ payload.model
32
+
33
+ <span class="property-type">string</span>
34
+ </dt>
35
+ <dd>The model to use for generating the next message.</dd>
36
+
37
+ <dt>
38
+ payload.messages
39
+
40
+ <span class="property-type">array</span>
41
+ </dt>
42
+ <dd>
43
+ The chat history to use for generating the next message.<br />
44
+
45
+ <h4>Message</h4>
46
+ <dl class="message-properties">
47
+ <dt>
48
+ role
49
+
50
+ <span class="property-type">string</span>
51
+ </dt>
52
+ <dd>The role of the message sender ('user', 'system', or 'assistant').</dd>
53
+
54
+ <dt>
55
+ content
56
+
57
+ <span class="property-type">string</span>
58
+ </dt>
59
+ <dd>The content of the message.</dd>
60
+
61
+ <dt>
62
+ images
63
+
64
+ <span class="property-type">array</span>
65
+ </dt>
66
+ <dd>The images attached to the message, either as Uint8Array or base64 encoded strings.</dd>
67
+ </dl>
68
+ </dd>
69
+
70
+ <dt class="optional">
71
+ payload.format
72
+
73
+ <span class="property-type">string</span>
74
+ </dt>
75
+ <dd>The format of the response (only <code>json</code> for now).</dd>
76
+
77
+ <dt class="optional">
78
+ payload.stream
79
+
80
+ <span class="property-type">boolean</span>
81
+ </dt>
82
+ <dd>When true an AsyncGenerator is returned.</dd>
83
+
84
+ <dt class="optional">
85
+ payload.keep_alive
86
+
87
+ <span class="property-type">string | number</span>
88
+ </dt>
89
+ <dd>How long to keep the model loaded.</dd>
90
+
91
+ <dt class="optional">
92
+ payload.options
93
+
94
+ <span class="property-type">object</span>
95
+ </dt>
96
+ <dd>
97
+ Options to configure the runtime.<br />
98
+
99
+ <h4>Options</h4>
100
+ <dl class="message-properties">
101
+ <dt>
102
+ numa
103
+
104
+ <span class="property-type">boolean</span>
105
+ </dt>
106
+ <dd>Use NUMA for the runtime.</dd>
107
+
108
+ <dt>
109
+ num_ctx
110
+
111
+ <span class="property-type">number</span>
112
+ </dt>
113
+ <dd>The number of contexts to use.</dd>
114
+
115
+ <dt>
116
+ num_batch
117
+
118
+ <span class="property-type">number</span>
119
+ </dt>
120
+ <dd>The number of batches to use.</dd>
121
+
122
+ <dt>
123
+ main_gpu
124
+
125
+ <span class="property-type">number</span>
126
+ </dt>
127
+ <dd>The main GPU to use.</dd>
128
+
129
+ <dt>
130
+ low_vram
131
+
132
+ <span class="property-type">boolean</span>
133
+ </dt>
134
+ <dd>Use low VRAM.</dd>
135
+
136
+ <dt>
137
+ f16_kv
138
+
139
+ <span class="property-type">boolean</span>
140
+ </dt>
141
+ <dd>Use f16 key-value.</dd>
142
+
143
+ <dt>
144
+ logits_all
145
+
146
+ <span class="property-type">boolean</span>
147
+ </dt>
148
+ <dd>Return all logits.</dd>
149
+
150
+ <dt>
151
+ vocab_only
152
+
153
+ <span class="property-type">boolean</span>
154
+ </dt>
155
+ <dd>Return only the vocabulary.</dd>
156
+
157
+ <dt>
158
+ use_nmap
159
+
160
+ <span class="property-type">boolean</span>
161
+ </dt>
162
+ <dd>Use NMAP.</dd>
163
+
164
+ <dt>
165
+ use_mlock
166
+
167
+ <span class="property-type">boolean</span>
168
+ </dt>
169
+ <dd>Use mlock.</dd>
170
+
171
+ <dt>
172
+ embedding_only
173
+
174
+ <span class="property-type">boolean</span>
175
+ </dt>
176
+ <dd>Return only the embeddings.</dd>
177
+
178
+ <dt>
179
+ num_thread
180
+
181
+ <span class="property-type">number</span>
182
+ </dt>
183
+ <dd>The number of threads to use.</dd>
184
+
185
+ <dt>
186
+ num_keep
187
+
188
+ <span class="property-type">number</span>
189
+ </dt>
190
+ <dd>The number of models to keep.</dd>
191
+
192
+ <dt>
193
+ seed
194
+
195
+ <span class="property-type">number</span>
196
+ </dt>
197
+ <dd>The seed to use.</dd>
198
+
199
+ <dt>
200
+ num_predict
201
+
202
+ <span class="property-type">number</span>
203
+ </dt>
204
+ <dd>The number of predictions to use.</dd>
205
+
206
+ <dt>
207
+ top_k
208
+
209
+ <span class="property-type">number</span>
210
+ </dt>
211
+ <dd>The top k to use.</dd>
212
+
213
+ <dt>
214
+ top_p
215
+
216
+ <span class="property-type">number</span>
217
+ </dt>
218
+ <dd>The top p to use.</dd>
219
+
220
+ <dt>
221
+ typical_p
222
+
223
+ <span class="property-type">number</span>
224
+ </dt>
225
+ <dd>The typical p to use.</dd>
226
+
227
+ <dt>
228
+ repeat_last_n
229
+
230
+ <span class="property-type">number</span>
231
+ </dt>
232
+ <dd>The repeat last n to use.</dd>
233
+
234
+ <dt>
235
+ temperature
236
+
237
+ <span class="property-type">number</span>
238
+ </dt>
239
+ <dd>The temperature to use.</dd>
240
+
241
+ <dt>
242
+ repeat_pentalty
243
+
244
+ <span class="property-type">number</span>
245
+ </dt>
246
+ <dd>The repeat pentalty to use.</dd>
247
+
248
+ <dt>
249
+ presence_penalty
250
+
251
+ <span class="property-type">number</span>
252
+ </dt>
253
+ <dd>The presence penalty to use.</dd>
254
+
255
+ <dt>
256
+ frequency_penalty
257
+
258
+ <span class="property-type">number</span>
259
+ </dt>
260
+ <dd>The frequency penalty to use.</dd>
261
+
262
+ <dt>
263
+ mirostat
264
+
265
+ <span class="property-type">boolean</span>
266
+ </dt>
267
+ <dd>Use mirostat.</dd>
268
+
269
+ <dt>
270
+ mirostat_tau
271
+
272
+ <span class="property-type">number</span>
273
+ </dt>
274
+
275
+ <dt>
276
+ mirostat_eta
277
+
278
+ <span class="property-type">number</span>
279
+ </dt>
280
+
281
+ <dt>
282
+ penalize_newline
283
+
284
+ <span class="property-type">boolean</span>
285
+ </dt>
286
+ <dd>Penalize newline.</dd>
287
+
288
+ <dt>
289
+ stop
290
+
291
+ <span class="property-type">array</span>
292
+ </dt>
293
+ <dd>The stop to use.</dd>
294
+ </dl>
295
+ </dd>
296
+ </dl>
297
+
298
+ <h3>Outputs</h3>
299
+
300
+ <dl class="message-properties">
301
+ <dt>
302
+ payload.model
303
+
304
+ <span class="property-type">string</span>
305
+ </dt>
306
+ <dd>The model used for generating the next message.</dd>
307
+
308
+ <dt>
309
+ payload.created_at
310
+
311
+ <span class="property-type">Date</span>
312
+ </dt>
313
+ <dd>The creation date of the message.</dd>
314
+
315
+ <dt>
316
+ payload.message
317
+
318
+ <span class="property-type">object</span>
319
+ </dt>
320
+ <dd>
321
+ The generated message.<br />
322
+
323
+ <h4>Message</h4>
324
+ <dl class="message-properties">
325
+ <dt>
326
+ role
327
+
328
+ <span class="property-type">string</span>
329
+ </dt>
330
+ <dd>The role of the message sender ('user', 'system', or 'assistant').</dd>
331
+
332
+ <dt>
333
+ content
334
+
335
+ <span class="property-type">string</span>
336
+ </dt>
337
+ <dd>The content of the message.</dd>
338
+
339
+ <dt>
340
+ images
341
+
342
+ <span class="property-type">array</span>
343
+ </dt>
344
+ <dd>The images attached to the message, either as Uint8Array or base64 encoded strings.</dd>
345
+ </dl>
346
+
347
+ <dt>
348
+ payload.done
349
+
350
+ <span class="property-type">boolean</span>
351
+ </dt>
352
+ <dd>Whether the chat is done.</dd>
353
+
354
+ <dt>
355
+ payload.total_duration
356
+
357
+ <span class="property-type">number</span>
358
+ </dt>
359
+ <dd>The total duration of the chat.</dd>
360
+
361
+ <dt>
362
+ payload.load_duration
363
+
364
+ <span class="property-type">number</span>
365
+ </dt>
366
+ <dd>The load duration of the chat.</dd>
367
+
368
+ <dt>
369
+ payload.prompt_eval_count
370
+
371
+ <span class="property-type">number</span>
372
+ </dt>
373
+ <dd>The prompt evaluation count of the chat.</dd>
374
+
375
+ <dt>
376
+ payload.prompt_eval_duration
377
+
378
+ <span class="property-type">number</span>
379
+ </dt>
380
+ <dd>The prompt evaluation duration of the chat.</dd>
381
+
382
+ <dt>
383
+ payload.event_count
384
+
385
+ <span class="property-type">number</span>
386
+ </dt>
387
+ <dd>The event count of the chat.</dd>
388
+
389
+ <dt>
390
+ payload.event_duration
391
+
392
+ <span class="property-type">number</span>
393
+ </dt>
394
+ <dd>The event duration of the chat.</dd>
395
+ </dl>
396
+ </script>
@@ -0,0 +1,23 @@
1
+ module.exports = function( RED ) {
2
+ const { Ollama } = require( 'ollama' )
3
+
4
+ function OllamaChatNode( config ) {
5
+ RED.nodes.createNode( this, config )
6
+ const node = this
7
+
8
+ node.on( 'input', async function( msg ) {
9
+ const ollama = new Ollama()
10
+ const { model, messages, format, stream, keep_alive, options } = msg.payload
11
+
12
+ const response = await ollama.chat( { model, messages, format, stream, keep_alive, options } )
13
+ .catch( error => {
14
+ node.error( error )
15
+ } )
16
+
17
+ msg.payload = response
18
+ node.send( msg )
19
+ } )
20
+ }
21
+
22
+ RED.nodes.registerType( 'ollama-chat', OllamaChatNode )
23
+ }
@@ -0,0 +1,55 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType( 'ollama-copy', {
3
+ category: 'AI',
4
+ color: 'rgb(186 230 253)',
5
+ defaults: {
6
+ name: { value: '' },
7
+ },
8
+ inputs: 1,
9
+ outputs: 1,
10
+ icon: 'ollama.png',
11
+ label: function() {
12
+ return this.name || 'ollama-copy';
13
+ },
14
+ } )
15
+ </script>
16
+
17
+ <script type="text/html" data-template-name="ollama-copy">
18
+ <div class="form-row">
19
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
20
+ <input type="text" id="node-input-name" placeholder="Name" />
21
+ </div>
22
+ </script>
23
+
24
+ <script type="text/html" data-help-name="ollama-copy">
25
+ <p>Copy a model. Creates a model with another name from an existing model.</p>
26
+
27
+ <h3>Inputs</h3>
28
+
29
+ <dl class="message-properties">
30
+ <dt>
31
+ payload.source
32
+
33
+ <span class="property-type">string</span>
34
+ </dt>
35
+ <dd>The name of the model to copy.</dd>
36
+
37
+ <dt>
38
+ payload.destination
39
+
40
+ <span class="property-type">string</span>
41
+ </dt>
42
+ <dd>The name of the new model.</dd>
43
+ </dl>
44
+
45
+ <h3>Outputs</h3>
46
+
47
+ <dl class="message-properties">
48
+ <dt>
49
+ payload.status
50
+
51
+ <span class="property-type">string</span>
52
+ </dt>
53
+ <dd>The status of the copy operation.</dd>
54
+ </dl>
55
+ </script>
@@ -0,0 +1,23 @@
1
+ module.exports = function( RED ) {
2
+ const { Ollama } = require( 'ollama' )
3
+
4
+ function OllamaCopyNode( config ) {
5
+ RED.nodes.createNode( this, config )
6
+ const node = this
7
+
8
+ node.on( 'input', async function( msg ) {
9
+ const ollama = new Ollama()
10
+ const { source, destination } = msg.payload
11
+
12
+ const response = await ollama.copy( { source, destination } )
13
+ .catch( error => {
14
+ node.error( error )
15
+ } )
16
+
17
+ msg.payload = response
18
+ node.send( msg )
19
+ } )
20
+ }
21
+
22
+ RED.nodes.registerType( 'ollama-copy', OllamaCopyNode )
23
+ }
@@ -0,0 +1,90 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType( 'ollama-create', {
3
+ category: 'AI',
4
+ color: 'rgb(186 230 253)',
5
+ defaults: {
6
+ name: { value: '' },
7
+ },
8
+ inputs: 1,
9
+ outputs: 1,
10
+ icon: 'ollama.png',
11
+ label: function() {
12
+ return this.name || 'ollama-create';
13
+ },
14
+ } )
15
+ </script>
16
+
17
+ <script type="text/html" data-template-name="ollama-create">
18
+ <div class="form-row">
19
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
20
+ <input type="text" id="node-input-name" placeholder="Name" />
21
+ </div>
22
+ </script>
23
+
24
+ <script type="text/html" data-help-name="ollama-create">
25
+ <p>Create a model from a <a href="https://github.com/ollama/ollama/blob/main/docs/modelfile.md" target="_blank">Modelfile</a>.</p>
26
+
27
+ <h3>Inputs</h3>
28
+
29
+ <dl class="message-properties">
30
+ <dt>
31
+ payload.model
32
+
33
+ <span class="property-type">string</span>
34
+ </dt>
35
+ <p>The name of the model to create.</p>
36
+
37
+ <dt class="optional">
38
+ payload.path
39
+
40
+ <span class="property-type">string</span>
41
+ </dt>
42
+ <p>The path to the Modelfile to use for creating the model.</p>
43
+
44
+ <dt class="optional">
45
+ payload.modelfile
46
+
47
+ <span class="property-type">string</span>
48
+ </dt>
49
+ <p>The content of the Modelfile to create.</p>
50
+
51
+ <dt class="optional">
52
+ payload.stream
53
+
54
+ <span class="property-type">boolean</span>
55
+ </dt>
56
+ <p>When true an AsyncGenerator is returned.</p>
57
+ </dl>
58
+
59
+ <h3>Outputs</h3>
60
+
61
+ <dl class="message-properties">
62
+ <dt>
63
+ payload.status
64
+
65
+ <span class="property-type">string</span>
66
+ </dt>
67
+ <dd>The progress status.</dd>
68
+
69
+ <dt>
70
+ payload.digest
71
+
72
+ <span class="property-type">string</span>
73
+ </dt>
74
+ <dd>The progress digest.</dd>
75
+
76
+ <dt>
77
+ payload.total
78
+
79
+ <span class="property-type">number</span>
80
+ </dt>
81
+ <dd>The total progress.</dd>
82
+
83
+ <dt>
84
+ payload.completed
85
+
86
+ <span class="property-type">number</span>
87
+ </dt>
88
+ <dd>The completed progress.</dd>
89
+ </dl>
90
+ </script>
@@ -0,0 +1,23 @@
1
+ module.exports = function( RED ) {
2
+ const { Ollama } = require( 'ollama' )
3
+
4
+ function OllamaCreateNode( config ) {
5
+ RED.nodes.createNode( this, config )
6
+ const node = this
7
+
8
+ node.on( 'input', async function( msg ) {
9
+ const ollama = new Ollama()
10
+ const { model, path, modelfile, stream } = msg.payload
11
+
12
+ const response = await ollama.create( { model, path, modelfile, stream } )
13
+ .catch( error => {
14
+ node.error( error )
15
+ } )
16
+
17
+ msg.payload = response
18
+ node.send( msg )
19
+ } )
20
+ }
21
+
22
+ RED.nodes.registerType( 'ollama-create', OllamaCreateNode )
23
+ }