CustomerAI Meets Serverless - Connect to thousands of integrations with natural language

Learn more about Segment’s first CustomerAI trial to enable the engineers to activate the customer data in minutes using Segment Functions.

By Gagan Sikri, Himanshu Patidar, Doosan Baik

In June, Twilio announced CustomerAI - bringing the power of large language models (LLMs) with the rich customer data that flows through Twilio’s Customer Engagement Platform to help companies unlock the potential of their customers. 

Today, we’re excited to introduce a new set of skills for CustomerAI – the ability to connect your data to thousands of integrations, based on natural language. CustomerAI will now write the code for new integrations based on a high-level description and requirements, turning what would have previously been weeks of integration coding into a 3-sentence prompt.

customerai-serverless

Functions Writer

image3

But that’s not all. CustomerAI will also make the process of maintaining your code easier with its new Functions Analyzer capabilities. Functions Analyzer summarizes your code and extracts a simple description of what it does, reducing the “cold-start” problem for new developers to be able to contribute and maintain functions.

Functions Analyzer

image1

Segment Functions <3 CustomerAI

Segment Functions let you bring new types of data into Segment and activate your data to new tools with just a few lines of JavaScript, without any additional infrastructure. You can even use Insert functions to transform data before it reaches the tools you are using downstream. 

Since introducing Functions, we have seen developers push the bounds of what was possible with customer data. Segment Functions processes 40+ billion messages across 4,000 functions every month, and the number is growing every day. Our developer friends find it so easy to write and deploy the codes to bring and activate the data. 

Functions unlock all kinds of advanced use cases: integrations, enrichment, filtration - you name it! However, they require code, and not everyone can (or wants!) to write code. So we asked ourselves, what would it look like if you gave the flexibility and scale of serverless functions to everyone within an organization using CustomerAI?

How is CustomerAI helping Segment Functions?

When working with Functions, there are two common challenges we’ve come across:

  • Translating logic into code - a developer understands what the requirements are, translates those needs into code, and considers non-functional requirements like, "how many retries should this system attempt?"

  • Maintaining code across a large team - inheriting another developer’s code can be a puzzle in itself. Some Functions can be hundreds of lines of code. And when that code was written by someone else who’s not next to you anymore; you’re tempted to abandon them and re-write the new ones. 

As a developer-first company, we realize the best code can sometimes be the code you never have to write and maintain. 

So today we’re introducing Functions Writer and Functions Analyzer.

Functions Writer

Functions Writer is your AI-powered coding assistant, designed to supercharge the development of custom integrations, enrich, and transform on Segment Functions. You can simply provide a prompt outlining your use cases; the Writer will suggest structured examples or craft entire Functions following Javascript best practices. It's your shortcut to discovering alternative solutions, writing efficient code, exploring new APIs, and validating marketing use-cases swiftly.

Powered by OpenAI Codex under the hood, Functions Writer is engineered to understand and generate JavaScript code with precision. It combines insights from your workspace catalog usage and configurations, Segment's extensive functions examples and templates collection, and documentation to deliver personalized and context-aware code suggestions, ensuring optimal solutions for your use cases.

Prompt Used (Input to OpenAI Codex):

A function that is used to send requests to Amazon DSP. It first checks if an access token exists, and if not, it fetches one using a refresh token. It then sends a request to Amazon DSP, and if the access token is expired, it will attempt to refresh it and retry the request up to 3 times. If the request fails after 3 attempts, it will throw an error. 

Functions Analyzer

Functions Analyzer is your AI-powered copilot to simplify code maintenance. When prompted, Functions Analyzer analyzes your code and generates a clear summary of its functionality and areas for optimization. Imagine having a second set of eyes that not only understands your code but also suggests optimizations, ensuring every line you write is efficient and cost-effective. The result? Quicker function builds, simpler code management, and significant savings in computation time and costs.

Under the hood, Functions Analyzer is powered by OpenAI Codex, which has broad knowledge of how the developers write and use codes. It draws context from Segment's vast collection of example Functions, documentation, and JavaScript best practices.

Analysis from Functions Analyzer (Output from OpenAI Codex):

Overview

The above code is an asynchronous function that is used to send a request to Amazon DSP. It first checks if the access token is expired, and if so, it refreshes the token using the refresh token. It then sends the request to Amazon DSP, and if the request fails, it will retry up to 3 times. If the access token is expired, it will retry up to 3 times. 

Detailed Summary

  1. The isAccessTokenExpired() function checks if the response status is 401, which indicates that the access token is expired. 

  2. The isRetriable() function checks if the response status is 429 or greater than 500, which indicates that the request should be tried.

  3. The fetchAccessTokenUsingRefreshToken() function uses the refresh token to get a new access token. It retires the request up to 3 times if the response is not successful. 

  4. The sendRequestToAmazonDSP() function sends a request to Amazon DSP using the access token. It retires the request up to 3 times if the response is not successful. If the response indicates that the access token has expired, it will attempt to refresh the access token and retry the request. 

  5. The onIdentify() function is the main function that is called when the class is invoked. It fetches the external IDs from Personas, checks if any of them are IDFAs and if so, sends a request to Amazon DSP to add or remove the user from the audience. 

Ensuring Trust in CustomerAI

While aiming for the correctness in code through the insights gathered from your workspace, we treat your customer data privacy with the utmost importance. To do so, we are building CustomerAI products based on the fundamental principles of Transparency, Responsibility and Accountability. Moreover, our AI nutrition facts aim to give consumers and businesses a more transparent and clear view into ‘what's in the box’ for our CustomerAI products, especially around how their data is being used.

label-functions-writer

In a future blog post, we will dive deeper into the ‘Trust’ layer of CustomerAI. We are excited to share our journey to earn trust on CustomerAI from consumers and businesses soon. Stay tuned! 

Ready to get your hands on it?

We will be introducing Functions Writer & Functions Analyzer in pilot over the coming weeks. We're eager to gather feedback to make these features as intuitive and effective as possible. Your insights will play a pivotal role in training our models to be contextually aware and precise.

Looking ahead, we’re excited about the ways in which CustomerAI will change the game for customer data. We’ll be introducing more capabilities that empower developers and data teams to bring more value out of their customer data quickly and safely. Great customer engagement depends on great customer data, and CustomerAI is emerging as a powerful tool to collect, unify, and activate customer data. 

Interested in becoming the first developer supercharging the customer data with the Segment Functions and CustomerAI? Schedule a demo now.

Test drive Segment

Test drive Segment CDP today

It’s free to connect your data sources and destinations to the Segment CDP. Use one API to collect analytics data across any platform.

Recommended articles

Loading

Want to keep updated on Segment launches, events, and updates?