Skip to main content
Skip table of contents

ChatGPT

ChatGPT setup

Requirements

To connect with Cyclr, you need a OpenAI account, API key, and organization ID. You can register for an OpenAI account on the OpenAI website.

OpenAI API access is a paid for service. For more information on pricing, see the OpenAI documentation.

Get an API key

  1. Go to the API keys page.

  2. Select Create new secret key.

  3. Enter a name for the new secret key.

  4. Select Create secret key.

  5. Make note of the API key displayed in the modal text box.

Get your organization ID

An organization ID allows you to use API requests against a specific organization's subscription quota. You can find the organization ID on the Organization settings page of the OpenAI website.

Cyclr account setup

Cyclr asks for the below values when you install the ChatGPT connector into an account:

Value

Description

OpenAI Organization

Optional: the OpenAI organization to use for API requests. Usage from the API requests will count against the specified organization's subscription quota.

API Key

The OpenAI API key to make API requests with.

You can use different details for different accounts.

Chat sessions

Cyclr uses chat sessions to store chat history for the ChatGPT connector. Each chat session contains the ID of the chat, a log of the messages sent and received in the chat, and the date and time the chat was created and modified.

Methods inside the Chat Sessions and Chats method categories operate using chat sessions.

You can identify and access chat sessions with a Chat Session ID. This ID is stored as a string and can have any format. If the Chat Session ID doesn't exist when a method inside the Chat's method category is used, this creates a new chat session with the entered Chat Session ID.

Saved chat sessions have a hard character limit of 51,200 characters. Chat sessions that exceed this will be trimmed down, with the oldest messages removed first, until they are below the limit.

Cyclr prunes any chat session created or modified more than 30 days ago.

Token trimming

Each chat message sent has a token value based on the total content of all the messages in the chat session. As each chat session logs messages, the token total for the chat session increases as the chat session is used. For more information, see OpenAI's documentation on tokens and how to count them.

Each model has a limit on the number of tokens that can be used per request. For methods in the Chats method category, the available models have token limits as follows:

Name

Model

Token limit

GPT-4o

gpt-4o

4,096

GPT-4o latest

chatgpt-4o-latest

16,384

GPT-4o mini

gpt-4o-mini

16,384

GPT-4 turbo

gpt-4-turbo

4,096

GPT-4

gpt-4

8,192

GPT-3.5 turbo

gpt-3.5-turbo

4,096

To automatically manage chat session tokens, methods in the Chats method category have Trim Tokens? and Custom Token Limit parameters that you can use.

Trim Tokens?

Set this parameter to true to automatically trim chat sessions down to below the token limit for the model. If no model is found, a default token limit of 4096 is used. When you trim a chat session, Cyclr trims the oldest message in the chat session first. This process repeats until the chat session is below the token limit, and then Cyclr sends the request with the trimmed chat session.

The token total for a chat session is an approximation made by Cyclr and may not reflect the token total the API calculates.

If you enable Trim Tokens?, messages that Cyclr removes from chat sessions are permanently removed.

Custom Token Limit

Set this parameter to force a custom token limit for Cyclr to trim a chat session down to. This overrides the limit for the model and the default token limit. There is a lower limit of 100 tokens for this value to make sure that at least one message can be sent in the request.

Basic chat bot Cycle

You can set up a basic chat bot cycle:

Install the Generic Webhook Utility Connector

  1. Navigate to the install a Utility Connector page:

    • In the Cyclr Console:

      • Navigate to Templates > Template Connectors.

      • Select + Install New Utility.

    • In the Cycle builder:

      • Select + Add Utility.

  2. Find the Generic Webhook connector and select Install.

  3. Edit the Name field if you need to. This example sets the name to ChatGPT webhook.

  4. Select Next.

Setup the Generic Webhook connector

  1. Navigate to the Edit Connector page of the Generic Webhook Connector:

    • In the Cyclr Console:

      • Navigate to Templates > Template Connectors.

      • Under the Installed Utility Connectors heading, select Edit Connector next to the ChatGPT webhook Connector.

    • In the Cycle builder:

      • In the right hand menu, under the Utility Connectors heading, select the ChatGPT webhook Connector.

      • Select Settings.

  2. Under the Methods and Fields heading, select Webhooks > Webhook.

  3. Under the Request Fields heading, select the + (Add Field) icon to add request fields for:

    • A Chat Session ID field that will receive the chat session ID to use for the chat request.

    • A Message field that will receive the message to send to the API.

  4. Under the Methods and Fields heading, select HTTP Methods > POST.

  5. Under the Request Fields heading, select the + icon to add a request field for:

    • A Chat Session ID field that contains the chat session ID to identify which chat the response was from.

    • A Message field that contains the response message.

Create the Cycle

Create a new Cycle as follows:

image-20240828-130715.png

Setup each method as follows:

Webhook

Receive the chat session ID and message.

List Chat Session Messages

Check if the chat session already exists. If it does, the message from the Webhook step is sent to the chat. If it doesn’t, an initial system message is sent to the chat using the Send System Message step before a user message is sent to the chat using the Send User Message step.

Send User Message

Sends a user message to an existing chat session.

Field

Mapping

Chat Session ID

Webhook > Chat Session ID

Trim Tokens?

Use Select a Value to set if tokens should be trimmed.

Model

Use Select a Value to set the model.

Message

Webhook > Message

Send System Message

Sends an initial system message to a new chat session.

Field

Mapping

Chat Session ID

Webhook > Chat Session ID

Model

Use Select a Value to set the model.

Message

Use Type a Value to enter an initial system message.

POST

Respond to an external source with the answer ChatGPT generated.

Field

Source

URL

Use Type a Value to enter a URL to post ChatGPT’s response to.

Chat Session ID

Webhook > Chat Session ID

Message

Send User Message > Choice Message Content

Use the cycle

To start the cycle, select Run in the Cycle builder. To use the chat bot cycle:

  1. Select the Step Setup of the Webhook step.

  2. Make note of the webhook URL.

  3. Post to this webhook URL from an external source, either another Cycle or an external client such as Postman, with a request body structure as follows:

    CODE
    {
    	"chatSessionId": "test-chat-session-1",
    	"message": "How do I convert miles to centimeters?"
    }

Cyclr saves all messages (system, user, and assistant) with the Chat Session ID provided. In this example, the ID is test-chat-session-1, and you can therefore post follow up requests with the same Chat Session ID to continue the conversation.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.