pwshub.com

Using Chrome AI to Rewrite Text

Earlier this month, I discussed how Chrome's upcoming built-in AI support was adding new features specifically tailored to certain use-cases. In that post, I looked at the Summarizer API. For today, I decided to take a look at the rewriter API.

As a quick reminder, this is very early on, and if you want to try this yourself, you should hit the sign-up form and read the intro post from the Chrome folks first. Obviously, everything I'm going to show below probably will, almost certainly will, change before shipping.

Ok, with that out of the way, let's talk rewriting, specifically, how the Chrome API operates. Given a set of source input, the API can shorten, or lengthen the input, as well as help modulate the level of formality of the text. Another example would be to, well not "dumb down", but simplify text for audiences of different technical abilities.

One of the reasons this excites me is the specific use-case of shortening content. I feel like this is something I've hit many times in the past. I'll be using a form on the web, enter some text, and then be told I need to shorten my input. (By the way, if your form doesn't provide real-time feedback about this, that's a UX issue you need to correct. See my post from last year on how I did this with Alpine as an example.)

As a way to see this in action, I built a quick demo that provides a text area for input and then provides a shorter version of your text:

Screenshot of the application I built, showing a text field with a block of input, a button 'Make Shorter', and result text.

In case it is difficult to read in the screenshot, my input was my typical bio:

Raymond Camden is a Senior Developer Evangelist for Adobe. He works on the Acrobat Services APIs to build powerful (and typically cat-related) PDF demos. He is the author of multiple books on web development and has been actively blogging and presenting for almost twenty years. Raymond can be reached at his blog (www.raymondcamden.com) or via email at raymondcamden@gmail.com.

Thrilling, right? You would definitely hire me as your next GenAI Evangelist I bet! After using the built-in AI service to shorten it, the result was:

Raymond Camden is a Senior Developer Evangelist for Adobe. He's the author of multiple books on web development and has been blogging and presenting for nearly 20 years. He can be reached at his blog (www.raymondcamden.com) or via email at raymondcamden@gmail.com.

I got to say, I think this is the most impressed I've been so far with these proposed APIs. For the heck of it, I took this output and fed it back in. The result was:

Raymond Camden is a web development evangelist for Adobe. He's the author of several books, blogs, and presents regularly. You can contact him at his blog or email.

To be honest, that's dang good. And because I'm crazy, I did it again:

Raymond Camden, Adobe web development evangelist, writes books and blogs and gives presentations. You can contact him at his blog or email.

Again, great result. It would be stupid for me to do it again. So I did it:

Raymond Camden writes books, blogs, and gives presentations. You can contact him at his blog or email.

At this point we are down to 17 words. Let's do it again:

Raymond Camden blogs, writes, and presents. Contact him at his blog or email.

Just 13 words. And yes, I did try again and it wasn't able to make it shorter. In theory it could have gone with "Mr. Camden", but honestly, I'm pretty pleased with the iterations.

Let's look at the code. I'm going to 'paraphrase' a bit from the Alpine.js bits. After you determine if the browser supports it, you can then create a session:

session = await window.ai.rewriter.create({
	sharedContext:'You help shorten text',
	length:'shorter'
});

I feel like sharedContext would normally be more tuned to a particular kind of content. So for example, if this were helping writers on a site dedicated to cats, the context could be modified to discuss that. For length, you have values for shortening, lengthening, or keeping it as is. There is also a 'tone' setting that lets go for more formal and casual.

Once you have that, this is all you need to do:

let newText = await session.rewrite(input);

And that's it. Incredibly simple. I will share the CodePen below so you can see the full code, but 99% of it is Alpine.js and, again, it won't work for you outside of Chrome Canary. That being said, I am curious what you think. Leave me a comment!

See the Pen window.ai - shorten by Raymond Camden (@cfjedimaster) on CodePen.

```

Source: raymondcamden.com

Related stories
2 weeks ago - I've looked at Chrome's on-device GenAI development a few times now, and as a feature it is moving pretty fast. In fact, that first post and my follow up both don't work anymore due to the API changing. I'm fine with that as I knew it was...
1 month ago - Google announced a while back their intent to experiment with generative AI in the browser itself. Personally, I think this could be a really good idea, but I'm really unsure as to how many other vendors would support it. With Edge being...
1 month ago - Stay organized with collections Save and categorize content based on your preferences. The...
1 day ago - Reusing code is an important part of software development. Instead of writing the same code again and again, developers can save time and effort by using code that already works. This not only speeds up the development process but also...
2 weeks ago - An employee recognition platform is a tool to create a workplace where employee’s efforts are seen and celebrated. These platforms turn the everyday moments of appreciation into a structured, visible, and impactful part of company...
Other stories
1 hour ago - Do you want to become a Microsoft 365 Certified Fundamentals professional? The MS-900 certification is your gateway to demonstrating a solid understanding of Microsoft 365, including its productivity apps, intelligent cloud services, and...
1 hour ago - If you want to improve your skills in machine learning and MLOps, we have a great course for you. We just posted a comprehensive End-to-End Machine Learning course on the freeCodeCamp.org YouTube channel. It is designed to equip you with...
4 hours ago - During a research session, you often uncover little bits of information that you eventually bring together to form a hypothesis. […] The post An overview of participatory design research appeared first on LogRocket Blog.
5 hours ago - Tauri is an excellent toolkit for building lightweight, secure, and cross-platform desktop applications. Learn more in this guide. The post Tauri adoption guide: Overview, examples, and alternatives appeared first on LogRocket Blog.
5 hours ago - Customer validation is the step in a customer development process where you validate your solutions against customer needs and expectations. The post Customer validation: Building consistent and repeatable sales appeared first on...