node-red-contrib-ollama 0.2.6 → 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.
@@ -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,12 @@
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 },
9
14
  options: { value: '', type: 'ollama-config-options', required: false },
10
15
  },
11
16
  inputs: 1,
@@ -14,6 +19,37 @@
14
19
  label: function() {
15
20
  return this.name || 'ollama-show';
16
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
+ }
17
53
  } )
18
54
  </script>
19
55
 
@@ -29,8 +65,21 @@
29
65
  </div>
30
66
 
31
67
  <div class="form-row">
32
- <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>
33
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" />
34
83
  </div>
35
84
 
36
85
  <div class="form-row">
@@ -50,24 +99,19 @@
50
99
  </dt>
51
100
 
52
101
  <dd>
53
- 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.
54
104
 
55
105
  <dl class="message-properties">
56
106
  <dt class="optional">
57
107
  payload.host <span class="property-type">string</span>
58
108
  </dt>
59
- <dd>
60
- The host of the Ollama instance.<br />
61
- <em>Alternative to the <code>Server</code> field.</em>
62
- </dd>
109
+ <dd>The host of the Ollama instance.</dd>
63
110
 
64
111
  <dt class="optional">
65
112
  payload.model <span class="property-type">string</span>
66
113
  </dt>
67
- <dd>
68
- The model to show information for.<br />
69
- <em>Alternative to the <code>Model</code> field.</em>
70
- </dd>
114
+ <dd>The model to show information for.</dd>
71
115
 
72
116
  <dt class="optional">
73
117
  payload.system <span class="property-type">string</span>
@@ -81,10 +125,7 @@
81
125
  <dt class="optional">
82
126
  payload.options <span class="property-type">object</span>
83
127
  </dt>
84
- <dd>
85
- Options to configure the runtime.<br />
86
- <em>Alternative to the <code>Server</code> field.</em>
87
- </dd>
128
+ <dd>Options to configure the runtime.</dd>
88
129
  </dl>
89
130
  </dd>
90
131
  </dl>
@@ -3,37 +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: payloadOptions
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
+ }
24
62
 
25
63
  const optionsConfig = RED.nodes.getNode( config.options )
26
- const options = ( optionsConfig ) ? optionsConfig.json : payloadOptions
64
+ const options = msg?.payload?.options || ( optionsConfig ) ? JSON.parse( optionsConfig.json ) : null
27
65
 
28
66
  const response = await ollama.show( {
29
- model,
30
- system,
31
- template,
32
- options
33
- } )
34
- .catch( error => {
35
- node.error( error )
36
- } )
67
+ model,
68
+ system,
69
+ template,
70
+ options
71
+ } )
72
+ .catch( error => {
73
+ node.error( error )
74
+ } )
37
75
 
38
76
  msg.payload = response
39
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.6",
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,7 +30,6 @@
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
34
  "ollama-config-tools": "nodes/ollama-config-tools.js",
36
35
  "ollama-config-options": "nodes/ollama-config-options.js"
@@ -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
- }