Using AI In Your Own Apps

In my previous post I covered how to run a large language model on your own computer. I covered how to send prompts to it and start a chat. The next step is adding an LLM to your own applications. The llm library makes this easy.

First, initialize a new project with uv and add the llm and llm-mlx libraries:

uv init llm-test --python 3.12
cd llm-test
uv add llm llm-mlx

Now open up main.py with your favorite editor and make it look something like this:

import llm

def main():
    model = llm.get_model("mlx-community/Llama-3.2-3B-Instruct-4bit")
    response = model.prompt(
        "Tell me a joke."
    )
    print(response.text())

if __name__ == "__main__":
    main()

There are three steps to the process:

  1. Get the model we installed in the previous post.
  2. Get a response by prompting the model.
  3. Print the response text.

You can now run your new AI program with uv run main.py to see the result.

Once this is working, see the LLM Python API documentation for more information. For example, maybe you’d like to add a system prompt. Here’s a classic:

import llm

def main():
    model = llm.get_model("mlx-community/Llama-3.2-3B-Instruct-4bit")
    response = model.prompt(
        "Tell me a joke.",
        system="Talk like a pirate."
    )
    print(response.text())

if __name__ == "__main__":
    main()

In the documentation you’ll also find support for conversations that allow you to have an ongoing chat. Here’s a simple example of a CLI chat bot:

import llm

def main():
    model = llm.get_model("mlx-community/Llama-3.2-3B-Instruct-4bit")
    conversation = model.conversation()
    
    print("Welcome to my LLM chatbot! Type 'exit' to quit.")

    while True:
        question = input("What can I help you with? ")

        if question == "exit":
            break

        response = conversation.prompt(question)
        print(response.text())

if __name__ == "__main__":
    main()

Note that I added a new conversation with model.conversation(). Then instead of prompting the model directly, I prompt the conversation. This allows the model to remember previous questions so you can ask follow-up questions.

From here the possibilities are basically endless. You could use your favorite web framework to create your own web-based chat bot or use fragments to analyze external content.

Next time I’ll cover using a commercial model. Until our personal computers get much faster we’ll only be able to go so far with local models.

Run Your Own AI

Large Language Models seem to be taking over the world. People in all kinds of careers are using LLMs for their jobs. I’ve been experimenting at work with using an LLM to write code with mixed, but promising, results.

After playing around with LLMs at work, I thought it might be interesting to run one locally on my laptop. Thanks to the hard work of several open-source developers, this is pretty easy.

Here are some instructions that I shared with my co-workers. These are specifically for Macs with an M-series processor. On a PC, skip the steps about MLX and use Ollama to download a model. Then install the llm-llama plugin instead of llm-mlx.

Install uv

If you’re a Python developer, you might already have uv. If not, it’s easy to install:

curl -LsSf https://astral.sh/uv/install.sh | sh

If you’re not familiar with uv, the online documentation describes its as “An extremely fast Python package and project manager, written in Rust.”

Install llm

Now that we have uv installed, you can use it to install Simon Willison’s llm:

uv tool install llm --python 3.12

Note that I specified Python version 3.12. One of the dependencies for the llm-mlx plugin doesn’t support 3.13 yet.

Install llm-mlx

MLX is an open-source framework for efficient machine learning research on Apple silicon. Basically what that means is MLX optimized models run much faster.

llm install llm-mlx

Again, if you’re not on a Mac, skip this step.

Download A Model

The llm CLI makes this easy:

llm mlx download-model mlx-community/Llama-3.2-3B-Instruct-4bit

This installs a model from the mlx-community, optimized for a Mac.

Run The Model

It’s finally time to test everything out:

llm -m mlx-community/Llama-3.2-3B-Instruct-4bit "Tell me a joke"

If you followed these steps, you should see a joke. AI jokes are kind of like dad jokes. People seem to groan more than laugh.

Chat With The Model

Rather than make one request at a time, you can also chat with local models:

llm chat -m mlx-community/Llama-3.2-3B-Instruct-4bit

This is how most of us interact with LLM models online. The chat option responds to whatever you type at the prompt until you enter “exit” or “quit”.

What’s Next?

