tmbb

tmbb

Geminix - bindings to the Google Gemini API generated from the official REST API JSON spec

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?

Popular in Announcing Top

danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
384 13736 119
New
Flo0807
Hello everyone! I am excited to share our heart project Backpex with you. After building several Phoenix applications, we realized that...
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 13966 106
New
marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 10858 107
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement