OpenAI Connector (ChatGPT)

Content Type: Module
Categories: Artificial Intelligence

Overview

Welcome to the OpenAI Connector module!

This module allows users to seamlessly integrate the OpenAI API completion endpoints into their Mendix application. With this module, users can easily request completions from the OpenAI API and configure the AI's response to suit their specific needs.

To get started, simply import the module into your Mendix project and add the OpenAI API key to the module's configuration. From there, you can use the provided microflows and actions to request completions and alter the configuration settings to tailor the AI's response to your needs.

Some of the key features of this module include:

  • Easy integration with the OpenAI API.
  • Support for multiple completion endpoints.
  • Flexible configuration options to adjust the AI's response.
  • Microflows and actions for requesting completions and managing configurations.
  • Content generation

We hope you find this module useful in your Mendix projects and look forward to seeing what you can create with it!

If you have any questions or feedback, please don't hesitate to reach out to our support team.

Written by Comotion Business Solutions

Documentation

Description

This module allows you to easily integrate the OpenAI API completion endpoints into your Mendix application. With this module, you can request completions from the OpenAI API and configure the AI's response to suit your specific needs.

In this guide, we will walk you through the process of setting up and using the module. We will cover topics such as tenant setup, bot configuration setup and how the user can use the chat interface to their best advantage.

By the end of this guide, you will have a reliable understanding of how to use the module and how to get the most out of it. So, let's get started!

Please note that before using this module, you must have an API key from OpenAI.

Typical usage scenario

  • Customer wanting to find out more about a site or product.
  • Company want to generate email content.
  • Company employees wanting to have certain questions answered.

Features and limitations

Features

  • Multi-tenancy
  • API Key Encrypted Storage
  • AI bot configurations setup (per Tenant)
  • OpenAI completion AI API integration
  • OpenAI models API integration
  • Chat interface (with Advanced Options)
  • Copy chat entries 
  • Content generation process

Limitations

  • OpenAI Completion AI API Integration only (does not include the Edits or Images AI API)

Future versions will include the Edits and Images API endpoint integrations.

Dependencies [optional]

  • Mendix Modeler 9.18.3
  • Encryption (v8.0.3)
  • Administration (v2.1.1)
  • NanoflowCommons (v2.1.0)
  • CommunityCommons (v9.0.2)

 

Installation 

User Security

The module users should be applied to the appropriate user roles.

All users should gain access to the "manageUserKey" module role, and only high level users (e.g. Administrators) should gain access to module roles such as "moduleAdministrator" and "manageConfigurations".

Users which should only be allowed to use the chat interface should be assigned the module user role "requestCompletions" and "manageUserKey".

Microflows

  • ACT_RequestContent

This microflow is used to generate content and should not be used in a chat context. It requires authentication parameters (tenant, tenant user) and the content request. It returns the completion request response which contains the completion choices. The completion choices should be used to view the generated content.

Requirements: Tenant, TenantUser, Prompt (content request) and UseDefault (refers to the configuration)

If UseDefault is set to false a random bot configuration will be used.

Pages & Snippets

The following pages and snippets should be integrated to the parent application.

  • AI_IntegrationConfigurationsSnippet

This snippet is the configuration place for the module. All pages and actions required for setup can be found from here.

Requirements: None.

  • AI_IntegrationConfigurations

This page is the configuration place for the module. All pages and actions required for setup can be found from here. The snippet 'AI_IntegrationConfigurationsSnippet' is used in this page.

Requirements: None.

  • AccountTenantUserKeyStore

This snippet displays the KeyStore (API authentication object) for a tenant user.

Requirements: This snippet requires context parameter of type: Account.

  • AccountTenantAssignment

This snippet holds the functionality for an administator to select the Tenant of a user.

Requirements: This snippet requires context parameter of type: Account.

  • ChatSnippet_Full

