Tales from the jar side: Spring with AI: Chat with GPT, Moving to foojay.social, LinkedIn spam, AssertJ in Polish, and my inevitable commentary on Travis Kelce / Taylor Swift
My wife kissed me on the sofa and said, "Let's take this upstairs." I replied, "Okay, if you really want. You grab one end, I'll grab the other, and maybe we can get the boy to help turn the corner."
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of October 1 - 8, 2023. This week I taught my Functional Programming in Java course on the O’Reilly Learning Platform.
Regular readers of (and listeners to, and now video viewers of) this newsletter are affectionately known as jarheads, and are far more intelligent, sophisticated, and attractive than the average newsletter reader or listener or viewer. If you wish to become a jarhead, please subscribe using this button:
As a reminder, when this message is truncated in email, click on the title to open it in a browser tab formatted properly for both the web and mobile.
Spring & AI without Spring AI: Chat with GPT
New video this week:
I’ve been planning this one for a while, but other activities kept interfering. I’m pretty happy with the result, though we’ll see how it does.
This video shows how to use Spring’s HTTP Exchange interfaces, the embedded Jackson JSON parser, and Java records to access ChatGPT like it was any other RESTful web service. An interesting part is where I add a default method in the Java interface to make it easy to extract the String
message from the ChatResponse
:
Here’s a test for it:
Sure enough:
It’s somewhat reassuring that GPT-4 gets that right.
There are ways to simplify that request as well, but it’s pretty convenient to be able to create a full request, with model, a list of messages, and a temperature all provided.
Validating Requests
I also used Spring’s dependency injection to autowire this interface into a service class. In the service class, the first thing I do is download the current list of models, and if I ask for a model that doesn’t exist, I throw an exception. As you might expect, that sort of input validation happened because I got burned.
Early in the week I accidentally typed “gpt4” instead of “gpt-4” for the model and got a weird error. The error showed the link to the service, but when I clicked on it, of course it failed. I say “of course,” but of course it that’s only true in retrospect. (rimshot) When I clicked on the link in the error message, I sent a GET request without the required Authorization header, so I got an error based on that. I spent probably a good hour worrying that somehow my dependency injection of the interface into the service wasn’t sending the header, but it was fine.
Once I finally realized what I’d done, I called downstairs to my wife:
Me: I fixed my problem.
Her: Really? What was it?
Me: I’m blind, or an idiot, or both.
Her: That’s nice, dear.
Or words to that effect. We haven’t been married for 33 years (yesterday) for nothing.
In the code in the GitHub repository, I have a pair of constants for the most common models:
public static final String GPT35 = "gpt-3.5-turbo";
public static final String GPT4 = "gpt-3.4";
That way I can call those two models with OpenAIService.GPT35
or OpenAIService.GPT4
, which are really the only ones I use anyway.
As my commit message (generated by the AI Assistant in IntelliJ IDEA) says,
Once burned, twice shy, I guess. As long as those are available, I probably don’t need to download all the model names each time, but that doesn’t cost anything and doesn’t take long, so I’ll probably leave it in for a while.
On Tuesday, I’m teaching my new Practical AI Tools for Java Developers training course as an NFJS virtual workshop. That will be fun, but I can’t use any of what I just described because it’s all using Spring. In reality I’ll ask the students, and if by change they already know Spring, maybe I’ll share this with them as well. I’ll probably create another Virtual Workshop specifically for AI & Spring WITHOUT Spring AI, and maybe yet another for AI & Spring WITH Spring AI. We’ll see. In the meantime, I have these videos, with a few more in the works.
Transitions
I’m now on foojay.social
When you join Mastodon, the initial form starts by asking you to pick a server:
That’s cleaner than when I first joined, when they didn’t have that Join mastodon.social button as a default.
The problem is, when someone chooses to join Mastodon for the first time, they have no idea about servers or how to tell one from another. Mastodon is part of the so-called Fediverse, which is a loosely-connected set of servers, each with different policies and moderation rules. It’s like email, in that your email address is associated with a particular organization, like gmail.com, but you can still send and receive messages from anywhere.
Mastodon servers range from small (even just one person) to huge, and mastodon.social is by far the largest, probably because it’s the default. The idea of having one dominant server goes against the whole philosophy of Mastodon, which is to avoid giving too much control to any one person or organization. I mean, that’s what led to the chaotic cesspool that is X/Twitter these days, and Bluesky, while fine for me so far, is similarly subject to the whims of a single owner.
I’ve been on mastodon.social since I joined, and this week I decided it was finally time for me to move. Somewhat arbitrarily I picked foojay.social.
Foojay stands for Friends of OpenJDK, the open source project that supports Java, and is located at https://foojay.io.
To be honest, I don’t really like the name, but the people are nice, supportive, and friendly, and it seemed like a natural home for me. There were other options, like fosstodon, which is about Free And Open Source software, but I figured foojay.social was fine.
The migration process was straightforward enough. I made an archive of my existing data from mastodon.social, created the new account on foojay.social (which was, fortunately, quickly approved), then told the old server about the new one and the new server about the old one. That migrated a lot of my settings, but sadly not all, from the old one to the new one.
My new Mastodon address is therefore now this one. Most of the people in my follow list migrated over properly, and I think most of my followers as well, though that resulted in a few hundred notifications I wasn’t expecting. The one thing I lost was my favorites list. I didn’t lose it, exactly — it just didn’t move from one server to the other, and I kind of rely on that. There also doesn’t appear to be any easy way to import that into the new server. You can import lots of lists, but I don’t see a setting for likes.
Fortunately, I have an effective but tedious workaround. Since I downloaded my archive, when I expanded it I found a file on my disk called likes.json, which is JSON data containing links to all the posts I’ve liked. I fired up good old jwebserver
(the trivial Java web server, added in Java 18) in that directory, and now I can see all those clickable links in a browser:
Now I can go through, one by one, opening them in a new tab. If I still want to save it, I can like it again, which will redirect me back to foojay.social and let me add it. The problem, of course, is that’s a big file (only 76K, but that’s a lot of one-line text entries), and it’s going to take me a while go to through it.
Still, it’s kind of fun revisiting all those posts, a lot of which are still pretty funny. It also reminds me of users I still have to re-follow, so I’m taking care of that, too.
LinkedIn update
Speaking of transitions, I needed my LinkedIn profile URL for a conference proposal this week. While I was there grabbing it, I noticed I hadn’t updated my LinkedIn profile to include my new position at Trinity College, which I’ve been talking about here for the last few months. I therefore added it:
What I didn’t realize was that by adding that position, LinkedIn was suddenly going to share it with my network:
Oops. Ever since then I’ve been getting notifications that people are liking it or sending me congratulations on the new job. Nothing wrong with that, of course, but I hadn’t expected it and I didn’t mean to spam everybody about my one undergraduate course I’m teaching as an adjunct. I mean, thanks everybody for the kind wishes, but I really need to check my notification settings now. :)
Also, from that picture you can see there’s no icon for the NFJS tour. That’s probably fixable, but I’m afraid if I try to update it, LinkedIn will probably spam everybody yet again. I think I’ll wait on that.
AssertJ in Polish
The last couple of weeks I mentioned my experiments with HeyGen, which not only translates video into other languages, but modifies the speaker to look like they’re saying the actual words. I ported one of my YouTube Shorts to Hindi, which I mentioned in last week’s newsletter.
I added another one in Dutch, which got a lot fewer views. Next I tried one in Polish:
I’m not quite sure what to make of that, either, but it doesn’t really matter because very few people watched it. I might try porting that one to Hindi instead, to see if that makes a difference. As I mentioned last week, the second largest group of jarheads by country resides in India. I didn’t market any of the shorts, by the way, other than here in the newsletter. I still have a couple of credits left, so it might be fun to try again.
Tweets, Toots, and Skeets
Kelce-Swift
I spent a lot of time talking about technical topics recently, but I know why most of you are really here. I have no data or any other evidence to prove it, but I wouldn’t be at all surprised if that vast majority of my readers skip directly to my weekly collection of funny and/or interesting social media posts.
Given that, and given that I’m an old white guy who has been following the NFL for decades and whose musical tastes were formed either late in the Jurassic Period or early in the Cretaceous Period, I feel it’s time to give the people what they want. So here are my Hot Takes on the Travis Kelce / Taylor Swift relationship.
That picture looks photoshopped to me. It’s from an article at a site called Deadline, which starts like this:
Um, yeah. I’ve never been a fan of crowd-shots during a game, though I must say the NBA is way worse about that than the NFL, especially given that NBA games are all about the flow while NFL games are bursts of action separated by committee meetings (as a comedian once said).
My opinion is, good for them (Travis and Taylor, I mean — screw the salivating NFL marketing people who are lusting after this becoming A Thing). They’re a couple of successful young people who are perfectly capable of knowing what they want and what they don’t want, and by all accounts they’re good people to be around. While Kelce is already a bit of a celebrity, I’m sure he’s never seen anything like what Swift deals with all the time, but he’ll quickly learn.
If you’re a Kansas City Chiefs fan, I can see how you might have mixed feelings. It’s probably fun having a celebrity of her magnitude bringing attention to your team, but her record in long-term relationships is, shall we say, somewhat shaky. Not to mention that her breakups tend to manifest themselves in potentially vicious popular songs in the Top 40. I sympathize with those who just want the seemingly inevitable breakup to wait until after the Super Bowl, but that’s a long time from now, at least for young people’s relationships. Besides, maybe it’ll all work out.
Another factor I keep in mind is that Swift is both a very intelligent and quite powerful woman. There’s no way the NFL (or anyone else) can take advantage of her without her permission. If they keep showing her on camera and getting her to attend games, I’m sure she’s getting something out of it other than just supporting Kelce. I don’t know what that something might be (selling additional tickets for her upcoming concert film, maybe?), but she knows what she’s doing. I’m sure there’s something.
So again, good for them. I wish them all the best and hope they’re happy forever. But yeah, it’s all rather entertaining and I’ll be keeping an eye on it, at least at the low-level of hearing about it through NFL reporting.
One thing, though. Can you imagine the hype around (in order of increasing press insanity):
The Chiefs make the Super Bowl and they’re still together?
The Chiefs make the Super Bowl and they’re in the middle of a breakup?
At halftime of the Super Bowl, Kelce gets down on one knee and asks her to marry him?
And she says no?
Wow. All the social media sites would simply melt.
I must admit, I’m also really enjoying how much this relationship is annoying other old white guys, especially those NFL curmudgeons who shouldn’t be talking about pop culture events at all. Unlike me, of course.
No politics this week, but…
I view this newsletter as an escape from politics, but these memes were funny enough to include:
and
Yeah, that’s enough. If you want more political memes, they’re not exactly hard to find.
YouTube channel growth
The twitter feed of @sivalabs did it to (actually, for) me again:
That led to a significant gain in my subscriber numbers, which I’ll go over, as usual, in tomorrow’s video version of this newsletter. I’m happy to support Siva’s efforts, and I replied with some mild advice, but it’s not like he needs my help. In fact, he already tried out LangChain4J in a Spring app, so now I have some catching up to do. That ought to be fun. :)
Hello, Fall
As the equinox turns…
Yup. I can almost feel the days getting shorter.
Inheritance
If he’s working on COBOL today and his mom worked on COBOL back in (presumably) the 1950s, I’ll bet she was a better coder then than he is now. Maybe not, but it’s just a thought.
Bisexual poll
Nice.
When I teach people about functional Java, I occasionally mention the BiConsumer
interface. I tell them what it’s for, but then I casually remark that implementing it also doubles your chances of getting a date on Saturday night.
I have to make sure to pick the right audience for that gag, though.
I hate when that happens
That might be a tough story to sell your boss, but it would cause a delay.
The tough one is remembering how to exit
Found that one while reviewing my old favorites list, as I talked above earlier. My thought is that there must be Emacs keybindings for all of those as well, but they all begin with Meta-Shift something or other. No doubt IntelliJ has mapped keyboard shortcuts for them, too.
Heartwarming?
Nice commentary on the US healthcare system.
But is it the same article?
Inspired.
Finally, a pair of signs
This might work:
Okay, maybe not, but this organization needs your help:
Or maybe they don’t after all.
Have a great week everybody!
The video version of this newsletter will be on the Tales from the jar side YouTube channel tomorrow.
Last week:
Two-day Functional Programming in Java course on the O’Reilly Learning Platform
Software Design, my course for undergrads at Trinity College
This week:
Practical AI Tools for Java Developers, an NFJS virtual workshop
Gradle, private class
Software Design, my course for undergrads at Trinity College
Northern Virginia Software Symposium (NFJS) next weekend
Here's to COBOL and Admiral Hopper. Java has a ways to go to beat either of their longevities.