ChatGPT Custom Server Connect module (node)

Custom Server Connect module - ChatGPT

Introduction

Welcome to my first revision of a Custom Server Connect module for node facilitating interfacing with ChatGPT. This module can use "gpt-3.5-turbo" or "gpt-4o". I hope to add more options later.

This server connect module allows the user to pass text to ChatGPT and returns a text response.

Extension location and installation

The extension can be found in the npm repository here:

The extension is installed in accordance with this post

Don't forget to do a full Wappler restart to activate the extension

Using the extension

Once installed a new icon will appear in the API connector group of server connect

Adding the Chat GPT API key

Firstly we must define out ChatGPT API key

You can get an API key from:

https://platform.openai.com/api-keys

and add credit via

https://platform.openai.com/settings/organization/billing/overview

We do so by creating a Environment variable within Workflows server connect settings

We add an environment variable. This MUST be called "OPENAI_API_KEY" and we add the API key

Adding the component

Create an API action and add the component

Add a name

In this tutorial i am going to pass the enquiry from a page as a $_POST variable so i add this to the Inputs. The data source could alternatively be static text or dynamic such as the output of a database query.

Configuration

Add it to as the request body

Tokens

It is important to set the number of tokens for the enquiry. Tokens roughly align to characters.
Each character in the enquiry and the response contribute to the tokens total.
As the pricing for chat GPT is based on the number of tokens used, then setting a limit is a good way of managing costs.

In this case i set the maximum number of tokens to 100 and check output to enable the response

Chat GPT Engine

I select the desired Chat GPT engine from the dropdown

Token Pricing based on chat engine

Open AI token process vary between engines, basically the more advance engine, the higher the cost. I have included gpt-3.5-.5-turbo as token prices are around 5% of the cost of gpt-4o tokens. While less sophisticated, using gpt-3.5-turbo can significantly reduce costs.

Output

Finally we enable output to ensure the response is available.

Example use

I now create a content page with a simple server connect form with a text input and submit button.

I name the text input to match the $_POST input variable.

I connect the server connect for to the chat API action i have just created

I add a further row/column and paragraph to display the results of the action and set the text via dynamic attributes to Inner text and select the returned value form the form data

I then open the page in a browser and add a question, in this case "what is wappler"

The Chat GPT response is displayed in the lower paragraph

8 Likes

This is an excellent extension Brian, I'm looking forward to getting it used.

I have a feeling this will be a springboard for more extensions that make interfacing with AI a bit more straightforward.

Just today I've started work on an internal mailer so I'm going to add this above the Summernote input to allow the email author to use it as a prompt for the message they are about to send out..

2 Likes

Thank you Brian!!!!
You are unstopable

1 Like

Amazing Brian...
As claude and gpt are leapfrogging each other on an almost weekly basis, It would be great if we could also have an extension for the claude api. :crossed_fingers:

It is on the to do list but not sure on timescales, too many ideas, too little time

That's amazing news Brian,
Im developing a PR web app with my wife and I know what too little time and too many ideas is like...

I'm filled with horror when she starts a sentence with 'It would be nice if' and
'that shouldn't take you too much time, should it?'. :joy:

1 Like