tmbb

tmbb

Geminix

Easy to use bindings to the Gemini API. These functions and structs follow the API very closely, making it very easy to follow their usage from the API docs.

The docs can be found at https://hexdocs.pm/geminix.

Why a new binding to a cloud AI API?

I have tried some packages that already exist, and some seem to have weird erros that seem to come from trying to use AI to translate from the API of some other langue into Elixir. This led to a lot of hard-to-debug errors which made me a bit frustrated and distrustful of some solutions out there. Additionally, not all solutions support the Gemini batch APIs, which are a very good fit for my projects.

I’ve decided to see if there was a good API reference, and it turns out Google already publishes a perfectly good REST API spec in JSON format, which is very easy to parse
and generate code from. The compile-time code generators don’t write any files to disk. They instead compile the quoted expressions directly. When required, manually written code is written to help with things such as polling long-running batch jobs.

A simple example from the test cases, showcasing support for the batch API:

alias Geminix.V1beta.{
  GenerateContentRequest,
  GenerateContentResponse,
  BatchGenerateContentRequest,
  GenerationConfig,
  Content,
  InlinedResponses
}

requests = [
  %InlinedRequest{
    metadata: %{
      key: "request-001"
    },
    request: %GenerateContentRequest{
      contents: [
        Content.from_text("What is the capital of Mali?")
      ],
      generation_config: %GenerationConfig{
        response_mime_type: "text/plain"
      }
    }
  },
  %InlinedRequest{
    metadata: %{
      key: "request-002"
    },
    request: %GenerateContentRequest{
      contents: [
        Content.from_text("What is the capital of Germany?")
      ],
      generation_config: %GenerationConfig{
        response_mime_type: "text/plain"
      }
    }
  },
  %InlinedRequest{
    metadata: %{
      key: "request-002"
    },
    request: %GenerateContentRequest{
      contents: [
        Content.from_text("What is the capital of Spain?")
      ],
      generation_config: %GenerationConfig{
        response_mime_type: "text/plain"
      }
    }
  }
]

{:ok, batch} =
  BatchGenerateContentRequest.start(
    "gemini-2.5-flash",
    requests,
    display_name: "Test batch"
  )

{:ok, batch} =
  BatchGenerateContentRequest.await(
    batch,
    poll_interval: 30_000
  )

{:ok, inlined_responses} = BatchGenerateContentRequest.get_output(batch)

assert %Geminix.V1beta.InlinedResponses{} = inlined_responses

While the API is somewhat verbose, due to all the relative “strong typing” and the large amount of structures, it is very close to the official API, which makes it very easy to configure everything to your needs, unlike approaches which try to simiplify a very complex API into a small handfull of knobs and dials. You can always write a simple wrapper on top of all the complexity so that it works better for you.

https://github.com/tmbb/geminix

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
pferriby
Introductory paragraph I’ll be looking for a keen junior or someone that has a couple of years experience in the real world (so you’ve be...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews