I finally finished listening to every single episode of the podcast Data Skeptic. I’m not sure that I really needed to listen to every episode, but I learned a lot.
I tend to be kind of obsessive about educational content. I made a point way back when of listening to every single episode of the Linear Digressions podcast as well. At least that one ended in 2020, so I can be officially done with it.
By now, I should be an expert at machine learning, but I’m not. Hmmm… Maybe I actually have to do some things on a computer and not just listen to other people talk about doing things on computers.
I just started Super Data Science: 859: BAML: The Programming Language for AI, with Vaibhav Gupta. It came on while I was in the car and I’m 14 minutes in. I barely know what BAML is, but I think I want to try it.
I mean, I just got API access to ChatGPT last Saturday. Anything that will push me forward in the LLM world has got to be worth checking out right?
Yeah. Let’s do this.
So my favorite starting point has changed from Google to ChatGPT. So let’s prompt away, “What is the purpose of BAML?“
ChatGPT didn’t know. Apparently GPT-4-turbo was trained until June 2024, the same month BoundaryML released BAML.
ChatGPT threw details about several different BAMLs at me, but none of them were the language for controlling LLM prompts.
So I clarified “I am speaking of the language for interacting with LLMs”. ChatGPT then offered to look this up on the web, and then it got a little bit of helpful information.
I wanted to know “What is the easiest way to try BAML?“
ChatGPT suggested that I start by reading the Official Documentation.
Ok. Not gonna. At least not yet. Next idea?
Explore the online playground Prompt Fiddle.
Ok. I’ll check that out.
Hmmmm… There is a cool example where I guess the LLM extracts data from a photo of a receipt. I guess that’s kind of cool, but this “playground” looks kind of complicated for me, and more like a “workground” than a “playground”
I pressed the play button for “Run ImageReceiptTest” and some stuff started spinning and lines started highlighting and it was kind of cool, but I really don’t know what I just did.
I see I can “Start a New Project” but that sounds even worse.
I still don’t want to read the documentation, but I’m thinking about it.
I think I should go ahead and try the third suggestion ChatGPT gave me, “Set Up BAML Locally ” and “Follow the Python Installation Guide to integrate BAML with your Python projects.”
Ok. They want me to install baml-py so for safety I’m gonna clone my old conda environment first.
Get to my miniconda prompt
conda create --name env_todaysdate --clone env
Perhaps this is too paranoid of me, but I hate it when you mess up an environment that used to work. Maybe there is a better way to manage that kind of thing. Don’t they have some way of listing all the packages?
Ah well. This is good enough. Just clone it. It works as a backup before we mess with our main working environment. I guess Docker and containers and package management and all that is a whole nother big thing I should maybe try to get better at someday.
conda activate env
They said to pip install baml-py, but I’m gonna try conda install instead.
Didn’t work. Ok. We’ll do it their way.
pip install baml-py
It worked.
Now I am supposed to get some starter code by running:
baml-cli init
There was a warning, but I got a new directory called baml-src
Inside are three “baml” files:
clients.baml
generators.baml
resume.baml
Let’s open up clients.baml into an editor (Notepad++ because I am afraid of powerful IDEs)
This is the first entry:
client CustomGPT4o {
provider openai
options {
model "gpt-4o"
api_key env.OPENAI_API_KEY
}
}
Cool. This makes more sense to me than the playground.
Maybe I just need to open a file for myself before I pay attention. Not sure what my problem was with the playground, but this is clearly a place to pick which LLM model you want and supply your API key.
Hey. I just got one of those last Saturday. Cool,
Let’s open the next file, generators.baml
Ugh. This one confuses me. Something about helping with auto generate libraries, generator target, output directory, version number and default_client_mode of sync or async.
Next is resume.baml
This looks ok.
There’s a class resume with name, email, experience and skills.
There’s a function:
function ExtractResume(resume: string) -> Resume {
And there’s a test resume for one of the founder’s of the company that created BAML
BTW, I want to point out that I still barely know what BAML is.
I know it is supposed to make interacting with LLMs in your code better. I think it turns prompts into functions or something like that. And I think it is supposed to constrain the responses you get from LLMs so that they match your schema and type.
Maybe that’s all it is. Maybe that’s enough. Still not sure.
Let’s keep going.
According to the installation guide, I should now “Generate the baml_client python module from .baml files“
Just typebaml-cli generate
Didn’t work. I was inside the src directory. Gotta be outside it.cd ..
baml-cli generate
It worked:baml_runtime::cli::generate] Generated 1 baml_client: baml_client
The installation guide now gives us code we can run called main.py
We just have to copy it and save I guess:

