Skip to main content

LLM plugin to access Google's Gemini family of models

Project description

llm-gemini

PyPI Changelog Tests License

API access to Google's Gemini models

Installation

Install this plugin in the same environment as LLM.

llm install llm-gemini

Usage

Configure the model by setting a key called "gemini" to your API key:

llm keys set gemini
<paste key here>

You can also set the API key by assigning it to the environment variable LLM_GEMINI_KEY.

Now run the model using -m gemini-1.5-pro-latest, for example:

llm -m gemini-1.5-pro-latest "A joke about a pelican and a walrus"

A pelican walks into a seafood restaurant with a huge fish hanging out of its beak. The walrus, sitting at the bar, eyes it enviously.

"Hey," the walrus says, "That looks delicious! What kind of fish is that?"

The pelican taps its beak thoughtfully. "I believe," it says, "it's a billfish."

Other models are:

  • gemini-1.5-flash-latest
  • gemini-1.5-flash-8b-latest - the least expensive
  • gemini-exp-1114 - recent experimental

Images, audio and video

Gemini models are multi-modal. You can provide images, audio or video files as input like this:

llm -m gemini-1.5-flash-latest 'extract text' -a image.jpg

Or with a URL:

llm -m gemini-1.5-flash-8b-latest 'describe image' \
  -a https://static.simonwillison.net/static/2024/pelicans.jpg

Audio works too:

llm -m gemini-1.5-pro-latest 'transcribe audio' -a audio.mp3

And video:

llm -m gemini-1.5-pro-latest 'describe what happens' -a video.mp4

The Gemini prompting guide includes extensive advice on multi-modal prompting.

JSON output

Use -o json_object 1 to force the output to be JSON:

llm -m gemini-1.5-flash-latest -o json_object 1 \
  '3 largest cities in California, list of {"name": "..."}'

Outputs:

{"cities": [{"name": "Los Angeles"}, {"name": "San Diego"}, {"name": "San Jose"}]}

Code execution

Gemini models can write and execute code - they can decide to write Python code, execute it in a secure sandbox and use the result as part of their response.

To enable this feature, use -o code_execution 1:

llm -m gemini-1.5-pro-latest -o code_execution 1 \
'use python to calculate (factorial of 13) * 3'

Chat

To chat interactively with the model, run llm chat:

llm chat -m gemini-1.5-pro-latest

Embeddings

The plugin also adds support for the text-embedding-004 embedding model.

Run that against a single string like this:

llm embed -m text-embedding-004 -c 'hello world'

This returns a JSON array of 768 numbers.

This command will embed every README.md file in child directories of the current directory and store the results in a SQLite database called embed.db in a collection called readmes:

llm embed-multi readmes --files . '*/README.md' -d embed.db -m text-embedding-004

You can then run similarity searches against that collection like this:

llm similar readmes -c 'upload csvs to stuff' -d embed.db

See the LLM embeddings documentation for further details.

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd llm-gemini
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

llm install -e '.[test]'

To run the tests:

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_gemini-0.4.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

llm_gemini-0.4-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file llm_gemini-0.4.tar.gz.

File metadata

  • Download URL: llm_gemini-0.4.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for llm_gemini-0.4.tar.gz
Algorithm Hash digest
SHA256 3b992e4c9609eac08aa2587a50a12b5d5e59b094a2f48f3fb2fd26f86f052ff8
MD5 db5c4fcb8f497157ad2537e5c0185f94
BLAKE2b-256 79e6019e31117846dd25f2f288bdfd407968e287b1756a9f31f5639da4405ee9

See more details on using hashes here.

File details

Details for the file llm_gemini-0.4-py3-none-any.whl.

File metadata

  • Download URL: llm_gemini-0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for llm_gemini-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 464e61da80a5f95bb844e56d195c2e8dda70bebcf3b9a63cb31f0ffcc32501c2
MD5 9d0b44f680ee2605ced25eafc2d70634
BLAKE2b-256 6e83737c099a7b7600f09e42c63205ee0e27329568ab56893a206204d26ce037

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page