Last active
December 5, 2024 11:53
-
-
Save ExcelRobot/4319e3c81f6fc8145aa845e908aeacb0 to your computer and use it in GitHub Desktop.
RegEx Expression From Generative AI LAMBDA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Name: RegEx Expression From Generative AI (RegExFromAI) | |
Description: Given a natural language input, uses Excel Labs' Generative AI function to return a RegEx expression. Optionally uses Excel's new REGEXEXTRACT function to check whether the RegEx generated works on a provided example and expected value. | |
Parameters: | |
input - natural language prompt like: extract email address | |
example - optionally provide some example data to help train the AI | |
expected - optionally provide the expected value to be returned given the example data | |
Source: Excel Robot (@ExcelRobot) | |
*/ | |
RegExFromAI =LAMBDA(input, [example], [expected], LET( | |
\\LambdaName, "RegExFromAI", | |
\\CommandName, "RegEx Expression From Generative AI", | |
\\Description, "Given a natural language input, uses Excel Labs' Generative AI function to return a RegEx expression. Optionally uses Excel's new REGEXEXTRACT function to check whether the RegEx generated works on a provided example and expected value.", | |
\\Parameters, { | |
"input","natural language prompt like: extract email address"; | |
"example","optionally provide some example data to help train the AI"; | |
"expected","optionally provide the expected value to be returned given the example data" | |
}, | |
\\Source, "Excel Robot (@ExcelRobot)", | |
_SystemPrompt, "You are a Regex robot. Given a natural language input, you will respond with ONLY a valid RegEx expression. Do not return your response in quotes. " | |
& IF( | |
ISOMITTED(example), | |
"", | |
"You will be given Example Data of the kind of data your RegEx expression will be processing. " | |
) | |
& IF( | |
ISOMITTED(expected), | |
"", | |
"You will be shown Expected Output of what the expected return value of your RegEx expression might look like. Use the natural language Input to determine the logic of the RegEx and only use the Expected Output to check your work." | |
), | |
_UserPrompt, "Input: " & input & CHAR(10) | |
& IF(ISOMITTED(example), "", "Example Data: " & example & CHAR(10)) | |
& IF(ISOMITTED(expected), "", "Expected Output: " & expected & CHAR(10)) | |
& "Regex Expression: ", | |
_RegEx, LABS.GENERATIVEAI(_SystemPrompt & CHAR(10) & _UserPrompt), | |
_Result, IF( | |
OR(ISOMITTED(example), ISOMITTED(expected)), | |
_RegEx, | |
IF( | |
IFERROR(REGEXEXTRACT(example, _RegEx), "") = expected, | |
_RegEx, | |
"RegEx didn't work as expected: " & _RegEx & ". Recalc to try again." | |
) | |
), | |
_Result | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installing Excel Labs and Configuring the Generative AI Feature
Step 1: Installing Excel Labs
Open Excel:
Launch Microsoft Excel on your computer.
Access the Add-ins Store:
Insert
tab in the ribbon.Get Add-ins
.Search for Excel Labs:
Excel Labs
.Add
button next to Excel Labs to install it.Launch Excel Labs:
Insert
tab.Excel Labs
to open it.Step 2: Configuring the Generative AI Feature
Getting an OpenAI API Key
Sign Up or Log In:
Access the API Key:
Configuring the API Key in Excel Labs
Open Excel Labs:
Insert
tab and click onExcel Labs
.Navigate to Settings:
Settings
gear icon.Enter the API Key:
Generative AI
settings section.Save the Configuration:
Save
orApply
to store your API key configuration.Step 3: Using the LABS.GENERATIVEAI Function
Insert a Formula:
=LABS.GENERATIVEAI("Your prompt here")
.Run the Function:
Enter
. Excel Labs will use the configured API key to process your prompt and return the generated output.Additional Tips
API Usage:
Be aware of the usage limits and costs associated with the OpenAI API. Monitor your usage in the OpenAI dashboard.
Experiment with Prompts:
Try different prompts to see how the generative AI responds and tailor it to suit your needs.
By following these steps, you should be able to install Excel Labs, configure the Generative AI feature, and start using it effectively within Excel.