From 2604ed2b3549b2dc49498684500ec9a7660a1c94 Mon Sep 17 00:00:00 2001
From: Inskipp <71417979+HaroldPetersInskipp@users.noreply.github.com>
Date: Fri, 12 Jul 2024 11:27:53 -0600
Subject: [PATCH] Support `msg.model` property
Select any model going forward using the `msg.model` property.
---
CHANGELOG.md | 8 +++++++-
README.md | 2 ++
chatgpt.html | 7 +++++++
chatgpt.js | 15 +++++++--------
package.json | 4 ++--
5 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f42af57..d9cae0f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,12 @@
# Change Log
+## [1.3.2] - 2024-07-12
+
+### Changed
+
+- Included support for new message property `msg.model` to select any model.
+
## [1.3.1] - 2024-07-08
### Changed
@@ -50,7 +56,7 @@
### Changed
-- Include function calling with GPT-4 model with the msg.functions property
+- Include function calling with GPT-4 model with the `msg.functions` property
- Updated documentation
diff --git a/README.md b/README.md
index 9945c10..5ed3700 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,8 @@ With these, you're ready to configure your `node-red-contrib-custom-chatgpt` nod
With `node-red-contrib-custom-chatgpt`, you have the power to select the behavior of the node by setting the Topic property value to `gpt4o`, `image`, `edit`, `turbo` , or `gpt4`. You can control the node with a single required message property `msg.payload` or dynamically set the behavior with incoming messages using `read from msg.topic`.
+When is set to `read from msg.topic` if `msg.topic` is left undefined then the message property `msg.model` can be used to select any model.
+
For detailed information on the usage of these modes, please refer to the [OpenAI API documentation](https://beta.openai.com/docs/).
1. When `msg.topic` is set to `gpt4o`:
diff --git a/chatgpt.html b/chatgpt.html
index a0d0404..3991961 100644
--- a/chatgpt.html
+++ b/chatgpt.html
@@ -161,6 +161,11 @@
Inputs
string
The ORGANIZATION to be used if not specified in the node.
+
+ msg.model
+ string
+
+ The model to be selected.
Outputs
@@ -180,6 +185,8 @@ Outputs
Details
Select the node's behavior by setting the Topic property value to gpt4o
, edit
, image
, turbo
, gpt4
, or dalle3
.
+ When is set to read from msg.topic
if msg.topic
is left undefined then the message property msg.model
can be used to select any model.
+
Alternatively you can set the Topic to read from msg.topic
to set the behavior dynamically with incoming messages.
1. When msg.topic
is set to gpt4o
:
diff --git a/chatgpt.js b/chatgpt.js
index a32cf20..43c8c09 100644
--- a/chatgpt.js
+++ b/chatgpt.js
@@ -91,7 +91,7 @@ module.exports = (RED) => {
// Process messages with the "image" topic
try {
// Make a request to OpenAI API for image creation
- const response = await openai.createImage({
+ const response = await openai.images.generate({
prompt: msg.payload,
n: parseInt(msg.n) || 1,
size: msg.size || "256x256",
@@ -175,7 +175,7 @@ module.exports = (RED) => {
// Process messages with the "edit" topic
try {
// Make a request to OpenAI API for edit topic
- const response = await openai.createEdit({
+ const response = await openai.edits.create({
model: "text-davinci-edit-001",
instruction: msg.payload,
n: parseInt(msg.n) || 1,
@@ -222,7 +222,7 @@ module.exports = (RED) => {
};
msg.history.push(input);
// Request completion from gpt-3.5-turbo model
- const response = await openai.createChatCompletion({
+ const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: msg.history,
temperature: parseInt(msg.temperature) || 1,
@@ -281,7 +281,7 @@ module.exports = (RED) => {
msg.history.push(input);
// Request completion from GPT-4 model
- const response = await openai.createChatCompletion({
+ const response = await openai.chat.completions.create({
model: "gpt-4",
messages: msg.history,
temperature: parseInt(msg.temperature) || 1,
@@ -329,11 +329,10 @@ module.exports = (RED) => {
} else {
// Process messages with the "gpt4o" topic
try {
- msg.topic === "gpt4o";
// Handle GPT-4 conversation logic
if (typeof msg.history === "undefined")
msg.history = [];
- msg.topic = "gpt4o";
+ msg.topic = msg.model ? msg.model : "gpt4o";
const input = {
role: "user",
content: msg.payload,
@@ -341,8 +340,8 @@ module.exports = (RED) => {
msg.history.push(input);
// Request completion from GPT-4 model
- const response = await openai.createChatCompletion({
- model: "gpt-4o",
+ const response = await openai.chat.completions.create({
+ model: msg.model ? msg.model : "gpt-4o",
messages: msg.history,
temperature: parseInt(msg.temperature) || 1,
top_p: parseInt(msg.top_p) || 1,
diff --git a/package.json b/package.json
index 0ab696c..bc6a380 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-custom-chatgpt",
- "version": "1.3.1",
+ "version": "1.3.2",
"description": "A Node-RED node that interacts with OpenAI machine learning models to generate text and image outputs like 'ChatGPT', 'DALL·E 2', and 'DALL·E 3'.",
"main": "chatgpt.js",
"scripts": {
@@ -50,6 +50,6 @@
},
"homepage": "https://github.com/HaroldPetersInskipp/node-red-contrib-chatgpt#readme",
"dependencies": {
- "openai": "^3.2.1"
+ "openai": "^4.52.7"
}
}