I’ve been reading a lot about Google Gemini’s new AI language model, version 2 (currently in an experimental release), so I decided to try building something with it.
One of the best features of Flash is how it’s priced–users get 1,500 queries per day free, with up to 1 million tokens (a token is about 2/3rds of a word). But according to Google, Flash is not just faster but more powerful on some benchmarks than their “pro” model.
Of course, free has a caveat–the free tier gives Google permission to use the information. So it’s only suitable for information that you would already make public. Once you can prove a use case, Google also has a paid tier that is quite cost effective, generally about 25% of the cost of GPT-4. The paid tier doesn’t give Google permission to use your data, so it’s safe for use with confidential information.
This combination of fast, free, and relatively high performing opens up a lot of public use cases that I was more hesitant to experiment with in the past. One use case I have been thinking about is adding some spam filtering to our public feedback forms. Some of our clients have gotten a few dozen annoying targeted solicitations via their feedback form. This feedback ends up visible on GitHub in the public issue list for the repository, so it also clutters up the workload of developers. But, because it’s already publicly shared, Google’s free tier was perfect.
We use a few different tricks already, but it was clear to get much better performance, we’d need some kind of Bayesian filter. Those can be pretty hard to train on a limited number of examples. Could a large language model do the trick with less work?
It turns out, yes, the simple prompt:
You are reviewing a feedback form for {context}. Your job is to allow as many relevant feedback responses as possible while filtering out irrelevant and spam feedback, especially targeted advertising that isn’t pointing out a problem on the guided interview.
Rate the user’s feedback as ‘spam’ or ‘not spam’ based on the context of the guided interview. Answer only with the exact keywords: ‘spam’ or ‘not spam’.
Was good enough to give me great results in my testing. The wrapper code from Google to make use of this code wasn’t much more. Most of my code is error handling to handle situations where the API key isn’t set up, so I can deploy it more gradually across my clients.
Take a look at the full code for my new spam filter below:
Now, I can protect my client’s feedback forms with confidence that it won’t break the bank.
I did run into one weird gotcha-Gemini added a newline character (“\n”) at the end of its response. I solved that just by removing any white space from the response.
Want to set up your own experiment with Google Gemini? The fancy new model is “gemini-2.0-flash-exp”. You can follow Google’s quick start guide to try it in your own favorite programming language. Want some help? Hire Lemma Legal to help you integrate generative AI into your product, with Google Gemini or another leading edge AI model!
