README-work
WWW::Gemini
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::GeminiFrom GitHub:
zef install https://github.com/antononcube/Raku-WWW-GeminiUsage 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!",
"where is the best coffee made?"],
format => 'values');
say "Shape: ", deduce-type(@vecs);
.say for @vecs;Counting tokens
Here we show how to find the number of tokens in a text:
my $text = q:to/END/;
AI has made surprising successes but cannot solve all scientific problems due to computational irreducibility.
END
gemini-count-tokens($text, format => 'values');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.
Default models
Default models can be specified with the operating system environmental variables:
GEMINI_DEFAULT_MODELGEMINI_DEFAULT_IMAGE_GENERATION_MODELGEMINI_DEFAULT_EMBEDDING_MODEL
Command Line Interface
Maker suite access
The package provides a Command Line Interface (CLI) script:
gemini-prompt --helpRemark: 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:
TODO
TODO Implementation
DONE Function calling support
TODO Image generation
TODO Image editing
TODO Audio generation
TODO Live AI support
TODO Documentation
DONE Core functionalities
DONE Function calling / tool workflow notebook
TODO Image generation
TODO Comparison of OpenAI vs Google image generation
TODO Thinking model(s) demo
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.