node-red-contrib-ollama 0.2.5 → 0.3.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.
@@ -5,7 +5,10 @@
5
5
  defaults: {
6
6
  name: { value: 'Ollama Push' },
7
7
  server: { value: '', type: 'ollama-config-server', required: false },
8
- model: { value: '', type: 'ollama-config-model', required: false },
8
+ model: { value: '', required: false },
9
+ modelType: { value: 'str', required: false },
10
+ insecure: { value: false },
11
+ stream: { value: false },
9
12
  },
10
13
  inputs: 1,
11
14
  outputs: 1,
@@ -13,6 +16,17 @@
13
16
  label: function() {
14
17
  return this.name || 'ollama-push';
15
18
  },
19
+ oneditprepare: function() {
20
+ if( !this.modelType ) {
21
+ this.modelType = 'str'
22
+ }
23
+
24
+ $( '#node-input-model' ).typedInput( {
25
+ type: 'str',
26
+ types: [ 'str', 'msg', 'flow', 'global' ],
27
+ typeField: '#node-input-modelType'
28
+ } )
29
+ }
16
30
  } )
17
31
  </script>
18
32
 
@@ -28,8 +42,19 @@
28
42
  </div>
29
43
 
30
44
  <div class="form-row">
31
- <label for="node-input-model"><i class="fa fa-bookmark"></i> Model</label>
45
+ <label for="node-input-model"><i class="fa fa-comment"></i> Model</label>
32
46
  <input type="text" id="node-input-model" />
47
+ <input type="hidden" id="node-input-modelType" />
48
+ </div>
49
+
50
+ <div class="form-row">
51
+ <label for="node-input-insecure"><i class="fa fa-lock"></i> Insecure</label>
52
+ <input type="checkbox" id="node-input-insecure" />
53
+ </div>
54
+
55
+ <div class="form-row">
56
+ <label for="node-input-stream"><i class="fa fa-cog"></i> Stream</label>
57
+ <input type="checkbox" id="node-input-stream" />
33
58
  </div>
34
59
  </script>
35
60
 
@@ -44,31 +69,26 @@
44
69
  </dt>
45
70
 
46
71
  <dd>
47
- The payload object.
72
+ The payload object is an alternative way to configure the node.<br />
73
+ Any properties in the payload object will override the node configuration.
48
74
 
49
75
  <dl class="message-properties">
50
76
  <dt class="optional">
51
77
  payload.host <span class="property-type">string</span>
52
78
  </dt>
53
- <dd>
54
- The host of the Ollama instance.<br />
55
- <em>Alternative to the <code>Server</code> field.</em>
56
- </dd>
79
+ <dd>The host of the Ollama instance.</dd>
57
80
 
58
81
  <dt class="optional">
59
82
  payload.model <span class="property-type">string</span>
60
83
  </dt>
61
- <dd>
62
- The name of the model to upload.<br />
63
- <em>Alternative to the <code>Model</code> field.</em>
64
- </dd>
84
+ <dd>The name of the model to upload.</dd>
65
85
 
66
- <dt>
86
+ <dt class="optional">
67
87
  payload.insecure <span class="property-type">boolean</span>
68
88
  </dt>
69
89
  <dd>Push to servers whose identity cannot be verified.</dd>
70
90
 
71
- <dt>
91
+ <dt class="optional">
72
92
  payload.stream <span class="property-type">boolean</span>
73
93
  </dt>
74
94
  <dd>When true an AsyncGenerator is returned.</dd>
