README-work

WWW::Gemini Raku package

Raku package for connecting with Google's Gemini. It is based on the Web API described in Gemini's API documentation.

The design and implementation of the package closely follows those of "WWW::PaLM", [AAp1], and "WWW::OpenAI", [AAp2].

Installation

From Zef ecosystem:

zef install WWW::Gemini

From GitHub:

zef install https://github.com/antononcube/Raku-WWW-Gemini

Usage examples

Show models:

use WWW::Gemini;

gemini-models()

Show text generation:

.say for gemini-generate-content('what is the population in Brazil?', format => 'values');

Using a synonym function:

.say for gemini-generation('Who wrote the book "Dune"?');

Embeddings

Show text embeddings:

use Data::TypeSystem;

my @vecs = gemini-embed-content(["say something nice!",
                            "shout something bad!",
                            "wher is the best coffee made?"],
        format => 'values');

say "Shape: ", deduce-type(@vecs);
.say for @vecs;

Vision

If the function gemini-completion is given a list of images, textual results corresponding to those images is returned. The argument "images" is a list of image URLs, image file names, or image Base64 representations. (Any combination of those element types.)

Here is an example with this image:

my $fname = $*CWD ~ '/resources/ThreeHunters.jpg';
my @images = [$fname,];
say gemini-generation("Give concise descriptions of the images.", :@images, format => 'values');

When a file name is given to the argument "images" of gemini-completion then the function encode-image of "Image::Markup::Utilities", [AAp4], is applied to it.

Command Line Interface

Maker suite access

The package provides a Command Line Interface (CLI) script:

gemini-prompt --help

Remark: When the authorization key argument "auth-key" is specified set to "Whatever" then gemini-prompt attempts to use one of the env variables GEMINI_API_KEY or PALM_API_KEY.

Mermaid diagram

The following flowchart corresponds to the steps in the package function gemini-prompt:

References

Articles

[AA1] Anton Antonov, "Workflows with LLM functions", (2023), RakuForPredictions at WordPress.

[AA2] Anton Antonov, "Number guessing games: Gemini vs ChatGPT" (2023), RakuForPredictions at WordPress.

[ZG1] Zoubin Ghahramani, "Introducing Gemini 2", (2023), Google Official Blog on AI.

Packages, platforms

[AAp1] Anton Antonov, WWW::PaLM Raku package, (2023-2024), GitHub/antononcube.

[AAp2] Anton Antonov, WWW::OpenAI Raku package, (2023-2024), GitHub/antononcube.

[AAp3] Anton Antonov, LLM::Functions Raku package, (2023-2024), GitHub/antononcube.

[AAp4] Anton Antonov, Image::Markup::Utilities Raku package, (2023-2024), GitHub/antononcube.

[AAp5] Anton Antonov, ML::FindTextualAnswer Raku package, (2023-2024), GitHub/antononcube.

WWW::Gemini v0.0.7

WWW::Gemini provides access to Google's Gemini.

Authors

  • Anton Antonov

License

Artistic-2.0

Dependencies

HTTP::Tiny:ver<0.2.5+>JSON::Fast:ver<0.17+>Image::Markup::Utilities:ver<0.1.1+>:auth<zef:antononcube>

Test Dependencies

Provides

  • WWW::Gemini
  • WWW::Gemini::EmbedContent
  • WWW::Gemini::GenerateContent
  • WWW::Gemini::Models
  • WWW::Gemini::Request

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.