This snippet contains all the chats for the logged in TenantUser. On this page the user can create new chats and if the bot configuration of the chat allows the user to change the configurations they can do so.

Requirements: None.

  • ChatPage

This snippet contains all the chats for the logged in TenantUser. On this page the user can create new chats and if the bot configuration of the chat allows the user to change the configurations they can do so. The snippet 'ChatSnippet_Full' is used in this page.

Requirements: None.

  • RequestContent_Example

This page is used as the starting point for an example process of content generation.

Requirements: Access Required: moduleAdministrator, requestionCompletion

User Guide

Tenants

User Roles: manageConfigurations, moduleAdministrator

The usage of this module requires that at least one tenant is setup for usage. These following sections will take you through the setup process and management of a tenant.

Create / Edit

Firstly, you’ll need to create a tenant. You can start this process by navigating to the ChatGPT integration configuration page.

From there you can click on the Tenants tile (shown above) and then click ‘+ New’ at the top right of the Tenants Overview page.

If this is the first tenant that you are creating, set the tenant to Default. This will ensure that the core processes have a default tenant to use.

Set the Tenant to ‘Active’, give it a ‘Name’ and ‘Prefix’ and then select the ‘Authentication Level’.

The ‘Authentication Level’ determines at which level (Tenant or User) will the API key be required to be set.

If the ‘Authentication Level’ is set to Tenant, new fields will become available below the drop down.

Click the ‘+ Add Key’ button to add an API key. It is important to note that the API key should be in the following format: “Bearer API_KEY_HERE”. The “Bearer ” part is required for every key.

The key stored on your application is kept encrypted and is only available to the user or tenant that added it.

Lastly, if the tenant is an organization and is registered on OpenAI, an ID can be acquired from your OpenAI account and stored here. This will link all the requests made to the organisation.

Disclaimer: Please be aware of the costing element associated with the API key that you set are not monitored on in this module.

User Administration

Once the tenant has been created the administrator can start to assign users to the tenant.

This assignment process will take place on the page where the ‘AccountTenantAssignment’ snippet was placed. The snippet allows the administrator to select a tenant for the user.

User’s without tenants won’t be able to make use of the chat functionality.

Below is an example of how the page where the snippet was placed may look:

A complete list of the tenant’s users can be found on the Tenant View page under the Tenant Users tab.

Here you can deactivate or activate users.

Selected Models

Complete General Configurations before continuing with this step.

Tenants can refine the number of models that they would like to be available for the bot configurations by selecting and associating models with the tenant.

Selected models can be defined from the Tenant View page.

The tenant view page can be accessed from the Tenant Overview page by selecting the specific tenant and click ‘View’.

Once you have landed on the Tenant View page open the ‘Selected Models’ tab.

On the right-hand side are the available models that can be selected and associated with the tenant. On the left-hand side are the models that have already been selected.

Once a model has been selected you can:

  • Change Status: Activate/Deactivate.
  • Make Default: Set the model as the default model for the tenant.
  • Remove: Remove the model from the tenant.

Bot Configurations

Complete General Configurations before continuing with this step.

Bot configurations is the collection of settings that will be applied to the chat interface with the AI.

Bot configurations can be defined from the Tenant View page.

The tenant view page can be accessed from the Tenant Overview page by selecting the specific tenant and clicking ‘View’.

Once you have landed on the Tenant View page open the ‘Bot Configurations’ tab.

 

Create Bot Configuration

To create a bot configuration, you can click ‘+ New’ on the ‘Bot Configurations’ tab.

You will be prompted with a pop-up where you must select the Bot Type. For this user guide and version 1.0.0 of the module we only focus on the completion bot type.

Select the Completion Bot.

On the next page you will complete the general details of the bot. More information of the fields and settings will be provided on the page.

 The next page will allow you to set the specialised bot configurations for the type of bot that you have selected. The completion bot type has the most settings and more information on the various fields can be found by consulting the completion API documentation provided by Open AI.

