***UPDATE*** The Edit endpoint may be being decommissioned by OpenAI. There is now a ChatGPT v3.5Turbo Connector that supercedes this version, available here...
https://community.alteryx.com/t5/Community-Gallery/OpenAI-ChatGPT-3-5Turbo-Completions-Connector/ta-...
INTRO
This macro will allow you to send data to OpenAI's ChatGPT AI.
The ChatGPT AI has multiple API (Application Programming Interface) functions or "endpoints", for generating images, writing code, answering questions and editing text. This Connector points to the Edits endpoint, which takes a natural language input string, instruction string, and tries to apply the instruction to the input as an edit.
Alteryx is a very strong tool for preparing and cleaning data, and this Edits endpoint is something that many Alteryx users should be interested in.
With Alteryx, you can prepare a set of data you need to edit or clean, and tag on a standard instruction such as "Fix the spelling", and get the fixed data returned to you for later processing. You can also make repeated seqential calls, so one call to the AI might fix the spelling in some text, and another might be used to correct grammar or punctuation. I do not yet know the limits to what this AI can do in terms of editing, but this connector will allow you to experiment with it.
QUICK START
To use this macro, you first need to go to...
https://openai.com/api/
... and hit the "Sign Up" button. Here, you will need to create a new API account. Then you create an API Secret Key, and you will be given a Personal Organisation ID. The macro will have two text boxes where you enter your Key and OrgID. Once the macro has the identifying Key and OrgID, very little else is required.
The main macro is called OpenAI_ChatGPT_Edits.yxmc. There are other macros in the package. These are required but can be ignored, they are sub components of the main macro. To use the macro, open the yxzp file and choose to save the expanded files somewhere you will find them easily. As with any other macro, right click on the canvas and "Insert Macro", and then browse to where you expanded the yxzp file to, find the OpenAI_ChatGPT_Edits.yxmc file and select that.
For input to the macro, all you have to provide is a record ID, input string and instruction string. The other variables are optional, and you can ignore them initially.
The Record ID is just an Int32 value, and the RecordID tool can quickly create this for you. This allows you use a Join tool to hook your responses to your initial prompts, if you wish to process the responses in downstream flows or systems.
The input string is an instruction or phrase in normal English, and this is the string you would want to cleanse or change. The instruction string is also a phrase in normal English, such as "Correct the spelling" or "Capitalise all proper nouns". You do not have to say please, but I was tempted.
Of course, the beauty of Alteryx is that you can build multiple input strings (one per record), and append multiple instructions for each string, if required, and even set up multiple sequential calls to the AI so that you have fine control over the editing process.
IN DEPTH GUIDE
The link below details the values you can send to the AI Edits endpoint.
https://platform.openai.com/docs/api-reference/edits
Here are the variables that the macro requires you to provide...
- RecordID (REQUIRED) (Int32); A simple record ID so that you can join response records back to your input records.
- Input (REQUIRED) (String); The text that you wish to edit or correct, effectively your data.
- Instruction (REQUIRED) (String); A text instruction for how the AI should edit your data.
Here are the variables that are optional...
- Temperature_0to1 (OPTIONAL) (Double); Temperature is a value between 0 and 1, that reflects how "creative" you want the AI to be. If you are engaged in serious factual work, 0 is the suggested value, should produce deterministic repeatable results, and this is the macro default value. If you want the AI to write jokes or lyrics, or be a bit scatty and flighty, you can increase this value up to 1.
- ResponseResults (OPTIONAL) (Int32); You can ask the API to give you multiple replies with this value. If you use 0 for Temperature_0to1, then each reply will probably be the same, so this value defaults to 1 for a single response. If you use a high temperature value like 0.9, each response might be different, so you could select the most appropriate or creative response from the selection of responses.
- Attempts (OPTIONAL) (Int32); ChatGPT is very popular is very busy and is in beta. As such it is sometimes busy, or it may crash. This Attempts value sets how many tries the macro should make to get a good response, and it defaults to 5 attempts per request. This is usually enough to ride over the minor temporary outages that occur, but you can raise this value if it is important for you to get a response for each prompt.
OPERATION
The main outer macro calls some submacros. If you copy the main macro, please remember to also copy the numbered sub-macros and DosCommand macro with it, or re-expand the package in your target folder. The macros has relative directory addressing, so they will attempt to call each other in the same workflow folder as the main outer macro.
EXAMPLE
Below is a screenshot showing an example flow.
Here we show 6 records, that each have at least one error. The Input field shows the data with the error, and the Response field shows the AI's correction attempt. Of particular interest here is that the AI can correct for quite sophisticated grammatical errors that depend on the context of the sentence.
Record 5 is corrected for Subject-Verb agreement, which means the AI has to understand that the verb "to be" should be conjugated for the subject "Profits" (plural) and not "Agricultural Industry" (singular), and it correctly edits the sentence so that "The profits earned by the agricultural industry is not high enough" to be "The profits earned by the agricultural industry are not high enough".
Record 6 also shows a sophisticated grammatical correction. The dangling modifier in the input has a qualifying clause added, to clarify the meaning of the sentence.
When I asked the AI to correct for such errors, I did not know if it could do it, and I do not know how far the AI's abilities extend. The nature of the AI means that it's capabilities are undocumented, and are potentially being improved with every new training pass. It is exciting to think that this is just the early days of such capabilities.
THROTTLING
Most API's do not have infinite resources, so they ask you to comply with a request rate. ChatGPT's rate is 20 requests per minute for this endpoint, for both free and paid usage.
OTHER OPEN-AI CONNECTOR
This connector is for ChatGPT Edits, and it takes your input string and tries to return a near-identical string with your edit applied. There is also a Completions endpoint that will attempt to answer questions, write poems, or tell you jokes, and we have a connector for this here...
https://community.alteryx.com/t5/Community-Gallery/OpenAI-ChatGPT-Completions-Connector/ta-p/1093372
SUMMARY
So, the most exciting and revolutionary new technology is available, and Alteryx can be used to immediately hook up to it and begin leveraging it. The amazing flexibility of Alteryx allows it to shape data to the requirements of a particular API, and process the responses back into your workflows and onward to downstream systems.
As new technologies come online, they will have their own API's, and Alteryx will be perfectly placed to connect data into these new systems to come. We all know that Alteryx is a simple but powerful toolkit for rapid development, so you know that if you invest in Alteryx, your investment will keep you in step with the revolutions to come that we cannot foresee.
Any problems with the macro or questions, please reply below. We would also be very interested in hearing about new use-cases and ways that this
CONTINUUM
This macro is the product of research by Continuum Jersey. We specialise in the application of cutting edge technology for process automation, applying Alteryx and AI tech for creative solutions. If you would like to know how your business could apply and benefit from Alteryx, and the agility and efficiency it provides, we would like to talk to you. Please visit dubDubDub dot Continuum dot JE , or send an email to enquiries at Continuum dot JE .
DISCLAIMER
This connector is free, for any use, commercial or otherwise. Resale of this connector is not permitted, either on it's own or as a component of a larger macro package or product. Please bear in mind that you use it at your own risk. ChatGPT is a beta demonstration of technology, and the services' performance and availability might be inconsistent. This macro connector is just an HTTP bridge to the service, and it will either get a 200-OK response or some kind of error. This connector macro is not responsible for the quality of the returned data. Please observe all usual data protection rules for your business in your jurisdiction when interacting with web services.
FIXES
- First version had a bug where zero characters, "0", were removed from the input strings incorrectly. Also, inbound text strings could potentially be truncated when escape characters were inserted to text strings. Both these issues have been resolved in the current version, released 4th April 2023 16:50 BST.
- Logo updated to include ChatGPT version 5th April 12:25 BST.