Skip to main content

Gemini provider plugin for llm-sdk.

Project description

llm-sdk-provider-gemini

Gemini provider plugin for llm-sdk, implemented using google-genai (Vertex AI). This package installs a provider plugin via Python entry points, enabling Gemini support without modifying the core SDK.


Table of Contents


Overview

llm-sdk-provider-gemini is a plugin package that adds support for:

  • Gemini chat completions
  • Gemini embeddings
  • Gemini streaming chat

It integrates with the llm-sdk core using Python entry points, so the provider is automatically discoverable via:

sdk.registry.load_plugins()

Architecture

Plugin mechanism

This package declares an entry point:

[project.entry-points."llm_sdk.providers"]
gemini = "llm_sdk_provider_gemini.plugin:GeminiProviderFactory"

At runtime:

  1. llm-sdk scans installed packages for llm_sdk.providers
  2. Loads the GeminiProviderFactory
  3. Calls:
    • spec() for metadata
    • create(settings) to build a provider client

Features

  • Async Gemini client
  • Supports:
    • chat completions
    • embeddings
    • streaming chat
  • Uses google-genai (Vertex AI mode)
  • Unified SDK error mapping (ProviderError)
  • Strong typing
  • Clean separation from SDK core

Installation

Install core SDK

pip install llm-sdk

Install Gemini provider

pip install llm-sdk-provider-gemini

Usage

Async quickstart

import asyncio
from llm_sdk.async_sdk import AsyncSDK


async def main() -> None:
    sdk = AsyncSDK.default()

    # Load installed plugins (entry points)
    sdk.registry.load_plugins()

    resp = await sdk.chat(
        provider="gemini",
        model="gemini-2.5-flash",
        messages=[("user", "Write a haiku about software architecture.")],
    )

    print(resp.content)


if __name__ == "__main__":
    asyncio.run(main())

Streaming example

import asyncio
from llm_sdk.async_sdk import AsyncSDK


async def main() -> None:
    sdk = AsyncSDK.default()
    sdk.registry.load_plugins()

    async for ev in sdk.stream_chat(
        provider="gemini",
        model="gemini-2.5-flash",
        messages=[("user", "Explain AI in Spanish, in 5 short bullets.")],
    ):
        print(ev.delta, end="", flush=True)

    print("\n[done]")


if __name__ == "__main__":
    asyncio.run(main())

Embeddings example

import asyncio
from llm_sdk.async_sdk import AsyncSDK


async def main() -> None:
    sdk = AsyncSDK.default()
    sdk.registry.load_plugins()

    resp = await sdk.embed(
        provider="gemini",
        model="text-multilingual-embedding-002",
        input=["Hola mundo", "Hello world"],
    )

    print(resp.vectors[0][:10])


if __name__ == "__main__":
    asyncio.run(main())

Configuration

This provider uses Google credentials from the environment.

Authentication (Vertex AI)

You must have:

  • Google Cloud project enabled for Vertex AI
  • Proper credentials available through ADC (Application Default Credentials)

Typical local setup:

gcloud auth application-default login

Provider-specific settings

This package typically reads:

  • Gemini location (example: us-central1)

Depending on your llm-sdk settings design, you may configure:

export LLM_SDK_LOCATION="us-central1"

Or if you implement namespaced settings:

export LLM_SDK_GEMINI_LOCATION="us-central1"

Project Structure

llm-sdk-provider-gemini/
├─ src/
│  └─ llm_sdk_provider_gemini/
│     ├─ plugin.py
│     ├─ settings.py
│     ├─ async_client.py
│     ├─ sync_client.py
│     └─ __init__.py
├─ tests/
│  ├─ test_factory.py
│  └─ test_contracts.py
├─ pyproject.toml
└─ README.md

Setup

Development

python -m venv venv
source venv/bin/activate
pip install -U pip
pip install -e .

Install core SDK in editable mode (local dev)

pip install -e ../llm-sdk

Testing

pytest -q

Notes

Provider tests should include:

  • Factory loads correctly
  • Spec metadata is correct
  • Client implements required methods
  • Error mapping works as expected

Avoid real network tests in unit tests. If you want integration tests, put them behind an env flag.


Deployment

Build package

python -m build

Upload to TestPyPI

python -m twine upload --repository testpypi dist/*

Upload to PyPI

python -m twine upload dist/*

Roadmap

  • Better usage extraction for Gemini responses
  • Support for Gemini tool calling (if SDK adds tool abstractions)
  • Optional support for non-Vertex Gemini API mode
  • Optional response caching hooks

Contributing

PRs welcome.

Recommended workflow:

  1. Fork repo
  2. Create a feature branch
  3. Add tests
  4. Run pytest
  5. Submit PR

License

MIT License


Contact

Author: Esteban Flores

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_sdk_provider_gemini-0.2.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_sdk_provider_gemini-0.2.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file llm_sdk_provider_gemini-0.2.0.tar.gz.

File metadata

  • Download URL: llm_sdk_provider_gemini-0.2.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for llm_sdk_provider_gemini-0.2.0.tar.gz
Algorithm Hash digest
SHA256 50c5576637695766eddfc80e29526f9af001cfe4cd702e21eb49a9a100ae02da
MD5 0295665e3dc6296b635cfbbfbc47004a
BLAKE2b-256 39d812c7b8b7cf8d47e7f3cf4df9d1ea6cbd74face85c0002f6ebc22ca48fe73

See more details on using hashes here.

File details

Details for the file llm_sdk_provider_gemini-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_sdk_provider_gemini-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8234cfde47ce7003b9d0ed4734db48bd359526f831279695351cb56c592266c
MD5 045a2a215bedc992f698c125a51961f8
BLAKE2b-256 5436e4d8bf9c4803d5ef16236cc226d9ba2c45a2a0af2a79d01c8c8f5b55f20c

See more details on using hashes here.

Supported by

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