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

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
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
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
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
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews