Skip to main content

AI Chatbot integration

The AI Chatbot integration allows you to add persistent instructions and context to create custom AI chat profiles tailored to a specific use case, allowing for feature-rich automated workflows.

Benefits

The Squid AI Chatbot integration provides a streamlined way to create AI solutions ranging from a single conversational chatbot who answers questions about your product all the way to robust AI agents and systems with multiple layers and actions.

Use cases

Create embedded workflows that are kicked off from a single client query. A customer message like "I need to transfer my service" can be classified and then passed to the appropriate agent in the workflow. From there, another Squid AI chatbot profile can consult with internal private resources like those pertaining to transfer procedures, and then pass its responses to another agent or back to the as needed. These workflows can be as simple or complex as required to suit your unique use case.

How it works

Under the hood, this integration uses OpenAI and the GPT-3.5, GPT-4, and GPT-4 Turbo models to generate answers to users' questions. When a user asks a question, the persistent instructions and most relevant context are passed to OpenAI as part of the prompt, providing the user with a contextualized answer.

Squid AI provides two straightforward methods to create chatbots, add or update chat instructions, and add or update context: through the Squid Cloud Console or programmatically using the Squid Client SDK. And with Squid Cloud's powerful Backend SDK, you can secure your Squid AI chatbots however you need to for your use case so you can be sure only the right information goes to the right place.

squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('profile-id')
.chat('How do I use the AI Chatbot integration?')
.subscribe((response: string) => {
// The 'response' will be built incrementally as tokens are received from OpenAI.
});

Creating the integration

To create the integration, navigate to the list of available AI integrations in the Squid Cloud Console, and add the AI Chatbot integration.

Integration fields

When creating the integration you must supply the following:

  • Integration ID: The unique identifier for the integration. This should be meaningful and easily readable in code. This cannot be changed later.

Building a profile

A profile represents a distinct personality or setup for the AI chatbot. Each profile is like a different persona or use case that the chatbot can adopt, distinguished by its own set of instructions and context. This design enables customized responses from the AI according to the specific profile.

After creating an integration, profiles can be constructed either through the Squid Cloud Console or through the Squid Client SDK itself.

Note

The following examples show how to create a profile using the Client SDK. However, the Console provides a robust UI for creating profiles and adding and removing instructions or context on a profile. If you're not dynamically creating profiles or adding context, this UI is all you need to successfully create an chatbot.

Adding a profile

Backend code
await squid.ai().chatbot('INTEGRATION_ID').profile('pirate').insert({
modelName: 'gpt-4',
isPublic: true,
});

When inserting a profile, you pass an object with a modelName field indicating the OpenAI model to use. Currently Squid supports gpt-3.5-turbo and gpt-4.

isPublic determines whether the chat functionality of the given profile can be accessed without setting up security rules.

Note that the insert method results in an error if a profile already exists with the same profile ID.

Updating a profile

To update an existing profile, use the update() method, passing the profile data you want to change:

Backend code
await squid.ai().chatbot('INTEGRATION_ID').profile('pirate').insert({
isPublic: false,
});

Deleting a profile

To delete an existing profile, use the delete() method:

Backend code
await squid.ai().chatbot('INTEGRATION_ID').profile('pirate').delete();

Note that this function results in an error if no profile exists for the provided profile ID.

Instructions

Instructions set the rules for how the profile responds to prompts and answers questions. They should be direct and simple, and explain the purpose of the profile. Instructions are supplied as a block of text.

When generating a reference to an instruction, you can provide an instruction ID or one can be automatically generated.

The following example provides an instruction ID of 'pirate-speak':

Backend code
const instruction = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak'); // uses the 'pirate-speak' instruction ID

The following example does not provide an instruction ID, so one is randomly generated:

Backend code
const instruction = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction(); // uses a new randomly-generated instruction ID

Adding instructions

To add a new instruction entry to a chatbot profile, use the instruction().insert() method, passing the instruction data as an object. For the

Backend code
const instruction =
'You are a pirate, only answer questions like a pirate would.';
await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak')
.insert({ instruction });

Note that this function results in an error if an entry exists with the same ID. For example, if the profile shown here already had an instruction with a key of instruction, this would result in an error. To update instructions, use the update() method shown in following example.

Updating instructions

To update an existing profile instruction, use the update() method:

Backend code
const instruction =
'You are a pirate, only answer questions like a pirate would. Call me Captain.';
await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak')
.update({ instruction });

