AI Utilities
Toolbox of functions for calling OpenAI and Anthropic models including ChatGPT and Claude in Snowflake SQL
Overview
Cybersyn AI Utilities is a toolbox of functions for calling OpenAI and Anthropic models such as ChatGPT and Claude in Snowflake SQL. Functions to clean and process URLs and phone numbers within Snowflake queries are also included.
AI UDFs
The user is required to have an API key for the OpenAI or Anthropic functions
Utility UDFs
Unlike the AI functions, the phone number and URL parsing functions do not call external AI models.
Internally, Cybersyn uses these user defined functions to call out to AI tools and more accurately and consistently parse and match data across tables.
OpenAI Functions
The OpenAI functions allow you to call OpenAI models (e.g. ChatGPT) from Snowflake.
Function | Description |
---|---|
| Returns string response from OpenAI
|
Example
Returns:
Set Up Instructions
Create network rule to allow for external access:
Create secret with OpenAI API key:
Create external access integration:
Grant access for the application to use the api key and external integration (replace CybersynFunctionsAppAI with the installed app name):
Call stored procedure to enable native app to have external access to OpenAI API:
Anthropic Functions
The Anthropic functions allow you to call Anthropic AI models (e.g. Claude) from Snowflake.
Function | Description |
---|---|
| Returns string response from Anthropic
|
Example
Returns:
Set Up Instructions
Create network rule to allow for external access:
Create secret with Anthropic API key:
Create external access integration
Grant access for the application to use the api key and external integration (replace CybersynFunctionsAppAI with the installed app name):
Call stored procedure to enable native app to have external access to Anthropic API
Token Counter Functions
Functions that call external API to find number of tokens in the string. This can be used to estimate cost of the prompt.
Function | Description |
---|---|
| Returns number of tokens in the prompt
|
Example
Returns:
Set Up Instructions
Create network rule to allow for external access:
Create external access intergration
3. Grant access for the application to use external integration(replace CybersynFunctionsAppAI with the installed app name):
4. Call stored procedure to enable native app to have external access to OpenAI API:
Phone Number Parsing Functions
Clean and process phone numbers directly in Snowflake SQL. The user-defined functions (UDFs) allow users to easily extract phone number from a string directly within Snowflake queries, which can be particularly useful for data cleaning and analysis tasks related to contact information.
The UDFs are all callable in Snowflake SQL and take two parameters:
String with a phone number
Country code (optional parameter, default value is set to 'US')
Function | Description |
---|---|
| Returns phone number in a national format if it is possible to extract, otherwise result is null |
Examples
URL Parsing Functions
Clean and process URLs directly in Snowflake SQL. The user-defined functions (UDFs) allow users to easily extract website parts from URLs within Snowflake queries, which is particularly useful for data cleaning and analysis tasks related to clickstream and web traffic data.
Each UDF takes a single parameter, URL, which should be a string.
Function | Description |
---|---|
| Returns the domain with the suffix or top level domain without any URL parameters or subdomains. |
| Returns only the core domain text without any subdomain, parameters, suffix or top level domain. |
| Returns only the public suffix domain. Public suffixes include suffixes under which users or companies can register domains. |
| Returns the domain in addition to the subdomain. The subdomain “www” is excluded from results. |
| Returns only the subdomain portion of the domain. |
Internally, Cybersyn uses these functions to extract portions of URLs to more accurately and consistently parse and match domains across datasets. Use these functions to clean your own data or to easily join your internal data to Cybersyn’s web data.
Examples
Parse the domain details for the following url: https://chat.openai.com/?model=gpt-4-browsing
Releases & Changelog
Disclaimer
Your use of OpenAI is subject in all respects to the terms and conditions of OpenAI set forth here. Your use of Anthropic is subject in all respects to the terms and conditions of Anthropic set forth here and here. The URL function is built off of a library licensed from here.
Cybersyn does not have any logging or data collection mechanism as part of your usage of our function.
Cybersyn is not responsible for any use you may make of these services or any result derived therefrom. Contact support@cybersyn.com for questions.
Last updated