See Sanity in action 👀 Join us for a live product demo + Q&A →

Incorporating AI tools like ChatGPT and using with Document Actions & custom input components

3 replies
Last updated: Feb 11, 2023
has anyone figure out how to incorporate chatgpt with sanity v3? i found myself using notion AI now to draft then port over to my sanity v2 at the moment.
Was thinking migrating v3 would be worth it if theres a UX upgrade (not just tech upgrade with minimal ux impact). 2 bigs hesitant now is this and integrated newsletter (ala ghost)
Feb 11, 2023, 5:43 AM
Incorporate in what respect?
I ran some tests a few days ago with a database my client has for image tagging to use the Ada model to get embedding scores, so that we could store the matrices and use pg_vector to recommend related topics by tag.

But as I was doing it, it occurred to me that when we add products into Sanity we might be able to fetch the embeddings in a similar way on publish / save using
Document Actions and then wherever I needed to send that info do could compute it.
We're doing some things with the Cloudinary API directly, for example, and Cloudinary's npm package does not want to be used at all client-side, so I had to make an API route in our app to run the stuff, and have our Studio go fetch things from that app.

I'm sure there are more clever ways to go about it, but for right now we get a lot of mileage out of basic custom input components -- we're still in v2 but there are a lots of
guides to help you wade past the boilerplate . And one nice thing about v3 is that you really only have to focus on the aspects of fields and inputs that you actually want to change so you don't have to bring all of that in just to adjust one or two things, or set up a small additional function to load info in.
It's always been a composable environment, but now it's leaner and easier to achieve those customizations.

What did you have in mind, specifically?
Feb 11, 2023, 5:54 AM
first of thanks for the detailed reply
user S
so ill probably mock it up and share it in few days (im a full time designer, hobbyist coder) hence quite limited in technical skill to implement.

one idea is to have grammarly like ux that helps when needed (secondary in terms of ux hierarchy).

another idea which is probably more viable im imagining an input for chatgpt to help outline or draft that either used directly in the content or feeds a body/description input field.

I hope these makes sense
Feb 11, 2023, 6:01 AM
No problem!
As it happens, the same library you can use on your site or in your apps to pull down and use Sanity content can be run within the studio itself. Also, the portable text editor's content can be accessed in such a way as to flatten down to pure, raw text.

I could see a reasonably straightforward mechanism where someone enters a prompt into one field and you convert the response back into a portable text format to inject it into the page.

On a lark I just wrote a line of HTML to ChatGPT and asked it to convert it to Portable Text format so while tools exist to do that there's a chance you even get the response pre-formatted to only have to set it for that field.

Another exciting prospect is to pull from multiple parts of your studio to arrive at a conclusion.

For example, you could pull in every field on a current product page, hit a button, and send that along with a message that essentially says, "Write some exciting content to summarize this product based on these details" and get something that's highly likely to be reasonable right out of the gate.

I find it personally astounding what context it can arrive at from inference.

I just bought new eyeglasses and they wanted me to sign up for an account on their website to track my order coming in for pickup. in the logged in area, it had a bunch of numbers and initials I didn't understand that it said was my prescription information. I copied the list of seven lines of info, pasted it into the AI bot, and it told me that my sight wasn't actually all that bad (true) and that my right eye had an astigatism (a word I never mentioned, and also true).

I am no Sanity expert (official support staff have a different badge; I volunteer some time here to lend a helping hand) but I do have a decent amount of experience at this point and I have actively interacted with the APIs of some of these AI tools. After you've got a mockup going, and clear actionable idea of what you'd like to see, follow up here and I will do my level best to guide you through creating something useful to that end!
Feb 11, 2023, 2:09 PM – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.