Maybe try a different model and compare the results. The mlx-community on Hugging Face has lots of options. Beware, some of these are very large. In addition to a large download, they also require a lot of memory to run locally. For another small model, you might want to try Qwen3:

llm mlx download-model mlx-community/Qwen3-4B-4bit

Check out Simon Willison’s blog. He shares tons of interesting info covering the world of AI. I have a bad habit of leaving his posts open in tabs. Here are a few I have open right now:

Finally, a really interesting thing to me is embedding an LLM in an application. I’ll cover that in another post.

Wasted Evening

I love having my own blog, I really do. No one owns what I say here except me. But this comes with a huge burden. Every part of this site is set to automagically update itself, but that’s never enough.

A few days ago I got an email with a screenshot of my wp-config.php file. That file contains the name of my database as well as the username and password needed to access it. In other words everything anyone needs to completely take control of this site.

So, I did what any responsible person would do. I exported all of my posts, backed up the entire (presumably hacked) site, and re-installed everything from scratch. Of course that takes some time.

I then imported all of my posts after examining the exported data (an XML file) for any trace of spam. Manually copied all the images from the backup site. And tried to reconfigure everything like it was before.

Again, I love having my own blog, but it’s a real hassle sometimes.

New Year’s News

Happy 2025! I thought I’d post a little about what I’ve been up to lately.

Work

I’m still at Braintree (PayPal). My title is MTS-2 Software Engineer. MTS is short for Member of Technical Staff. I think most companies call this “Staff Engineer”. So I would be a Staff Engineer II.

My role is Tech Lead for the Cards Settlement team. Tech Lead means I’m not a people manager, but I am the most experienced engineer on the team. PayPal has dual tracks for moving up – a manager track and a technical track.

I work with our Engineering Manager and Product Manager to help plan what the team is going to build. This involves estimating work, documenting features, and writing a ton of JIRA cards. I also review pull requests, mentor other engineers, and still write some code.

Education

I’ve been thinking on and off about getting a Masters Degree for years now. PayPal offers some tuition reimbursement, so it wouldn’t cost too much. But it is a serious time commitment.

As of last summer I guess you could say I took the leap. I enrolled in the Ball State University Online Master of Science in Data Science. This is an online program through Coursera. I started with one class last summer (Intro to Programming) to see what is like and it was really good.

I took two classes in the fall – Intro to Data Science and Data Visualization. And I’m taking two more classes this semester – Foundations of Data Analysis and Statistical Methods for Data Science.

Each week there are a few hours of video lessons and some required reading. There are also graded tests and labs. At the end of the semester there will be a final and / or a project.

This is all entirely online and asynchronous, but that doesn’t mean it’s easy. I spend at least an hour a day after work learning and even more on the weekends. It’s hard, but I’m truly learning. I’ve always believed in continuous improvement.

Personal

I’m keeping busy with work and school, but we did have a great summer. Another perk at PayPal is the one-month sabbatical every five years. Last year was my fifth year.

I’ve never taken a month off of work in my life. Even when I change jobs I like to leave one on Friday and start the new one on Monday. I was honestly a little nervous at first, but it was great.

We’ve always wanted to go to Italy, so we did. We spent a week in Rome and week in Florence. It was amazing. We didn’t rush through everything. We saw our share of touristy sights, but we also spent time relaxing and exploring.

We stopped off in Dublin on the way back home and spent a week there, too. We took a bus to Northern Ireland and visited a castle and the Giant’s Causeway. We went to a jewelry making class and everyone made a silver ring.

It was an amazing trip and I can’t wait for out next adventure.

Future

At my current pace I should finish my degree in May 2026. I’m not sure exactly what that will mean for my job. Maybe nothing. But I’ll bet I could pivot into another position or at least move up in my current role.

We’ve always talked about moving somewhere northeast – a blue state. I see that in our future when the kids graduate. My next sabbatical lines up with that day perfectly. Maybe we’ll spend that month moving.

Now, I’ll get back to posting geeky stuff. As I progress in my degree there might be more about R or Python programming. There will probably also be more about AI and machine learning. The future looks bright.

Your Own Roguelike

Are you into old games? Really old games? How about a dungeon-crawling game originally developed in 1980?

