Demo using string replacement worked - now doesn't - unsure why

32 views
Skip to first unread message

Raymond Camden

unread,
Oct 24, 2025, 9:07:30 AM (13 days ago) Oct 24
to Chrome Built-in AI Early Preview Program Discussions
Last year, I built a demo (https://www.raymondcamden.com/2024/07/10/creating-a-generic-generative-template-language-in-google-gemini) where I asked Gemini to take a string, look for tokens {{ foo }}, and replace the value with a random instance of the token. So {{ noun }} would pick a noun, {{ color }} a color, and so forth. I even got it so it could reuse values: {{ name | yourname }} would pick a random name, and {{ yourname }} later in the string would re-use it. 

I thought I'd take a stab at doing it on device, and honestly, it worked great! 


I built this yesterday morning. Yesterday afternoon I was about to start a blog post on it, but when I ran it again, it completely, mostly, failed. Given the sample input, it would change {{name:myname}} to {{myname}}, and the other tokens wouldn't get replaced... about 90% of the time. Every now and then one gets replaced.

Is there anything in particular that would have caused this to be near perfect and then near 100% failure? (I've restarted Chrome of course, a few times.)

Thomas Steiner

unread,
Oct 24, 2025, 10:28:06 AM (13 days ago) Oct 24
to Raymond Camden, Brecht De Ruyte, Chrome Built-in AI Early Preview Program Discussions
Hey Ray,

This looks like a classic situation where you should split the responsibilities: JavaScript is good at dealing with template strings, and AI is good at creative suggestions, like "suggest me a playful sounding color name". I'd just use specific prompts for each of your gaps and fill those one by one (serially, not parallely, as the implementation doesn't currently support parallel prompts well). @Brecht De Ruyte hit a similar situation recently in his case study, where the biggest realization was exactly that, splitting the logic in what AI is good at and in what JS is good at.

Cheers,
Tom  

--
You received this message because you are subscribed to the Google Groups "Chrome Built-in AI Early Preview Program Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chrome-ai-dev-previe...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chrome-ai-dev-preview-discuss/7b28cf9a-819f-48b3-8ccd-d3b1db882efen%40chromium.org.


--
Thomas Steiner, PhD—Developer Relations Engineer (blog.tomayac.comtoot.cafe/@tomayac)

Google Spain, S.L.U.
Torre Picasso, Pl. Pablo Ruiz Picasso, 1, Tetuán, 28020 Madrid, Spain

CIF: B63272603
Inscrita en el Registro Mercantil de Madrid, sección 8, Hoja M­-435397 Tomo 24227 Folio 25

----- BEGIN PGP SIGNATURE -----
Version: GnuPG v2.4.8 (GNU/Linux)

iFy0uwAntT0bE3xtRa5AfeCheCkthAtTh3reSabiGbl0ck
0fjumBl3DCharaCTersAttH3b0ttom.xKcd.cOm/1181.
----- END PGP SIGNATURE -----

Raymond Camden

unread,
Oct 24, 2025, 10:32:36 AM (13 days ago) Oct 24
to Thomas Steiner, Brecht De Ruyte, Chrome Built-in AI Early Preview Program Discussions
Yeah, I definitely considered that... was just kinda hoping there would be a magic bullet solution here. Like I said, I swear, it was *perfect*. Sigh. Thanks for the sanity check.
--
===========================================================================
Raymond Camden

Email : raymon...@gmail.com
Blog : www.raymondcamden.com

Raymond Camden

unread,
Oct 31, 2025, 10:58:59 AM (6 days ago) Oct 31
to Chrome Built-in AI Early Preview Program Discussions, Raymond Camden, Brecht De Ruyte, Chrome Built-in AI Early Preview Program Discussions, Thomas Steiner
FYI, it works mostly ok, and is faster than I thought. This is a non-interactive example, will make it a proper app later:

Thomas Steiner

unread,
Oct 31, 2025, 11:11:23 AM (6 days ago) Oct 31
to Raymond Camden, Chrome Built-in AI Early Preview Program Discussions, Brecht De Ruyte, Thomas Steiner
Nice progress. You can likely simplify your string processing by making use of tagged templates, and more specifically the tag function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates.

Thomas Steiner, PhD—Developer Relations Engineer (blog.tomayac.comtoot.cafe/@tomayac)

Google Spain, S.L.U.
Torre Picasso, Pl. Pablo Ruiz Picasso, 1, Tetuán, 28020 Madrid, Spain

CIF: B63272603
Inscrita en el Registro Mercantil de Madrid, sección 8, Hoja M­-435397 Tomo 24227 Folio 25

----- BEGIN PGP SIGNATURE -----
Version: GnuPG v2.4.8 (GNU/Linux)

iFy0uwAntT0bE3xtRa5AfeCheCkthAtTh3reSabiGbl0ck
0fjumBl3DCharaCTersAttH3b0ttom.xKcd.cOm/1181.
----- END PGP SIGNATURE -----

Raymond Camden

unread,
Oct 31, 2025, 11:14:35 AM (6 days ago) Oct 31
to Thomas Steiner, Chrome Built-in AI Early Preview Program Discussions, Brecht De Ruyte
omg - I completely forgot that part of the template string spec - and I've NEVER really imagined it being useful - now I do! Thank you. (I may ship with this, then blog a v2 with what you suggested.)

Raymond Camden

unread,
Oct 31, 2025, 11:22:52 AM (6 days ago) Oct 31
to Thomas Steiner, Chrome Built-in AI Early Preview Program Discussions, Brecht De Ruyte
Actually... I'm not sure that would work. In the examples given, there's always a value for the tag:

const person = "Mike";
const age = 28;
// myTag defined here
const output = myTag`That ${person} is a ${age}.`;

But in my case, I need the tag to not exist, ie: "Hello {{ name }}" where name isn't an actual value. So if I were to use:  someFunc`Hello ${name}`, I assume someFunc would get an undefined value. 

Also, given that my input is dynamic, how would I do something like this:

let input = someTextField.value;
let result = someFunc` ... can I put input here?` 

Thomas Steiner

unread,
Oct 31, 2025, 11:34:26 AM (6 days ago) Oct 31
to Raymond Camden, Thomas Steiner, Chrome Built-in AI Early Preview Program Discussions, Brecht De Ruyte
I think the idea was more to get the gaps that you then need to fill. You would look at something like this:

function getGaps(_, ...gaps) {
  // Process the gaps.
}

I think this could work even if the variables aren't defined, but I don't sit in front of a computer right now. Maybe it's also just complicating a problem you've already solved. 😊 

Cheers,
Tom

Thomas Steiner, PhD—Developer Relations Engineer (blog.tomayac.comtoot.cafe/@tomayac)

Google Spain, S.L.U.
Torre Picasso, Pl. Pablo Ruiz Picasso, 1, Tetuán, 28020 Madrid, Spain

CIF: B63272603
Inscrita en el Registro Mercantil de Madrid, sección 8, Hoja M­-435397 Tomo 24227 Folio 25

----- BEGIN PGP SIGNATURE -----
Version: GnuPG v2.4.8 (GNU/Linux)

iFy0uwAntT0bE3xtRa5AfeCheCkthAtTh3reSabiGbl0ck
0fjumBl3DCharaCTersAttH3b0ttom.xKcd.cOm/1181.
----- END PGP SIGNATURE -----

Raymond Camden

unread,
Oct 31, 2025, 11:36:11 AM (6 days ago) Oct 31
to Thomas Steiner, Chrome Built-in AI Early Preview Program Discussions, Brecht De Ruyte
Going to ask the good Dr Axel - it's an interesting Q outside of this particular use case.
Reply all
Reply to author
Forward
0 new messages