Skip to content

Commit

Permalink
Support msg.model property
Browse files Browse the repository at this point in the history
Select any model going forward using the `msg.model` property.
  • Loading branch information
HaroldPetersInskipp committed Jul 12, 2024
1 parent 3c6a0eb commit 2604ed2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
7 changes: 7 additions & 0 deletions chatgpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ <h3>Inputs</h3>
<span class="property-type">string</span>
</dt>
<dd> The ORGANIZATION to be used if not specified in the node.</dd>

<dt class="optional">msg.model
<span class="property-type">string</span>
</dt>
<dd> The model to be selected.</dd>
</dl>

<h3>Outputs</h3>
Expand All @@ -180,6 +185,8 @@ <h3>Outputs</h3>
<h3>Details</h3>
<p>Select the node's behavior by setting the Topic property value to <code>gpt4o</code>, <code>edit</code>, <code>image</code>, <code>turbo</code>, <code>gpt4</code>, or <code>dalle3</code>.</p>

<p>When is set to <code>read from msg.topic</code> if <code>msg.topic</code> is left undefined then the message property <code>msg.model</code> can be used to select any model.</p>

<p>Alternatively you can set the Topic to <code>read from msg.topic</code> to set the behavior dynamically with incoming messages.</p>

<p>1. When <code>msg.topic</code> is set to <code>gpt4o</code>:</p>
Expand Down
15 changes: 7 additions & 8 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -329,20 +329,19 @@ 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,
};
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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -50,6 +50,6 @@
},
"homepage": "https://github.com/HaroldPetersInskipp/node-red-contrib-chatgpt#readme",
"dependencies": {
"openai": "^3.2.1"
"openai": "^4.52.7"
}
}

0 comments on commit 2604ed2

Please sign in to comment.