That game is Rogue. In Rogue you play a simple @ sign making your way through a procedurally generated dungeon made up of ASCII characters. Monsters are represented by capital letters. Death is frequent and permanent.

I never played the original Rogue, but I did spend some time playing other roguelike games such as NetHack and Angband. Even if you’ve never heard of those, I’ll bet you have heard of a more modern, mostly roguelike game called Diablo. I don’t even want to know how much time I spent playing that series of games.

In addition to playing games, I also still dabble in game development. One day I thought “Maybe I could make my own roguelike…”. That lead me to Roguelike Tutorials. Every summer the RoguelikeDev community on Reddit goes through the tutorial over the course of several weeks.

This tutorial uses Python and the TCOD library to develop a text-based, ASCII-art game. I’m a big fan of Python so this is great. But, there other game engines available that would let you develop something a little more modern.

Enter Godot, a free, open-source game engine. I’ve made a few half-hearted attempts to learn and use Godot over the past few years, but my never really stuck with it. I’ve had this link to the excellent Yet Another Roguelike Tutorial by SelinaDev open in a tab in Safari for at least 6 months.

And that’s the reason for this post. I leave interesting sites open in a tab for ages sometimes. I should probably use some kind of “read it later” site like Pocket to keep track of these sites, but for whatever reason I never really liked using any of those services.

If I find something so interesting that I leave it open in a tab, I’ll post about it here. After all what is a blog other than a series of posts about things that I find interesting?

Strange Loop Day 2

Day two started off with your choice of talks.

Ectype – Bringing Type Safety (and more!) to Vanilla JavaScript

I started with Holly Wu talking about a new system for making JavaScript type safe.

Ectype is a library and type checker that doesn’t require a build system of some other pre-compile step. Interesting stuff if you’re not into TypeScript.

The Economics of Programming Languages

Evan Czaplicki, creator of Elm, spoke to a packed room. I stood against the wall since there wasn’t an empty seat.

As the title says, he talked about the economics of creating your own language as opposed to languages like Swift and Go that are sponsored by a company. It’s tough to make a living doing your own thing.

A Long Strange Loop

Alex Miller created Strange Loop on October 22, 2009. He named it after a book that was sitting on his nightstand.

Alex talked about the origins of the conference and covered stats like the rise in attendance, the number of talks submitted, and some numbers about diversity.

There was an In Memoriam section mentioning three former speakers that have passed away.

Finally, Alex talked about why he’s ending the conference. It has achieved every goal he set for it. It’s getting harder to make sure the conference makes enough money to cover fixed costs.

He doesn’t want anyone else to take it over since the feeling of the conference is based on his beliefs, but he encouraged anyone who wants to start a conference to do their own thing.

I can’t believe this is the last Strange Loop. There’s no other conference like this.

Making Hard Things Easy

Julia Evans cheered us up with her wit and drawings.

She covered Bash, HTTP, SQL, and DNS. She’s great at finding fun ways to explain complex topics. Here’s her list of tricks for explaining hard things:

She followed this up with a list stereotypical people who take care of h

Drawing Comics at Work

Randall Munroe was the perfect ending for Strange Loop. He gave an interesting look back at how he went from NASA to web comics. It all started with this.

That comic got picked up by BoingBoing and suddenly everybody wanted a copy. He talked about several more comics, including my all time favorite:

Not everyone is nice on the internet. Do your own thing and don’t feed the trolls.

Strange Loop Party

The City Museum in St Louis is one of a kind.

The front has a variety of walkways, crawl spaces, and slides. On the roof there’s a Ferris wheel and a school bus hanging precariously off the corner of the building.

Unfortunately it started raining right after I got here so I listened to the band for a bit,

decided I was too old for the 3-story slide,

saw some interesting art,

wandered around the rest of the inside, and headed back to the hotel.

Strange Loop Day 1

How to Build a Meaningful Career

Taylor Poindexter and Scott Hanselman kicked things off with an opening keynote filled with thoughts and ideas about career building.

They’re both great speakers. They transitioned between sharing the stage and taking turns at center stage several times. The talk was a lot of fun.

Playing with Engineering