The final page is where you can review the configuration setup.

Bot Configuration Management

Once you have created the bot configurations for a tenant and assigned the default configuration, users can start to use the chat interface. The default bot configuration will be used when a user creates a chat sessions.

Should you want to edit, deactivate or change the default bot configuration. You can do this from the ‘Bot Configuration’ tab.

General Configurations

User Roles: manageConfigurations, moduleAdministrator

Complete Tenant Create/Edit before continuing with this step.

To use the module effectively you will need to setup Bot Types and the AI Models.

Bot Types

Bot types effectively are the types of endpoints that will be available to the end user.

The following bot types are currently available in this module: Completion.

You can start this process by navigating to the AI integration configuration page. Here you can click the ‘Bot Types’ tile.

Once on this page, the user must click ‘Generate Default Bot Types’. This will generate the default bot types. These will be used later.

 

AI Models

Open AI provides many different AI models. These models all vary in accuracy of results, output variety and cost of usage.

An API endpoint is provided to retrieve all the available models.

You can start this process by navigating to the AI integration configuration page. Here you can click the ‘Models’ tile.

Once on the AI models page you can click ‘Get Models’. This will trigger the endpoint that retrieves all the models from Open AI.

If there are any models that you as an administrator do not want to allow the usage of, you can select and click ‘Update Status’ to change the status of the model. This will enable or disable the usage of the model depending on its status.

Users

User Roles: manageUserKey, completionRequest

Tenant Assignment

See User Assignment.

User API Key Assignment

Users can manage their own API key if they are associated to a tenant that has the ‘Authentication Level’ set to User.

In this case the user can open the page where the snippet ‘AccountTenantUserKeyStore’ was placed.

Click the ‘+ Add Key’ button to add an API key. It is important to note that the API key should be in the following format: “Bearer API_KEY_HERE”. The “Bearer ” part is required for every key.

The key stored on your application is kept encrypted and is only available to the user or tenant that added it.

Lastly, if the user/tenant is part of an organization and is registered on OpenAI, the OrganisationID can be acquired from your OpenAI account and stored here. This will link all the requests made to the organisation.

Disclaimer: Please be aware of the costing element associated with the API key that you set are not monitored on in this module.

Chat Interface

Once all the configurations have been setup, tenants created and users have been assigned their tenants the main feature, the chat interface, can be used successfully.

If a user is not assigned to a tenant and they attempt to create a new chat, they will receive the following error:

Basic Interface

The chat interface allows the user to send and receive information from OpenAI’s completions endpoint.

Like ChatGPT’s interface the user can keep multiple chats using the chat list on the left side of the chat page.

These chats will have auto generated names, but the names can be changed by the user.

The user can send requests using the text box at the bottom centre of the page and pressing enter.

The messages sent and received can be copied or cleared using the ellipses buttons on each chat entry, or the entire chat can be cleared using the ‘Clear Chat’ button.

Advanced Options

Depending on the default bot type configuration that was created, the user may be able to access advanced options on the chat interface.

The ability to do this will be indicated by the cog icon on a chat.

The user can toggle the visibility of the advanced options by clicking on the cog. The advanced options will appear on the right side of the page.

The updates made to the configuration will only be maintained within the chat session selected. Any changes made will not affect the main configuration.

The updates will also only take effect once the user clicks ‘Save’ and then submits a request using the text box at the bottom centre of the page.

Configuration

Constants
  • None.

 

Known bugs

  • N/A

 

Releases

Version: 1.0.0
Framework Version: 9.18.3
Release Notes: First Release. New Features: - Multi-tenancy - API Key Encrypted Storage - AI bot configurations setup (per Tenant) - OpenAI completion AI API integration - OpenAI models API integration - Chat interface (with Advanced Options) - Copy chat entries - Content generation process Limitations: - OpenAI Completion AI API Integration only (does not include the Edits or Images AI API)