Friday, August 30, 2024

gptel: Mindblowing integration between Emacs and ChatGPT

ChatGPT and its LLM brethren have been a potent source of FOMO: the AI revolution is happening, and I feel like I'm forever late to the party. After getting comfortable with OpenAI's web interface and coding my own command line tool, I figured it was time to complete the trilogy by integrating an LLM AI into Emacs.

As with many topics, there were a number of available Emacs packages, and it wasn't immediately obvious which was 'the best.' And then I watched this (to me) blandly named YouTube video: Every LLM in Emacs, with gptel and was hooked.

This 17 minute video blew my mind. If you're remotely interested in emacs and LLMs, stop reading this post and go watch this video. Heck, watch it a couple of times. In it, the gptel package developer goes through the why and how of gptel, and demonstrates some next-level uses of this package.

So gptel is my answer for adding them magic of ChatGPT to Emacs. gptel can be used both interactively and programmatically. I've found the former capability let's me have a running conversation with an 'assistant.' I can get answers to coding, writing or any other question on my mind without having to leave Emacs. Score.

But interactive use is just the beginning. By leveraging gptel-request, it's possible to automate common patterns. For example, I can set the region to include a word and run bs-gptel-define-word. In a few moments, ChatGPT will come back with a definition, examples, synonyms and antonyms. Here's the definition this function reports for FOMO:

In some respects, this is hardly exciting. There are a number of dictionary services are already integrated into Emacs, so why bother hand coding another? Yet, using gptel has two advantages. First, by changing the prompt, I can easily adjust the output. For example, here's the FOMO definition with a prompt that asks for active and passive voice examples:

The other benefit of using gptel for definitions is that the universe of what's considered a definable term is far larger. For example, I can ask for the 'definition' of a CSS property box-sizing: border-box.

Heck, it even handles slang. Here's the definition of slang: what the sigma

This would have been handy when we were traveling with our nieces and nephew, and this phrase came up repeatedly.

Another example of automating a task by leveraging gptel is gptel-proof. This is an early attempt at coding a proofreading tool within Emacs. The package works by taking an arbitrary region of text and asking ChatGPT to fix the spelling and grammar. The result is embedded back in the original document, surrounded by the familiar version control conflict markers. For example, here's what I see when I proofread this paragraph.

By using the conflict markers, I can use M-x vc-resolve-conflicts, to interactively compare and adopt the improved text.

What I like about this approach is that I don't need to blindly accept the LLM's changes. By using ediff, I'm combining both the magic of AI with the magic of emacs, to make, well, more magic. It's magical. A

This all feels like a very awkward start to using such a game-changing capability. But, at least I've started!

Here's some additional inspiration on the topic: Integrate Emacs with ChatGPT or any LLM, Powerful AI Prompts I have Known and Loved - that you can use, and Emacs pinky Saver: a voice driving GPT4 co-worker for emacs. together.ai is a platform for letting me interact with more LLMs than just ChatGPT.

Monday, August 19, 2024

Review: The Lost Apothecary

I randomly picked up The Lost Apothecary, by Sarah Penner, from my Mother-in-Law's (z"l) bookshelf, read a few pages and was hooked. F from there, I couldn't put it down. In short, while it's not perfect, it was a delightful read and one that was both entertaining and thought-provoking.

Spoilers Below. Go read the book.

The plot, the philosophizing, the characters, I'm here for it all. I appreciated the symmetry and timelessness of both the historic and modern-day story and was impressed with how poisons were tied into both. I fell into every trap Penner set for me, from thinking that James may be a decent guy to thinking Eliza was dead. I'm sure a more observant reader would have picked up on the (in hindsight) obvious clues; but not me.

I liked the story enough that I was fine with suspending my disbelief that a property in downtown London would lay untouched for hundreds of years. And the fact that just about every man in the text is some degree of sleazeball, well sure, why not. Girl power for the win!

I generally appreciated the book's philosophizing. When Caroline challenges that there's a difference between being happy and being fulfilled, I found myself agreeing. Clearly delaying gratification for a bigger goal is a powerful life skill. But what are the limits of this? More than anything, I appreciated that the book gave me a chance to chew on these ideas.

I also appreciated Nella's mission of capturing the names of the women she helps in her registrar. That humble act was a way of recording for posterity that which would normally be forgotten. One of the missions of my blog is to do the same: to try to leave a mark, however insignificant, for those to find in the future.

So yeah, Penner had me. That was, until the last two pages of the book. When Caroline decides that Eliza and the vial would be "one secret I would not share." I found myself mouthing a slow-motion 'Noooooooooo' as she chucked the vial in the Thames.

This decision to withhold Eliza's story from her research struck me as flawed in a number of ways. First off, it seems to have the ethical equivalence of a police officer planting evidence 'just this once.' And more to the theme of the text, isn't Caroline's goal to bring stories of regular people to life? Hiding Eliza and the physical evidence she existed seems directly counter to this.

Respecting the story itself, Eliza's elixir fended off hypothermia. If such a concoction could be replicated in the lab, Eliza's 'magic' could have potentially life-saving implications. How could Caroline not see that there's an opportunity to not just tell Eliza's story, but have it be elevated into one of discovery and world impact?

If you're looking for a fun, fast paced, historic read The Lost Apothecary may be just the tonic you're looking for.

Friday, August 16, 2024

Buzzard Hill, Appalachian Trail Hike - Close to DC, Far from Easy

[Composed: 7/2/2024]


