node-red-contrib-openai
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -52,3 +52,3 @@ [ | ||
"name": "completions", | ||
"func": "msg.api = 'completions';\nmsg.params = {\n \"model\": \"text-davinci-003\",\n \"prompt\": \"Say this is a test\",\n \"max_tokens\": 7,\n \"temperature\": 0\n}\nreturn msg;", | ||
"func": "msg.api = 'chat/completions';\nmsg.params = {\n \"model\": \"text-davinci-003\",\n \"prompt\": \"Say this is a test\",\n \"max_tokens\": 7,\n \"temperature\": 0\n}\nreturn msg;", | ||
"outputs": 1, | ||
@@ -787,2 +787,2 @@ "noerr": 0, | ||
} | ||
] | ||
] |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
16
node.js
@@ -30,6 +30,6 @@ const axios = require("axios") | ||
}else{ | ||
node.url = 'https://api.openai.com/v1/completions'; | ||
node.url = 'https://api.openai.com/v1/chat/completions'; | ||
} | ||
} | ||
// node.error(node.url); | ||
node.error(node.url); | ||
node.options = {}; | ||
@@ -41,3 +41,2 @@ node.options.headers = {}; | ||
node.options.headers['Authorization'] = 'Bearer ' + node.api_key; | ||
axios.post(node.url, node.params, node.options) | ||
@@ -47,5 +46,10 @@ .then(function (response){ | ||
node.send(msg); | ||
}).catch(function (err){ | ||
msg.payload = err; | ||
node.send(msg); | ||
}).catch(function (error){ | ||
if (error.response) { | ||
msg.payload = error.response.data; | ||
node.send(msg); | ||
}else { | ||
msg.payload = error; | ||
node.send(msg); | ||
} | ||
}); | ||
@@ -52,0 +56,0 @@ }); |
{ | ||
"name": "node-red-contrib-openai", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Node-RED node for openai", | ||
@@ -38,5 +38,5 @@ "main": "node.js", | ||
"dependencies": { | ||
"axios": "^1.2.1" | ||
"axios": "^1.6.8" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -17,10 +17,19 @@ node-red-contrib-openai | ||
## Wrapper openai API | ||
- https://beta.openai.com/docs/introduction | ||
- https://platform.openai.com/docs/api-reference/introduction | ||
## Sample parameters | ||
```js | ||
msg.api = 'completions'; | ||
msg.api = 'chat/completions'; | ||
msg.params = { | ||
"model": "text-davinci-003", | ||
"prompt": "Say this is a test", | ||
"model": "gpt-3.5-turbo", | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "Hello!" | ||
} | ||
], | ||
"max_tokens": 7, | ||
@@ -40,2 +49,2 @@ "temperature": 0 | ||
![alt](examples/result.png) | ||
![alt](examples/result.png) |
@@ -0,0 +0,0 @@ var should = require("should"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
948
49
1208682
Updatedaxios@^1.6.8