node-red-contrib-ollama 0.2.6 → 0.4.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,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.4.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"
@@ -40,7 +39,7 @@
40
39
  "node": ">=18.0.0"
41
40
  },
42
41
  "dependencies": {
43
- "ollama": "^0.5.11"
42
+ "ollama": "^0.5.16"
44
43
  },
45
44
  "bugs": {
46
45
  "url": "https://github.com/jakubburkiewicz/node-red-contrib-ollama/issues"
@@ -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
- }