Next, AnnMarie Thomas gave her keynote about play. She runs a place called the Playful Learning Lab which sounds amazing. Learn by building fun things.

My biggest takeaway was “Play is about process, not about outcome.”

Without Open Data, There is no Ethical Machine Learning

Keynotes are done. Time for some tech. I started with Erin Mikail Staples talk about Open Data.

Maybe scraping all of Reddit and Twitter isn’t the best way to build an AI?

President Obama signed an executive order stating that government data should be open and accessible. Unfortunately, releasing data in an open format takes funds and that funding has been disappearing since he left office.

Programming Distributed Systems

Mae Milano’s talk on distributed systems was so good. It was definitely the most technical talk I saw today.

She was a little soft spoken, but very smart and had some great one-liners. The audience favorite was:

The speed of light is pretty slow — around 4 inches per clock cycle.

Mae Milano

And this explains why global distributed systems are so hard to build.

I was really impressed by MixT, a DSL for writing transactions to guarantee consistency across multiple databases.

Oatmeal is Cheap: A Fundamental Theorem for Procedural Generators

Indie game developer and university student Younès Rabii shared mathematical formula for creating procedurally generated art.

He built an interactive graph showing the three properties of procedurally generated art. Adjusting the graph in real-time showed the effects. A great way to demonstrate the math.

Software & The Game of Go

I was a few minutes late to David Nolen’s talk so maybe I missed the part about software.

It was a great overview of the history and rules of Go. I’ve played in the past, but never had much luck. It’s much harder than it looks.

He ended with the ten rules above which are good for many thibgs beyond Go.

Designing Dope Distributed Systems for Outer Space with High-Fidelity Simulation

I finished the day learning about simulation testing from Toby Bell.

He and his team are building software for a pair of satellites that will orbit the Earth every 90 minutes and line up to take pictures of the sun’s corona.

The two satellites will line up 40 meters apart, the satellite closer to the sun has optics, the other captures the image. They effectively form a 40 meter long camera system.

When your software is running in space, effective testing on earth is obviously very important.

Day 1 Done

And with that day one is done. Time for the after party.

Strange Loop Day 0

I’m in St Louis for a few days for the last ever Strange Loop Conference. I attended back in 2019, but skipped the last few years due to the plague. When I heard this was the last ever Strange Loop I knew I had to come back.

Part of what makes this conference so special is the venue. Union Station is a great hotel and the party at the City Museum is awesome. Here are a few example pictures in and around Union Station:

The hotel lobby, no filter.
Outside my first-floor room there’s a live band and pyrotechnics.
That water is actually a koi pond. I wonder what the fish think about the pyro?
Around the corner there’s a giant Ferris Wheel, of course.

The conference kicks off tomorrow morning at 9:30 AM so I better start getting my schedule figured out. I’ll post more pictures tomorrow, including the City Museum.

The MacBook Pro

Apple has really put the “Pro” back in MacBook Pro. Ars Technica says “Yep, it’s what you’ve been waiting for”. That looks to be true.

I guess some might say I’m an Apple fanboy. I have an iPhone, iPad, Apple Watch, Apple TV, etc. Now that I’m so deep in the ecosystem it just makes sense to stick with it.

I bought 13-inch M1 MacBook Pro a year ago when they were announced. I was immediately impressed. It’s the fastest computer I’ve ever owned, the battery lasts all day, and it seems like the fan never even turns on.

There are a few things I’m not crazy about. I never use the touch bar. I don’t look at the keyboard while I type, so I don’t even think about it. I would like a little more screen real estate. The M1 is still plenty fast, but faster is always better.

The lack of ports doesn’t bother me. I rarely plug in anything other than the charging cable. On my old MacBook Pro I did occasionally use the SD Card reader, and I’ve even used HDMI to connect to TV.

So of course I ordered a 14-inch MacBook Pro with the M1 Pro. The good news is I can get $880 for my 1-year-old 13-inch M1. Combine that with 3% cash back on the Apple Card (of course) and the price tag doesn’t look so bad.

I won’t receive it until end of November, early December. Once it arrives I’ll post more details about how it compares to the M1. And decide if it was really worth it or I just like having the latest and greatest.