Deleting instructions

To delete an existing instruction, use the delete() method:

Backend code
const instruction =
'You are a pirate, only answer questions like a pirate would. Call me Captain.';
await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak')
.delete();

Context

Context tells the profile what knowledge to pull from when answering questions. Adding context allows the profile to provide relevant answers on specific topics that may not be part of the underlying AI model.

When generating a reference to context, you can provide a context ID or one can be automatically generated.

The following example provides a context ID of 'backstory':

Backend code
const context = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context('backstory');

The following example randomly generates a context ID:

Backend code
const context = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context();

Adding context

To ad new context to a profile, use the insert() method, passing the context:

const data = `Your name is Captain Anne "Eye Patch" Jones. Your favorite ship was the Red Flag. You sailed multiple voyages across the Seven Seas with your first mate Skinny Pete.`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context()
.insert({ title: 'Backstory', context: { type: 'text', data } });

Two types of contexts are supported:

The text context type

Text context is created with a string that contains the context:

const data = `Your name is Captain Anne "Eye Patch" Jones. Your favorite ship was the Red Flag. You sailed multiple voyages across the Seven Seas with your first mate Skinny Pete.`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context()
.insert({ title: 'Backstory', context: { type: 'text', data } });

The url context type

URL context is created by providing a URL to be scraped for context. Currently only content on that specified page will be scraped. If you want to create context for multiple pages on a site, they will each need their own context entry.

const data = `https://en.wikipedia.org/wiki/blackbeard`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context()
.insert({ title: 'Backstory', context: { type: 'url', data } });
Note

URL context is static, meaning it is not automatically refreshed with website updates. To ensure your chatbot's context is up to date, you need to re-add the URL context when the content of the website changes. Automatic context refreshes are coming to Squid AI in the future.

Updating context

To update context, use the update() method:

const data = `https://en.wikipedia.org/wiki/Anne_Bonny`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context('backstory')
.insert({ title: 'Backstory', context: { type: 'url', data } });

Note that this method results in an error if an entry has not yet been created for the current context ID.

Deleting context

To delete a context entry, use the delete() method:

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context('backstory')
.delete();

Note that this method results in an error if an entry has not yet been created for the current context ID.

While these are simple examples, the context you add can be much more complex. Some good examples for context could include things like code documentation, product manuals, business operations (e.g store hours) and user-specific data. You can mix and match url and text contexts to create a robust knowledge base for your AI chatbot, ensuring they can provide any information your users will need.

Note

Your context can be as long as you like, however since there are character limits to OpenAI prompts, only a portion of your context may actually be included alongside the user's inquiry. When constructing a prompt, Squid decides which portions of the supplied context are most relevant to the user's question.

Chatting

Once a profile has been created, you're ready to start asking questions. Use the chat() method on the desired chatbot profile.

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.chat('Tell me about yourself.')
.subscribe((response) => {
// Ahoy there, matey! I be Captain Anne "Eye Patch" Jones, the most fearsome pirate to ever sail the Seven Seas. Me favorite ship be the Red Flag, a beauty she was, and me trusty first mate be Skinny Pete. We've plundered countless treasures and sent many a scallywag to Davy Jones' locker. Arrr!
});

Because tokens are streamed incrementally from OpenAI, the chat() method returns an RxJs Observable which allows you to subscribe to the current response as tokens arrive on the client.

To receive the final response as a Promise, you use the lastValueFrom function in RxJs:

import { lastValueFrom } from 'rxjs';

const response = await lastValueFrom(
squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.chat('Tell me about yourself.')
);

Chat options

In addition to a prompt, the chat function can accept an optional options parameter. This parameter provides various properties for configuring the chatbot. To view a full list of available options and their default values, refer to the API reference documentation.

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.chat('Tell me about yourself.', {
chatId: 'my-chat',
maxTokens: 4096,
disableHistory: true,
/* ... */
})
.subscribe(/* ... */);
Note

By default, chats support conversational history. The history is tied to the user's current session, and is reset upon page reload.

Securing your data

Securing your data is vital when using the Squid Client SDK to create profiles and enable chatting. The AI chatbot's profiles and the chats conducted with them can contain sensitive information, so it's crucial to restrict access and updates to prevent unauthorized usage or modification.

To learn about securing your AI Chatbot, check out the Securing the AI Chatbot documentation.