As anyone who knows me will tell you I have two passions in life, Artificial Intelligence and of course the grand-daddy passion of them all – FME. And so, imagine my joy when I combined those two passions yesterday and created my very own Gemini AI custom transformer. It was as if all my Christmas’ had come at once and given the timing of this post is a fortunate coincidence.
My enthusiasm for FME is matched only by my inexperience with it, so I often find myself doing things for the first time. Yesterday’s first? Creating a custom transformer. For those unfamiliar, FME comes with over 500 out-of-the box transformers, each designed to interact with your data in a unique way. While the current FME 2024.2 version includes a transformer for communicating with ChatGPT, I wanted to use Google Gemini instead – I simply prefer it.
Talking to the Gemini API: Easier Than You’d Think
It’s super simple to talk to the Gemini API. You use FME’s HTTPCaller transformer which allows you to connect with nearly any API as long as you know the connection string and credentials. Of course, deciphering API documentation can feel like solving a puzzle designed to test your patience (and then some!) but once I had a handle on it, I was able to POST a request to Gemini via the HTTPCaller and get the result I wanted.
Enter the Custom Transformer
I could have stopped there—after all, I was already able to talk to Gemini as expected. However, my amazing colleague Pip suggested going one step further: creating a custom transformer. This would make it easy to reuse, and even allow me to publish it to the FME Community Hub
Challenge accepted!
From a technical standpoint it isn’t all that difficult creating a customer transformer in FME. You start by selecting the transformers that will form the custom transformation, right click and select ‘Create Custom Transformer’. Next, FME prompts you to define the inputs and outputs as well as set up the parameters required by the API.
Key Parameters for AI Integration
Working with AI APIs, it’s common to configure parameters like:
Model: AI’s often have different models that respond in different ways
Prompt: What you want the AI to do – write a story, summarize text, etc.
Max Tokens: Tokens are like an AI’s currency, the more you ‘spend’ the fuller and more detailed the answer to the prompt will be
Temperature: a difficult concept to explain, but a higher temperature results in a more colorful and creative response to the prompt.
It’s also a good idea to set the:
Base URL: which defines part of the API URL prior to the model being set and the API key which authorizes the request.
This will then form a URL that looks a little like this:
Each of these parameters are configured under the Customer Transformers User Parameters and are then entered when the user configures the transformer within FME.
Finishing Touches
Finally, I made a few tweaks to enhance the look of the dialog box for a cleaner, user-friendly interface.
Once the values are configured Gemini will run the prompt and the response body returns the results.
More complicated processes will no doubt make it a little more difficult to create custom transformers, but nevertheless they are a great way of combining multiple (or single) components into an easy to operate, reusable transformer.
More Resources
Contact Chris MorrisLearn more about FME
Register for FME Accelerator: free 90 min intro to FME