I saved main.py and made sure to place it in the baml_test directory. This is the dir that contains the baml_src dir and the baml_client dir.
From there:python main.py
Well it did something. I just can’t tell what.
It ran without errors, had no output and stopped.
I returned to the docs and don’t even see what I’m looking for.
So I asked ChatGPT which pointed me in what should’ve been an obvious direction, “Make sure main.py
contains a function call that actually prints or returns a result.“
In case you haven’t noticed. I am not a very good programmer. Sometimes my code is so bad, AI refuses to autocomplete it.
I should’ve noticed that all main.py does is a couple of imports and and defines a couple of functions. There are no function calls much less printing results.
Well.. in the spirit of being a new fangled kind of lazy AI assisted promptgrammer, I won’t even try to fix up main.py. ChatGPT already read my mind and suggested this code:

python chatgpts_runnable_code.py
Wow. I really am ditsy:
AttributeError: 'BamlSyncClient' object has no attribute 'your_function_name'
I almost want to edit this out of my post. But honestly, yeah I didn’t even look at the code and no, I didn’t catch that I am clearly supposed to fill in my own function there.
Upon a little reflection. I believe I am actually supposed to combine this code with my old main.py. Let’s give that a whirl.
Yeah. That first import line is the same in both.
The first code had functions, but no main function.
Let’s move the main function from ChatGPT’s version into the original main.py.
Now let’s add this little bootstrapping nugget:
if name == "main":
main()
Cool. This is gonna work.
Oh wait. Is there any printing….?
Yes!
Ok. This is gonna work:

python main_combined_with_chatgpts_code.py
Uuuuuuuugggg!
AttributeError: ‘BamlSyncClient’ object has no attribute ‘your_function_name’!!!!!!!!!!!!!!!!!!!
I did have to combine the code, but I ALSO had to rename the function call to something defined in that new combined code.
Oh, And I probably should make sure there is some input. Maybe something that looks more like a resume instead of “Your input here”
Ya know what? I don’t care. “Your input here” is good enough.

python keeptrying.py
Now an error that b.example doesn’t exist.
Change it to example
python keeptrying.py
Now an error “unexpected keyword argument ‘input_data’”
Remove that
python keeptrying.py
Ahh… Ran much longer but there’s an error “invalid_api_key”
Let’s put in that key I got last Saturday.
python keeptrying.py
Still wrong API key? What?
Give ChatGPT the function and ask how to set the API key.
It says to use (at the miniconda prompt) setx OPEN_API_KEY "your actual key"
Successfully set that.
python keeptrying.py
Still the wrong key!
So I mess around with setx vs. set. Apparently you may have to start a new session for it to take effect.
I also messed with setting OPEN_API_KEY
without quotes.
python keeptrying.py
Failed while parsing required fiedld. Missing name and email
Ok. I expected that my input of “Your input here” wouldn’t look much like an actual resume. Let’s improve that.
There’s a function in resume.baml which is setting a resume for testing purposes. I want to use that resume.
But I don’t really know how to use this function (test vaibhjav_resume). The word test precedes the function name. According to ChatGPT, that is for unit testing. But I don’t know how to use this.
I asked ChatGPT and I still don’t know how to call it, so I am going to just copy out the meat of his resume and feed it to what I have going on:

So now here is what I hope will be my last version of keeptrying.py

Let’s give it a shot.python keeptrying.py
unterminated string literal!
Kept messing with trying to get that resume into my parameter.
Eventually had the bright idea to throw this at ChatGPT and see if it could terminate my string literal.
It helped me to come up with this final version

python keeptrying.py
Response received: name='Vaibhav Gupta' email='vbv@boundaryml.com' experience=['Founder at BoundaryML', 'CV Engineer at Google', 'CV Engineer at Microsoft'] skills=['Rust', 'C++']
Hurray!
Maybe the playground would’ve been better. I never did read the documentation.
Leave a Reply