A simple and straight-forward library to integrate ChatGPT for content completion & chat assistance in Lucee and Adobe ColdFusion, Just use simple functions like suggestContent for completion and sendMessage for chat without needing to understand the intricacies of ChatGPT integration.
ChatGPT.cfc
straightforward functions suggestContent
for content completion and sendMessage
for chat Assistant support. Follow the steps below to initialize the ChatGPT settings, set configuration values, and utilize the ChatGPT methods provided.
CF-ChatGPT-Bridge should be compatible with both Lucee and Adobe ColdFusion. It has been tested with the Lucee engine version lucee-light@5.4.3+2 and the Adobe ColdFusion version adobe@2021.
You can run this as a standalone application without any frameworks. To run tests and build documentation, please execute box install
.
Ensure that the necessary ChatGPT completion and assistant Configuration configuration values are set in ChatGPTSettings.json
.
Create an instance of ChatGPT.cfc
and initialise
// Instantiate ChatGPT.cfc chatGPT = new com.madishetti.ChatGPT().init();
or
// Create and initialise JedisManager.cfc chatGPT = createObject("component","com.madishetti.ChatGPT"); chatGPT.init();
The suggestContent
method facilitates content completion by communicating with the OpenAI completion API and returning the response. You don't need to worry about how to properly create a prompt; simply pass the correct values to the function arguments, and the function will handle the rest.
The suggestContent
function accepts the following arguments:
false
. (boolean, required)English
. (string, required)general public
. (string, required)neutral
. (string, required)Please ensure you set the correct values for the default content settings to achieve the desired output.
//Initialize the arguments struct variables.args = { "purpose": purpose, "description": description, "formattingInstructions": formattingInstructions }; // Is review if(isReview) { variables.args.isReview = true; variables.args.reviewInstructions = reviewInstructions; } // Initialize the ChatGPT object variables.chatGPT = new com.madishetti.ChatGPT().init(); // Call the suggestContent method with the argument collection variables.response = variables.chatGPT.suggestContent(argumentCollection = variables.args);
Please review the example file named ChatSuggestContentTest.cfm
in the examples
folder to test the chatCompletion functionality
Use the sendMessage
method to send a message to the ChatGPT Assistant and retrieves the latest response. If the threadId is left blank for the first call, the ChatGPT Assistant will return a threadId in the response. This threadId should be used in subsequent calls for the same conversation thread. Keep in mind that sending a blank threadId will start a new conversation thread, and any previous conversation history will be lost.
// Initialize the ChatGPT object chatGPT = new com.madishetti.ChatGPT().init(); // Call the sendMessage method with the correct message and threadId arguments response = chatGPT.sendMessage(message = 'test', threadId ='');
{"ASSISTANTRESPONSE":"You're welcome! How can I assist you today? If you have any questions or need help with something specific, feel free to ask!","threadId":"thread_xyz895"}
Please review the example file named ChatAssistantTest.cfm
in the examples
folder to test the chatCompletion functionality.
Please be aware that a mock API endpoint named ChatAssistantTestEndPoint.cfm
has been created. This endpoint simulates an API and generates responses from the sendMessage
function of ChatGPT
.
In the main folder, we have ChatWizard.cfm
, which contains a complete snippet including HTML, CSS, and JavaScript, designed to create a styled chat wizard that can be seamlessly embedded into any HTML page. The CSS styles ensure a clean and user-friendly interface for interacting with the ChatGPT assistant.
To configure the chat wizard, set the following local variables:
chatHeading
: This variable stores the heading of the chat.chatAssistantTestEndPoint
: This variable stores the endpoint used for communicating with the ChatGPT assistant. For testing purposes, we are using a fake endpoint: examples/ChatAssistantTestEndPoint.cfm
. This endpoint mimics an API and returns responses from the sendMessage
function of ChatGPT.Use the sendMessageAndRetrieveAllMessages
method to send a message to the ChatGPT Assistant and retrieves all messages for a given thread. If the threadId is left blank for the first call, the ChatGPT Assistant will return a threadId in the response. This threadId should be used in subsequent calls for the same conversation thread. Keep in mind that sending a blank threadId will start a new conversation thread, and any previous conversation history will be lost.
// Initialize the ChatGPT object chatGPT = new com.madishetti.ChatGPT().init(); // Call the sendMessage method with the correct message and threadId arguments response = chatGPT.sendMessageAndRetrieveAllMessages(message = 'test', threadId ='');
Returns an ordered struct of all messages for a given thread generated from the ChatGPT Assistant OpenAI API.
To test the Chat Assistant functionality, please run the file ChatAssistantTest.cfm
. For testing content completion, run the file ChatSuggestContentTest.cfm
. These files are located in the examples
folder.
To access comprehensive documentation about the ChatGPT
component:
Execute the following command in CommandBox once:
run-script build-docs
Please navigate to servername:portnumber/docs
. This directory contains detailed information to help you better understand the functionality and usage of CF-ChatGPT-Bridge
.
We welcome contributions! If you find a bug or want to add features, feel free to submit a pull request.
CF-ChatGPT-Bridge is open-source under the MIT License.
Start using CF-ChatGPT-Bridge today and bring AI-powered content completion & chat assistance into your ColdFusion applications effortlessly!
There are no datasets linked
There are no datasets linked