{"id":15433008,"url":"https://github.com/simonw/llm-gemini","last_synced_at":"2025-05-15T08:04:56.044Z","repository":{"id":212361852,"uuid":"731319430","full_name":"simonw/llm-gemini","owner":"simonw","description":"LLM plugin to access Google's Gemini family of models","archived":false,"fork":false,"pushed_at":"2025-05-13T23:05:10.000Z","size":145,"stargazers_count":308,"open_issues_count":11,"forks_count":34,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-14T01:06:54.918Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"simonw"}},"created_at":"2023-12-13T20:17:45.000Z","updated_at":"2025-05-10T12:56:22.000Z","dependencies_parsed_at":"2024-08-26T18:58:29.421Z","dependency_job_id":"89b5780a-c81b-4650-9e28-a048e09d5401","html_url":"https://github.com/simonw/llm-gemini","commit_stats":{"total_commits":26,"total_committers":3,"mean_commits":8.666666666666666,"dds":0.07692307692307687,"last_synced_commit":"ce82727a6950c7769a8e40bf030591d0e6f83e5e"},"previous_names":["simonw/llm-gemini"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-gemini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-gemini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-gemini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-gemini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/llm-gemini/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254095573,"owners_count":22013794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T18:30:24.944Z","updated_at":"2025-05-15T08:04:56.033Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":["https://github.com/sponsors/simonw"],"categories":[],"sub_categories":[],"readme":"# llm-gemini\n\n[![PyPI](https://img.shields.io/pypi/v/llm-gemini.svg)](https://pypi.org/project/llm-gemini/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/llm-gemini?include_prereleases\u0026label=changelog)](https://github.com/simonw/llm-gemini/releases)\n[![Tests](https://github.com/simonw/llm-gemini/workflows/Test/badge.svg)](https://github.com/simonw/llm-gemini/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/llm-gemini/blob/main/LICENSE)\n\nAPI access to Google's Gemini models\n\n## Installation\n\nInstall this plugin in the same environment as [LLM](https://llm.datasette.io/).\n```bash\nllm install llm-gemini\n```\n## Usage\n\nConfigure the model by setting a key called \"gemini\" to your [API key](https://aistudio.google.com/app/apikey):\n```bash\nllm keys set gemini\n```\n```\n\u003cpaste key here\u003e\n```\nYou can also set the API key by assigning it to the environment variable `LLM_GEMINI_KEY`.\n\nNow run the model using `-m gemini-2.0-flash`, for example:\n\n```bash\nllm -m gemini-2.0-flash \"A short joke about a pelican and a walrus\"\n```\n\n\u003e A pelican and a walrus are sitting at a bar. The pelican orders a fishbowl cocktail, and the walrus orders a plate of clams. The bartender asks, \"So, what brings you two together?\"\n\u003e\n\u003e The walrus sighs and says, \"It's a long story. Let's just say we met through a mutual friend... of the fin.\"\n\nYou can set the [default model](https://llm.datasette.io/en/stable/setup.html#setting-a-custom-default-model) to avoid the extra `-m` option:\n\n```bash\nllm models default gemini-2.0-flash\nllm \"A joke about a pelican and a walrus\"\n```\n\nOther models are:\n\n- `gemini-2.5-pro-preview-05-06` - latest paid Gemini 2.5 Pro preview\n- `gemini-2.5-flash-preview-04-17` - Gemini 2.5 Flash preview\n- `gemini-2.5-pro-exp-03-25` - free experimental release of Gemini 2.5 Pro\n- `gemini-2.5-pro-preview-03-25` - paid preview of Gemini 2.5 Pro\n- `gemma-3-27b-it` - [Gemma 3](https://blog.google/technology/developers/gemma-3/) 27B\n- `gemini-2.0-pro-exp-02-05` - experimental release of Gemini 2.0 Pro\n- `gemini-2.0-flash-lite` - Gemini 2.0 Flash-Lite\n- `gemini-2.0-flash` - Gemini 2.0 Flash\n- `gemini-2.0-flash-thinking-exp-01-21` - experimental \"thinking\" model from January 2025\n- `gemini-2.0-flash-thinking-exp-1219` - experimental \"thinking\" model from December 2024\n- `learnlm-1.5-pro-experimental` - \"an experimental task-specific model that has been trained to align with learning science principles\" - [more details here](https://ai.google.dev/gemini-api/docs/learnlm).\n- `gemini-2.0-flash-exp` - [Gemini 2.0 Flash](https://blog.google/technology/google-deepmind/google-gemini-ai-update-december-2024/#gemini-2-0-flash)\n- `gemini-exp-1206` - recent experimental #3\n- `gemini-exp-1121` - recent experimental #2\n- `gemini-exp-1114` - recent experimental #1\n- `gemini-1.5-flash-8b-latest` - the least expensive\n- `gemini-1.5-flash-latest`\n\n### Images, audio and video\n\nGemini models are multi-modal. You can provide images, audio or video files as input like this:\n\n```bash\nllm -m gemini-2.0-flash 'extract text' -a image.jpg\n```\nOr with a URL:\n```bash\nllm -m gemini-2.0-flash-lite 'describe image' \\\n  -a https://static.simonwillison.net/static/2024/pelicans.jpg\n```\nAudio works too:\n\n```bash\nllm -m gemini-2.0-flash 'transcribe audio' -a audio.mp3\n```\n\nAnd video:\n\n```bash\nllm -m gemini-2.0-flash 'describe what happens' -a video.mp4\n```\nThe Gemini prompting guide includes [extensive advice](https://ai.google.dev/gemini-api/docs/file-prompting-strategies) on multi-modal prompting.\n\n### JSON output\n\nUse `-o json_object 1` to force the output to be JSON:\n\n```bash\nllm -m gemini-2.0-flash -o json_object 1 \\\n  '3 largest cities in California, list of {\"name\": \"...\"}'\n```\nOutputs:\n```json\n{\"cities\": [{\"name\": \"Los Angeles\"}, {\"name\": \"San Diego\"}, {\"name\": \"San Jose\"}]}\n```\n\n### Code execution\n\nGemini models can [write and execute code](https://ai.google.dev/gemini-api/docs/code-execution) - they can decide to write Python code, execute it in a secure sandbox and use the result as part of their response.\n\nTo enable this feature, use `-o code_execution 1`:\n\n```bash\nllm -m gemini-2.0-flash -o code_execution 1 \\\n'use python to calculate (factorial of 13) * 3'\n```\n### Google search\n\nSome Gemini models support [Grounding with Google Search](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-gemini#web-ground-gemini), where the model can run a Google search and use the results as part of answering a prompt.\n\nUsing this feature may incur additional requirements in terms of how you use the results. Consult [Google's documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-gemini#web-ground-gemini) for more details.\n\nTo run a prompt with Google search enabled, use `-o google_search 1`:\n\n```bash\nllm -m gemini-2.0-flash -o google_search 1 \\\n  'What happened in Ireland today?'\n```\n\nUse `llm logs -c --json` after running a prompt to see the full JSON response, which includes [additional information](https://github.com/simonw/llm-gemini/pull/29#issuecomment-2606201877) about grounded results.\n\n### Chat\n\nTo chat interactively with the model, run `llm chat`:\n\n```bash\nllm chat -m gemini-2.0-flash\n```\n\n## Embeddings\n\nThe plugin also adds support for the `gemini-embedding-exp-03-07` and `text-embedding-004` embedding models.\n\nRun that against a single string like this:\n```bash\nllm embed -m text-embedding-004 -c 'hello world'\n```\nThis returns a JSON array of 768 numbers.\n\nThe `gemini-embedding-exp-03-07` model is larger, returning 3072 numbers. You can also use variants of it that are truncated down to smaller sizes:\n\n- `gemini-embedding-exp-03-07` - 3072 numbers\n- `gemini-embedding-exp-03-07-2048` - 2048 numbers\n- `gemini-embedding-exp-03-07-1024` - 1024 numbers\n- `gemini-embedding-exp-03-07-512` - 512 numbers\n- `gemini-embedding-exp-03-07-256` - 256 numbers\n- `gemini-embedding-exp-03-07-128` - 128 numbers\n\nThis 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`:\n\n```bash\nllm embed-multi readmes -d embed.db -m gemini-embedding-exp-03-07-128 \\\n  --files . '*/README.md'\n```\nYou can then run similarity searches against that collection like this:\n```bash\nllm similar readmes -c 'upload csvs to stuff' -d embed.db\n```\n\nSee the [LLM embeddings documentation](https://llm.datasette.io/en/stable/embeddings/cli.html) for further details.\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n```bash\ncd llm-gemini\npython3 -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\nllm install -e '.[test]'\n```\nTo run the tests:\n```bash\npytest\n```\n\nThis project uses [pytest-recording](https://github.com/kiwicom/pytest-recording) to record Gemini API responses for the tests.\n\nIf you add a new test that calls the API you can capture the API response like this:\n```bash\nPYTEST_GEMINI_API_KEY=\"$(llm keys get gemini)\" pytest --record-mode once\n```\nYou will need to have stored a valid Gemini API key using this command first:\n```bash\nllm keys set gemini\n# Paste key here\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fllm-gemini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fllm-gemini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fllm-gemini/lists"}