[Announce] node-red-contrib-custom-chatgpt

A Node-RED node that interacts with OpenAI machine learning models like "ChatGPT".

I encourage you to give it a try, any feedback or collaborators will be greatly appreciated.

5 Likes

Here are some screenshots of the example flow and some output responses:

It can be used to generate completions, edits, and images.


Here are some simple ways you can alter the behavior with a template node.

Kinda surprised this didnt get more attention - this is pretty big. If you can preload the node with the ability to output whatever format you want (like JSON?) then this could emulate just about any other collection of data transformation nodes.

I haven't had a play with it yet, does it have the ability to hold onto context in the same way that the OpenAI webpage implementation does?

@wooferguy,
Yes indeed. I have the same feeling, but I can't give a decent explanation.

When developing (both for my daily job and for my Node-RED hobby), I use chatgpt very frequently because I gain a lot of knowledge by discussing with him/her/it.

And I am VERY convinced this will be a very useful node. But for some reason I lack some creativity to come up with a good use case to use in my flows. And most probably one day somebody will arrive here with a brilliant idea, and then I will go for it right away.

Just waiting for some good use cases from other people....

1 Like

The node has been updated to version 1.2.0 and now includes support for the gpt-3.5-turbo model and conversation history.

The included example has been updated as well.


The full change log is available here

1 Like

@wooferguy
The recent update does allow it to hold onto context when using the new model gpt-3.5-turbo .
To use the new model set msg.topic to turbo and you can then use the optional message property msg.history to input the conversation history. msg.history is expected to be an array of objects containing the conversation history.

msg.history should be formatted something like this:

[
    {
        "role": "user",
        "content": "Write a story about an Elephant."
    }, {
        "role": "assistant",
        "content": "An elephant is a gentle giant, with soft and wrinkled skin. It uses its long trunk to reach for food, and its broad ears to stay cool under the sun. It has two long tusks that can be used to defend itself, but its peaceful nature means it prefers to stay within its herd. Elephants are highly intelligent animals, with remarkable memories and complex communication skills. They are vital to their ecosystem, as their grazing habits help maintain the balance of the savannah. However, they are threatened by habitat loss and poaching for their ivory tusks. We must work to protect these magnificent animals and ensure their future survival."
    }, {
        "role": "user",
        "content": "Change it to be about a dog."
    }, {
        "role": "assistant",
        "content": "A dog is a loyal companion, with soft and furry fur. It uses its keen sense of smell to sniff out scents, and its sharp hearing to perceive sounds beyond human perception. It has sharp teeth that can be used to defend itself, but its friendly nature means it prefers to stick close to its owner. Dogs are highly adaptable animals, and their intelligence has made them a popular choice for a variety of tasks, ranging from service animals to police work. They bring joy and happiness to many, and their loving nature has made them a cherished member of families worldwide. However, they are susceptible to numerous health conditions and require proper care and nutrition to live a healthy, happy life. We must work to provide a loving home and appropriate care for our furry friends and appreciate the joy they bring into our lives."
    }
]

You should also be able to inject a pre-prompt behavior with the msg.history property like this:

[
    {
        "role": "system",
        "content": "You are a helpful assistant."
    }
]

Some more examples generated by chatgpt :wink:

[{"role": "system", "content": "You are a helpful assistant that translates French to English."},
{"role": "user", "content": 'Translate the following French text to English: "{text}"'}]

[{"role": "system", "content": "You are a creative writing assistant, helping users generate new ideas and improve their writing."},
{"role": "user", "content": 'Please provide a writing prompt to help me generate some ideas.'}]

[{"role": "system", "content": "You are a technical support assistant, helping users troubleshoot and resolve issues with software or hardware."},
{"role": "user", "content": 'Please describe the problem you are experiencing and what steps you have already taken to try to resolve it.'}]

[{"role": "system", "content": "You are a news summarizer, providing concise summaries of current events."},
{"role": "user", "content": 'Please provide a news article for me to summarize.'}]

[{"role": "system", "content": "You are a poetry generator, helping users create unique and creative poems."},
{"role": "user", "content": 'Please provide a topic or theme for the poem you would like me to generate.'}]

[{"role": "system", "content": "You are a customer service representative, assisting customers with inquiries and resolving issues."},
{"role": "user", "content": 'What can I help you with today? Please describe your inquiry or issue.'}]

[{"role": "system", "content": "You are a language learning assistant, helping users learn a new language."},
{"role": "user", "content": 'Please provide a phrase or sentence for me to translate to the language you are learning.'}]

[{"role": "system", "content": "You are a personal finance advisor, providing advice and guidance on managing finances."},
{"role": "user", "content": 'Please provide details about your current financial situation and goals.'}]

[{"role": "system", "content": "You are an academic writing assistant, helping users improve their writing for academic purposes."},
{"role": "user", "content": 'Please provide a writing prompt or topic for me to help you generate ideas and improve your writing.'}]

[{"role": "system", "content": "You are a personality test administrator, helping users learn more about their personality traits."},
{"role": "user", "content": 'Please answer the following questions to learn more about your personality.'}]

However, in general, gpt-3.5-turbo-0301 does not pay strong attention to the system message, and therefore important instructions are often better placed in a user message.

2 Likes

I wonder if it could be used to write the help window contents for a node automatically in the correct format based off of a nodes JavaScript code. I don't feel that I know the Node-RED Node help style guide well enough to create the prompt necessary for this yet.

Or similar prompts that could help facilitate creating nodes/subflows/etc.

1 Like