Lately, for my Generative AI powered Java apps,
I’ve used the Gemini
multimodal large language model from Google.
But there’s also Gemma,
its little sister model.
Gemma is a family of lightweight, state-of-the-art open models built from the same research
and technology used to create the Gemini models. Gemma is available in two sizes: 2B and 7B.
Its weights are freely available, and its small size means you can run it on your own, even on your laptop.
So I was curious to give it a run with LangChain4j.
No need to be a Python developer to do Generative AI!
If you’re a Java developer, you can take advantage of LangChain4j
to implement some advanced LLM integrations in your Java applications.
And if you’re interested in using
Gemini,
one of the best models available, I invite you to have a look at the following “codelab” that I worked on:
As I was working on tweaking the Vertex AI text embedding model in LangChain4j,
I wanted to better understand how the textembedding-geckomodel
tokenizes the text, in particular when we implement the
Retrieval Augmented Generation approach.
The various PaLM-based models offer a computeTokens endpoint, which returns a list of tokens (encoded in Base 64)
and their respective IDs.
Note
At the time of this writing, there’s no equivalent endpoint for Gemini models.
This week LangChain4j, the LLM orchestration framework for Java developers, released version
0.26.1, which contains my first significant contribution to the open source project:
support for the Imagen image generation model.
Imagen is a text-to-image diffusion model that was announced last year.
And it recently upgraded to Imagen v2, with even higher quality graphics generation.
As I was curious to integrate it in some of my generative AI projects, I thought that would be a great first
contribution to LangChain4j.
My go-to framework when developing Java apps or microservices is
Micronaut.
For the apps that should have a web frontend, I rarely use
Micronaut Views
and its templating support.
Instead, I prefer to just serve static assets from my resource folder,
and have some JavaScript framework (usually Vue.js)
to populate my HTML content (often using
Shoelace for its nice Web Components).
However, the static asset documentation
is a bit light on explanations.
So, since I always forget how to configure Micronaut to serve static assets,
I thought that would be useful to document this here.
A while ago, my friend Sylvain Wallez shared a little bookmarlet on Twitter/X that transforms a dark mode site into light mode. I know the trend is towards dark mode, but for a lot of people with certain vision issues, for example with astigmatism like me, certain dark modes can very painful.
This site about vision (and you’ll find other similar references) mentions that:
People who have myopia or astigmatism also may experience halation (from the word βhaloβ). Halation occurs when light spreads past a certain boundary, creating a foggy or blurry appearance.
In Java, builders are a pretty classical pattern for creating complex objects with lots of attributes.
A nice aspect of builders is that they help reduce the number of constructors you need to create,
in particular when not all attributes are required to be set (or if they have default values).
However, I’ve always found builders a bit verbose with their newBuilder() / build() method combos,
especially when you work with deeply nested object graphs, leading to lines of code of builders of builders of…
In this article, we’ll figure out how to create slugs.
Not the slobbery kind of little gastropods that crawls on the ground. Instead,
we’ll see how to create the short hyphened text you can see in the URL of your web browser,
and that is often a URL-friendly variation of the title of the article.
Interestingly, one of the most popular posts on my blog is an almost 20 year old article that explains
how to remove accents from a string.
And indeed, in slugs you would like to remove accents, among other things.
A promising feature of the Gemini large language model released recently by Google DeepMind,
is the support for function calls.
It’s a way to supplement the model, by letting it know an external functions or APIs can be called.
So you’re not limited by the knowledge cut-off of the model: instead, in the flow of the conversation with the model,
you can pass a list of functions the model will know are available to get the information it needs,
to complete the generation of its answer.
When using a service like Google Cloud Workflows,
in particular as your workflows get bigger, it can be difficult to understand what’s going on under the hood.
With multiple branches, step jumps, iterations, and also parallel branches and iterations,
if your workflow fails during an execution, until now, you had to check the execution status,
or go deep through the logs to find more details about the failed step.
I have good news for you!
Workflows recently added some deeper introspection capability:
you can now view the history of execution steps.
From the Google Cloud console, you can see the lists of steps, and see the logical flow between them.
The usual workflow visualisation will also highlight in green the successful steps, and in red the failed one.
Of course, it is also possible to make a curl call to get the JSON of the
list of executed steps.