Skip to content

Commit

Permalink
Changed default behavior
Browse files Browse the repository at this point in the history
Update to use GPT-4o
  • Loading branch information
HaroldPetersInskipp committed Jul 9, 2024
1 parent a7b49b6 commit d1bf97d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

# Change Log

## [1.3.0] - 2024-07-08

### Changed

- Removed support for depreciated model `text-davinci-003`. `msg.topic` can no longer be set to `completion`
- Changed default behavior to use the new `GPT-4o` model. `msg.topic` can be set to `gpt4o`

## [1.2.17] - 2024-01-17

### Changed
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ With these, you're ready to configure your `node-red-contrib-custom-chatgpt` nod

## Usage

With `node-red-contrib-custom-chatgpt`, you have the power to select the behavior of the node by setting the Topic property value to `completion`, `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`.
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`.

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 `completion`:
1. When `msg.topic` is set to `gpt4o`:

- [Required] `msg.payload` should be a well-written prompt that provides enough information for the model to know what you want and how it should respond. Its success generally depends on the complexity of the task and quality of your prompt. A good rule of thumb is to think about how you would write a word problem for a middle schooler to solve.

- [Optional] `msg.history` should be an array of objects containing the conversation history. [Default:`[]`]

2. When `msg.topic` is set to `image`:

- [Required] `msg.payload` should be a prompt of text description of the desired image.
Expand Down
7 changes: 4 additions & 3 deletions chatgpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$('#node-input-topic').typedInput({type:"topic", types:[{
value: "topic",
options: [
{ value: "completion", label: "completion"},
{ value: "gpt4o", label: "gpt4o"},
{ value: "edit", label: "edit"},
{ value: "image", label: "image"},
{ value: "turbo", label: "turbo"},
Expand Down Expand Up @@ -177,12 +177,13 @@ <h3>Outputs</h3>
</ol>

<h3>Details</h3>
<p>Select the node's behavior by setting the Topic property value to <code>completion</code>, <code>edit</code>, <code>image</code>, <code>turbo</code>, or <code>gpt4</code>.</p>
<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>, or <code>gpt4</code>.</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>completion</code>:</p>
<p>1. When <code>msg.topic</code> is set to <code>gpt4o</code>:</p>
<p>Required <code>msg.payload</code> should be a well-written prompt that provides enough information for the model to know what you want and how it should respond. Its success generally depends on the complexity of the task and quality of your prompt. A good rule of thumb is to think about how you would write a word problem for a middle schooler to solve.</p>
<p>Optional <code>msg.history</code> should be an array of objects containing the conversation history. [Default:<code>[]</code>]</p>

<p>2. When <code>msg.topic</code> is set to <code>image</code>:</p>
<p>Required <code>msg.payload</code> should be a prompt of text description of the desired image.</p>
Expand Down
39 changes: 26 additions & 13 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (RED) => {

// Define a list of acceptable topics for the node
const ACCEPT_TOPIC_LIST = [
"completion",
"gpt4o",
"image",
"edit",
"turbo",
Expand Down Expand Up @@ -287,28 +287,41 @@ module.exports = (RED) => {
}
}
} else {
// Default case for completion topic
// Process messages with the "gpt4o" topic
try {
msg.topic = "completion";
// Request completion from the default model
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: msg.payload,
suffix: msg.suffix || null,
max_tokens: parseInt(msg.max_tokens) || 4000,
msg.topic === "gpt4o";
// Handle GPT-4 conversation logic
if (typeof msg.history === "undefined")
msg.history = [];
msg.topic = "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",
messages: msg.history,
temperature: parseInt(msg.temperature) || 1,
top_p: parseInt(msg.top_p) || 1,
n: parseInt(msg.n) || 1,
stream: msg.stream || false,
logprobs: parseInt(msg.logprobs) || null,
echo: msg.echo || false,
stop: msg.stop || null,
max_tokens: parseInt(msg.max_tokens) || 4000,
presence_penalty: parseInt(msg.presence_penalty) || 0,
frequency_penalty: parseInt(msg.frequency_penalty) || 0,
best_of: parseInt(msg.best_of) || 1,
});
const trimmedContent =
response.data.choices[0].message.content.trim();
const result = {
role: "assistant",
content: trimmedContent,
};
msg.history.push(result);
// Extract completed text from the response
msg.payload = response.data.choices[0].text;
msg.payload = response.data.choices[0].message.content;
msg.full = response;
// Set node status
node.status({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-custom-chatgpt",
"version": "1.2.17",
"version": "1.2.18",
"description": "A Node-RED node that interacts with OpenAI machine learning models to generate text and image outputs like 'ChatGPT' and 'DALL·E 2'.",
"main": "chatgpt.js",
"scripts": {
Expand Down

0 comments on commit d1bf97d

Please sign in to comment.