Skip to main content
    Quick Guide
    2 min read

    Incorporate AI into a Code function

    Code allows you to completely customize your functions; this includes being able to import external modules just as you would when writing a function outside of Klaviyo. Explore how the modules available for import can create unique customer experiences and make your functions even more powerful.

    The situation

    Beantown prides themselves on connecting with their customers. They know their customers, their preferences, and their habits, and they make sure their marketing reflects that.

    Beantown’s marketing strategy revolves around their casual, low-key tone. They often include jokes and puns in their copy which resonate with their customers and help differentiate them from other local coffee providers.

    ‍Beantown’s marketing team was playing around with ChatGPT and discovered its ability to write fun, short poems that can be completely customized. Instantly, they thought of including these poems in confirmation emails when VIP customers make purchases.

    Use the power of AI

    ChatGPT, which uses generative AI to craft responses to prompts, is a free service developed by OpenAI. The OpenAI module contains everything required to use ChatGPT. Read more about ChatGPT.

    This module can be imported in a Code function so that you can use OpenAI’s features, including ChatGPT, in your functions. It requires creating a private OpenAI key on OpenAI’s website.

    Custom poetry

    Beantown wrote a Code function that uses the OpenAI module. The function fires every time a customer places an order, and it uses GPT-3, the LLM that powers ChatGPT, to generate a short and fun poem customized to each order.

    They include this poem in their order confirmation emails to really drive home their voice, get people smiling, and keep their brand top of mind.

    Incorporate AI into a Code function
    Back to all resources