Buzzard Hill is one of those hikes that looks perfect on paper: close to DC, relatively short (only 4'ish miles!) and with at least one notable feature, in this case, a waterfall. The hike is a tiny section of the Appalachian Trail, so it's easy to extend and could be turned into an overnight with ease. With all this going, how could the hike not be a winner?

With our niece C in town, we wanted to get some hiking time in. She expressed an interest in going on the AT so Buzzard Hill seemed like the perfect fit.

About 10 minutes in, I realized that this hike wasn't the slam dunk I'd hoped for. We were smack dab in the infamous section of the 2,197-mile AT, affectionately known as the 'Roller Coaster.' While the climbs weren't massive, they weren't trivial either. Up and down we hiked, and I realized that this trail wasn't the gentle introduction to the AT I'd hoped for. This was work, and after a summer of gaming and watching Netflix, C was feeling the grind.

We took the side trail to the waterfall and it was OK. There were multiple levels of waterfall to explore, but the rocks were wet, and the whole area was fairly treacherous. So while the waterfall wasn't a bust, it also didn't quite make up for the sweat equity spent getting there.

From the waterfall, we continued on to Buzzard Hill. More uphill. There's a very nice campsite at the summit, along with hints of great views. Alas, the vegetation makes it so there's no clear vista. Like the waterfall, it earns a 'nice but not spectacular' rating.

For nearly the entire length of the trail, pawpaw trees lined the path. Unfortunately, we only saw a couple of fruit, and they weren't ready to be harvested. Still, during the right time of year, this hike would be a glorious foraging location.

Another notable find on the trail was the '1000 miles from Georgia' marker. This helps put the AT in context, and you realize that for through-hikers this section of trail will hold a special place in their hearts.

I was excited to give C a first introduction to the AT. The thick tree cover provided for a maximum green-tunnel effect, but in this case, it helped keep us cool. We saw a bit of wildlife: a turtle, frog, a number of fascinating bugs, and a skink. Alas, we didn't see a wendigo like C had hoped for. Oh well, maybe next time.

Most importantly, I now appreciate that Buzzard Hill isn't an ideal option for introducing folks to the AT. What it gains in being close to DC, it loses in the elevation gain. It may have been a 4-mile hike, but it felt like a 10-miler.

Maybe I'll come back with Shira in the winter when we can roast hot dogs at the summit and take in the views. Or maybe I'll crack the pawpaw code here, and we'll come back for an epic haul.

Regardless, it was a real pleasure to hike with C. Whatever exhaustion she incurred helped save the next unfortunate soul we might have dragged out for a 'quick hike on the AT.' For that, C is a hero.



Wednesday, August 07, 2024

Review: The Dinosaur Artist: Obsession, Betrayal, and the Quest for Earth's Ultimate Trophy

The year is 2012 and Florida Man has struck again. This time, he is accused of the surprisingly sophisticated crime of smuggling a nearly complete Tyrannosaurus battar skeleton out of Mongolia, and selling it at auction for over $1 million dollars. Here's the headline: Florida man pleads guilty in New York to smuggling dinosaur fossils.

The Florida Man in this case is Erik Prokopi, the main character of Page Williams' engaging story The Dinosaur Artist: Obsession, Betrayal, and the Quest for Earth's Ultimate Trophy. Williams' text uses Prokopi's case to take a deep dive into the world of paleontology, with an emphasis on amateurs.

A good chunk of Williams' story is spent bringing the reader up to speed on how the field of paleontology developed. This alone makes the book a worthwhile read. Topics like the Central Asiatic Expeditions or the trailblazer Mary Anning were riveting and I can't believe that as an adult I'd never heard of them. I hope to do a deep dive into many of these topics.

I found Williams's exploration of the amateur side of paleontology to be equally fascinating. I buy her argument that dinosaurs make for an easy entry into the world of STEM. My four year old nephew's infatuation for dinos could easily blossom into a love of science.

While listening to the Dinosaur Artist, Shira and I attended a Foster Parent training seminar on teens and screentime. Yes, the pull of devices is strong, but the Dinosaur Artist offers a unique antidote: fossil hunting. In my experience, kids will gladly put down their phones if you can give them real world experiences as profound as finding the remains of prehistoric creatures. I know it was a special thrill for our crew when we found shark teeth at Westmoreland State Park.

The Dinosaur Artist also helped me appreciate the relatively level playing field among expert and amateur paleontologists; a scenario rare in most scientific fields. Many fossil discoveries depend on being in the right place at the right time, rather than say extensive knowledge or specialized equipment. That explains how three kids could find a scientifically interesting T-rex, a feat any professional would be eager to accomplish.

As for Eric Prokopi, Williams unpacks his case: she makes you appreciate that it's more complicated than the headlines suggest. No, he didn't smuggle a skeleton out of Mongolia; he used shady business dealings to buy raw material, which he painstakingly assembled into a masterpiece. Was Prokopi guilty? Definitely. But ultimately, the three month sentence he received seems fair. He crossed ethical lines and allowed privilege to cloud his judgement. But no, he wasn't some cartoon villain looking to rip off the people of Mongolia.

And speaking of Mongolia, it's remarkable how science has turned its unusually large concentration of dinosaur fossils into a new natural resource it can harness. This would be a plus for any country, but is especially critical for one that's as resource-strapped, and geopolitically tenuous as Mongolia. Well played, science.

Perhaps the biggest side effect from the Dinosaur Artist is my fresh appreciation for natural science museums. I'm looking at you, Natural History, Smithsonian. I admit it: I'd gotten desensitized to these amazing exhibits. I now have a fresh appreciation for the effort and artistry that goes into making fossil displays. The kids who are blown away by what they see have the right idea; the science, countless hours of prep, and creativity that goes into crafting a life-like scene should truly be savored.

Williams does an excellent job of showing how dinosaurs and their fossils impact science, business, governments, and young minds. Not bad for a species that went extinct 66 million years ago.