@@ -3,23 +3,36 @@ module.exports = function( RED ) {
3
3
 
4
4
  function OllamaPushNode( config ) {
5
5
  RED.nodes.createNode( this, config )
6
- const node = this
7
6
 
8
- node.on( 'input', async function( msg ) {
9
- const {
10
- host: payloadHost,
11
- model: payloadModel,
12
- insecure,
13
- stream
14
- } = msg.payload
7
+ this.modelType = config.modelType || 'str'
8
+ this.insecure = config.insecure || false
9
+ this.stream = config.stream || false
15
10
 
11
+ const node = this
12
+ node.on( 'input', async function( msg ) {
16
13
  const server = RED.nodes.getNode( config.server )
17
- const host = ( server ) ? server.host + ':' + server.port : payloadHost
14
+ const host = msg?.payload?.host || ( server ) ? server.host + ':' + server.port : null
18
15
 
19
16
  const ollama = new Ollama( { host } )
20
17
 
21
- const modelConfig = RED.nodes.getNode( config.model )
22
- const model = ( modelConfig ) ? modelConfig.name : payloadModel
18
+ let model = null
19
+ if( msg?.payload?.model ) {
20
+ model = msg?.payload?.model
21
+ } else if( !!config.model ) {
22
+ if( node.modelType === 'str' ) {
23
+ model = config.model
24
+ } else if( node.modelType === 'msg' ) {
25
+ model = msg[ config.model ]
26
+ } else if( node.modelType === 'flow' ) {
27
+ model = node.context().flow.get( config.model )
28
+ } else if( node.modelType === 'global' ) {
29
+ model = node.context().global.get( config.model )
30
+ }
31
+ }
32
+
33
+ const insecure = ( msg?.payload?.insecure !== undefined ) ? msg?.payload?.insecure : node.insecure
34
+
35
+ const stream = ( msg?.payload?.stream !== undefined ) ? msg?.payload?.stream : node.stream
23
36
 
24
37
  const response = await ollama.push( {
25
38
  model,
@@ -5,7 +5,13 @@
5
5
  defaults: {
6
6
  name: { value: 'Ollama Show' },
7
7
  server: { value: '', type: 'ollama-config-server', required: false },
8
- model: { value: '', type: 'ollama-config-model', required: false },
8
+ model: { value: '', required: false },
9
+ modelType: { value: 'str', required: false },
10
+ system: { value: '', required: false },
11
+ systemType: { value: 'str', required: false },
12
+ template: { value: '', required: false },
13
+ templateType: { value: 'str', required: false },
14
+ options: { value: '', type: 'ollama-config-options', required: false },
9
15
  },
10
16
  inputs: 1,
11
17
  outputs: 1,
@@ -13,6 +19,37 @@
13
19
  label: function() {
14
20
  return this.name || 'ollama-show';
15
21
  },
22
+ oneditprepare: function() {
23
+ if( !this.modelType ) {
24
+ this.modelType = 'str'
25
+ }
26
+
27
+ $( '#node-input-model' ).typedInput( {
28
+ type: 'str',
29
+ types: [ 'str', 'msg', 'flow', 'global' ],
30
+ typeField: '#node-input-modelType'
31
+ } )
32
+
33
+ if( !this.systemType ) {
34
+ this.systemType = 'str'
35
+ }
36
+
37
+ $( '#node-input-system' ).typedInput( {
38
+ type: 'str',
39
+ types: [ 'str', 'msg', 'flow', 'global' ],
40
+ typeField: '#node-input-systemType'
41
+ } )
42
+
43
+ if( !this.templateType ) {
44
+ this.templateType = 'str'
45
+ }
46
+
47
+ $( '#node-input-template' ).typedInput( {
48
+ type: 'str',
49
+ types: [ 'str', 'msg', 'flow', 'global' ],
50
+ typeField: '#node-input-templateType'
51
+ } )
52
+ }
16
53
  } )
17
54
  </script>
18
55
 
@@ -28,8 +65,26 @@
28
65
  </div>
29
66
 
30
67
  <div class="form-row">
31
- <label for="node-input-model"><i class="fa fa-bookmark"></i> Model</label>
68
+ <label for="node-input-model"><i class="fa fa-comment"></i> Model</label>
32
69
  <input type="text" id="node-input-model" />
70
+ <input type="hidden" id="node-input-modelType" />
71
+ </div>
72
+
73
+ <div class="form-row">
74
+ <label for="node-input-system"><i class="fa fa-comment"></i> System</label>
75
+ <input type="text" id="node-input-system" />
76
+ <input type="hidden" id="node-input-systemType" />
77
+ </div>
78
+
79
+ <div class="form-row">
80
+ <label for="node-input-template"><i class="fa fa-comment"></i> Template</label>
81
+ <input type="text" id="node-input-template" />
82
+ <input type="hidden" id="node-input-templateType" />
83
+ </div>
84
+
85
+ <div class="form-row">
86
+ <label for="node-input-options"><i class="fa fa-cog"></i> Options</label>
87
+ <input type="text" id="node-input-options" />
33
88
  </div>
34
89
  </script>
35
90
 
@@ -44,24 +99,19 @@
44
99
  </dt>
45
100
 
46
101
  <dd>
47
- The payload object.
102
+ The payload object is an alternative way to configure the node.<br />
103
+ Any properties in the payload object will override the node configuration.
48
104
 
49
105
  <dl class="message-properties">
50
106
  <dt class="optional">
51
107
  payload.host <span class="property-type">string</span>
52
108
  </dt>
53
- <dd>
54
- The host of the Ollama instance.<br />
55
- <em>Alternative to the <code>Server</code> field.</em>
56
- </dd>
109
+ <dd>The host of the Ollama instance.</dd>
57
110
 
58
111
  <dt class="optional">
59
112
  payload.model <span class="property-type">string</span>
60
113
  </dt>
61
- <dd>
62
- The model to show information for.<br />
63
- <em>Alternative to the <code>Model</code> field.</em>
64
- </dd>
114
+ <dd>The model to show information for.</dd>
65
115
 
66
116
  <dt class="optional">
67
117
  payload.system <span class="property-type">string</span>
@@ -3,34 +3,75 @@ module.exports = function( RED ) {
3
3
 
4
4
  function OllamaShowNode( config ) {
5
5
  RED.nodes.createNode( this, config )
6
- const node = this
7
6
 
8
- node.on( 'input', async function( msg ) {
9
- const {
10
- host: payloadHost,
11
- model: payloadModel,
12
- system,
13
- template,
14
- options
15
- } = msg.payload
7
+ this.modelType = config.modelType || 'str'
8
+ this.systemType = config.systemType || 'str'
9
+ this.templateType = config.templateType || 'str'
16
10
 
11
+ const node = this
12
+ node.on( 'input', async function( msg ) {
17
13
  const server = RED.nodes.getNode( config.server )
18
- const host = ( server ) ? server.host + ':' + server.port : payloadHost
14
+ const host = msg?.payload?.host || ( server ) ? server.host + ':' + server.port : null
19
15
 
20
16
  const ollama = new Ollama( { host } )
21
17
 
22
- const modelConfig = RED.nodes.getNode( config.model )
23
- const model = ( modelConfig ) ? modelConfig.name : payloadModel
18
+ let model = null
19
+ if( msg?.payload?.model ) {
20
+ model = msg?.payload?.model
21
+ } else if( !!config.model ) {
22
+ if( node.modelType === 'str' ) {
23
+ model = config.model
24
+ } else if( node.modelType === 'msg' ) {
25
+ model = msg[ config.model ]
26
+ } else if( node.modelType === 'flow' ) {
27
+ model = node.context().flow.get( config.model )
28
+ } else if( node.modelType === 'global' ) {
29
+ model = node.context().global.get( config.model )
30
+ }
31
+ }
32
+
33
+ let system = null
34
+ if( msg?.payload?.system ) {
35
+ system = msg?.payload?.system
36
+ } else if( !!config.system ) {
37
+ if( node.systemType === 'str' ) {
38
+ system = config.system
39
+ } else if( node.systemType === 'msg' ) {
40
+ system = msg[ config.system ]
41
+ } else if( node.systemType === 'flow' ) {
42
+ system = node.context().flow.get( config.system )
43
+ } else if( node.systemType === 'global' ) {
44
+ system = node.context().global.get( config.system )
45
+ }
46
+ }
47
+
48
+ let template = null
49
+ if( msg?.payload?.template ) {
50
+ template = msg?.payload?.template
51
+ } else if( !!config.template ) {
52
+ if( node.templateType === 'str' ) {
53
+ template = config.template
54
+ } else if( node.templateType === 'msg' ) {
55
+ template = msg[ config.template ]
56
+ } else if( node.templateType === 'flow' ) {
57
+ template = node.context().flow.get( config.template )
58
+ } else if( node.templateType === 'global' ) {
59
+ template = node.context().global.get( config.template )
60
+ }
61
+ }
62
+
63
+ const optionsConfig = RED.nodes.getNode( config.options )
64
+ const options = msg?.payload?.options || ( optionsConfig ) ? JSON.parse( optionsConfig.json ) : null
24
65
 
25
66
  const response = await ollama.show( {
26
- model,
27
- system,
28
- template,
29
- options
30
- } )
31
- .catch( error => {
32
- node.error( error )
33
- } )
67
+ model,
68
+ system,
69
+ template,
70
+ options
71
+ } )
72
+ .catch( error => {
73
+ node.error( error )
74
+ } )
34
75
 
35
76
  msg.payload = response
36
77
  node.send( msg )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-ollama",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "Add AI functionality to your flows! This module includes a set of nodes that enable easy communication with Ollama, enriching your projects with intelligent solutions.",
5
5
  "keywords": [
6
6
  "ai",
@@ -30,9 +30,9 @@
30
30
  "ollama-ps": "nodes/ollama-ps.js",
31
31
  "ollama-abort": "nodes/ollama-abort.js",
32
32
  "ollama-config-server": "nodes/ollama-config-server.js",
33
- "ollama-config-model": "nodes/ollama-config-model.js",
34
33
  "ollama-config-format": "nodes/ollama-config-format.js",
35
- "ollama-config-tools": "nodes/ollama-config-tools.js"
34
+ "ollama-config-tools": "nodes/ollama-config-tools.js",
35
+ "ollama-config-options": "nodes/ollama-config-options.js"
36
36
  }
37
37
  },
38
38
  "engines": {
@@ -1,18 +0,0 @@
1
- <script type="text/javascript">
2
- RED.nodes.registerType( 'ollama-config-model', {
3
- category: 'config',
4
- defaults: {
5
- name: { value: '', required: true }
6
- },
7
- label: function() {
8
- return this.name;
9
- }
10
- } )
11
- </script>
12
-
13
- <script type="text/html" data-template-name="ollama-config-model">
14
- <div class="form-row">
15
- <label for="node-config-input-name"><i class="fa fa-server"></i> Name</label>
16
- <input type="text" id="node-config-input-name" placeholder="llama3.3" />
17
- </div>
18
- </script>
@@ -1,9 +0,0 @@
1
- module.exports = function( RED ) {
2
- function OllamaConfigModelNode( config ) {
3
- RED.nodes.createNode( this, config )
4
-
5
- this.name = config.name
6
- }
7
-
8
- RED.nodes.registerType( 'ollama-config-model', OllamaConfigModelNode )
9
- }