First, let me start with a correction to Tuesday’s post: the hard 30 second limit for time outs appears to be just in Preview Mode for Integration Procedures. A grateful thank you to a friend who looked into this for me! So calling Integration Procedures from OmniScript should work fine even if OpenAI doesn’t fully respond until well over 30 seconds.
That being said, there are still some limits to just using Integration Procedures and OmniScript to build out our integrations. The two real pain points I’ve felt are:
As you want to substitute more and more data into ever more complex prompts, using a Set Values as a templating tool becomes unwieldy. The JSON properties editor that is not built for that sort of thing, and
Sometimes it takes a lot of tries at a test-revise cycle to get your prompt to return the results you want. Constantly editing and updating prompts in OmniScript can get tedious very quickly.
Let’s up our prompt engineering game a bit and solve those problems.
In today’s post I’m going to introduce a more elegant way of working that ameliorates both of those pain points. It doesn’t mean what we’ve done before is invalidated; rather, it builds upon that to make things even easier.
We’re going to use a contrived CPQ demo to illustrate this process I’ll call ChatCPQ™1. In this ficticious example, people can buy widgets in primary and secondary colors. If you buy widgets in a secondary color you must also buy 2 corresponding widgets in the primary colors that make up the secondary color2.
Can I color you interested and entice you to subscribe? It’s a rule of the Substack CPQ.
We’re going to define the rules in ChatCPQ’s prompts that has ChatGPT analyze orders for correctness and give us a report. It seems pretty simple now, when stuff is working, but trust me it took a bit of effort to finesse the prompts. Had I done all that testing and revising by editing Set Values statements it would have been most unproductive.
Instead, I broke out the part of testing and revising the prompts into a specialized application. Once the prompts were perfected3, they could be dropped back into Salesforce.
Because I like flowcharts4, I give you a visual representation of the overall process:
On the left is the process of building a prompt. It’s focused on allowing us to quickly edit the prompt and test a new version with minimal fuss. On the right is the process of building an OmniScript. It’s focused on building the UI and allowing us to drop in an already built integration to ChatGPT5. The lines between the two boxes indicate the natural bouncing back and forth you’ll do between the two.
Today’s post is going to focus on the left hand side, which we’ll start to play with now!
Introducing the OS Prompt Editor notebook
Let me introduce you to an incredible free tool: Google Colab.
This allows you, for free6, to host Python programs (called notebooks) in Google’s cloud and make it easy to share them with others. It’s perfect for the kind of uses here, where I’m sharing a Python program with you and I have no idea if you have Python or an IDE installed: it doesn’t matter, it’s all running in the browser and in the cloud.
What’s really neat is that when you go to my notebook, you get a copy of my source and are free to make changes and/or run it there. No download, no installation, just click the URL for the notebook and you’re all set. So (assuming you have a google account?) all you need to do is navigate here:
https://colab.research.google.com/drive/1Cc0aev-Ro9atCsYiH_d0VhgjVHNPzrL2?usp=sharing
The first thing you want to do is File → Save a copy in Drive so you have your own copy.
If you want to see what the heck it actually does before going further, select the Run All command from the menu:
The program will stop and ask you for your OpenAI API key. It does not save this anywhere (unless you rewrite the code) other than in your session memory, so it’s safe to paste it in. That looks like (with my key blurred out):
When it finishes (how long depends upon how perky OpenAI is feeling today), you’ll see this at the end7:
Aha, our order was not valid, the customer needs one more green widget!
As a last step, the notebook downloads the current versions of your prompts in a .zip file if you wish.
Hey, that analysis is pretty impressive, eh? Think I got it to work on the first try? Hell no. That’s why I have this notebook!
There’s (somewhat) helpful instructions throughout the notebook, and because you get your own copy, you can hack and chop it to your heart’s content while you figure out how it works. If you break it irretrievably, you can just grab another copy of mine.
Let me walk you through the sections of the notebook:
Welcome, which gives a quick idea what this is.
Imports / Setup, which:
Installs the OpenAI interface library
Imports the Python libraries we’ll need
Inputs, which consist of:
Your OpenAI API key
A copy of the Data JSON from the OmniScript you will eventually hook up to ChatGPT (in the default case, it’s from my test widgets one; you’ll get a copy of their DataPacks a few posts from now).
The system prompt template, which defines the rules of what you want ChatGPT to do.
The user prompt template, which expresses the order we want ChatCPQ to validate.
Execution, which:
Populates the templates with the data from the Data JSON (i.e., the data in your OmniScript).
Calls ChatGPT and prints the response.
Bundles up the templates (and .xml files you’ll need later on) into a .zip file and downloads it for safe keeping.
OK, that’s a lot to digest. Most of it is just simple Python code, but on Tuesday we’ll talk a bit more about how it works especially the templating we’re using; later we’ll show how we can get Salesforce to do the same thing making our prompt templates portable between this Python notebook and Salesforce.
Don’t hesitate to share this newsletter with your friends, colleagues, and random strangers.
I’m about 80% not serious about this name, but the 20% is whispering in my ear that it’s a land rush out there.
Color theory for the win!
For these kind of applications, “It works well enough to get by” is exactly the same thing as perfection.
And OmniGraffle, one of the best graphics tools I’ve ever seen.
There’s some foreshadowing about something called “promptkit”, which is a tool I’ve written to handle all the templating and integration between Salesforce and ChatGPT.
Yes, I like free.
I’ve made a few improvements since the screen shots were taken, but nothing major.