Skip to main content

AI functions

AI functions define how a Squid AI assistant should handle certain queries.

When configuring your AI assistant, you might find that certain questions require specific responses that are difficult to configure through instructions. For example, you might have industry-specific formulas that the model isn't familiar with. Or you may have customer questions that require a very specific wording in response. In these cases, you can incorporate this functionality through a Squid Service function with the @aiFunction decorator. You can add these functions upon creation of the assistant, allowing you to customize each assistant with the functionality it requires.

AI functions take a description parameter, which is a string describing the function. This description is how the AI assistant determines when to use the function, so ensure the description is clear and informative.

The following example uses the @aiFunction decorator to define a function that an assistant can use:

class AiService extends SquidService {
@aiFunction<{ shipName: string }>(
'This function returns the list of pirates in a ship'
)
async listPiratesInAShip(params: { shipName: string }): Promise<string[]> {
console.log('Got ai function call to listPiratesInAShip', params);
return ['Jack Sparrow', 'Black Beard'];
}
}

To add the function to an AI assistant, include its name when creating it:

const assistantId = await createAssistant(
'YOUR_ASSISTANT_NAME',
"YOUR ASSISTANT'S INSTRUCTIONS",
['listPiratesInAShip']
);

You can find out more about configuring AI assitants in the Squid AI assistant documentaiton