Metadata-Version: 2.4
Name: cjm-transcription-plugin-gemini
Version: 0.0.13
Summary: Google Gemini API plugin for the cjm-transcription-plugin-system library - provides speech-to-text transcription with configurable model selection and parameter control.
Home-page: https://github.com/cj-mills/cjm-transcription-plugin-gemini
Author: Christian J. Mills
Author-email: 9126128+cj-mills@users.noreply.github.com
License: Apache Software License 2.0
Keywords: nbdev jupyter notebook python
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastcore
Requires-Dist: pandas
Requires-Dist: cjm_transcription_plugin_system
Requires-Dist: cjm_ffmpeg_utils
Requires-Dist: google-genai
Requires-Dist: numpy
Requires-Dist: soundfile
Provides-Extra: dev
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# cjm-transcription-plugin-gemini


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Install

``` bash
pip install cjm_transcription_plugin_gemini
```

## Project Structure

    nbs/
    ├── meta.ipynb   # Metadata introspection for the Gemini plugin used by cjm-ctl to generate the registration manifest.
    └── plugin.ipynb # Plugin implementation for Google Gemini API transcription

Total: 2 notebooks across 1 directory

## Module Dependencies

``` mermaid
graph LR
    meta[meta<br/>Metadata]
    plugin[plugin<br/>Gemini Plugin]

    plugin --> meta
```

*1 cross-module dependencies detected*

## CLI Reference

No CLI commands found in this project.

## Module Overview

Detailed documentation for each module in the project:

### Metadata (`meta.ipynb`)

> Metadata introspection for the Gemini plugin used by cjm-ctl to
> generate the registration manifest.

#### Import

``` python
from cjm_transcription_plugin_gemini.meta import (
    get_plugin_metadata
)
```

#### Functions

``` python
def get_plugin_metadata() -> Dict[str, Any]: # Plugin metadata for manifest generation
    """Return metadata required to register this plugin with the PluginManager."""
    # Fallback base path (current behavior for backward compatibility)
    base_path = os.path.dirname(os.path.dirname(sys.executable))
    
    # Use CJM config if available, else fallback to env-relative paths
    cjm_data_dir = os.environ.get("CJM_DATA_DIR")
    
    # Plugin data directory
    plugin_name = "cjm-transcription-plugin-gemini"
    if cjm_data_dir
    "Return metadata required to register this plugin with the PluginManager."
```

### Gemini Plugin (`plugin.ipynb`)

> Plugin implementation for Google Gemini API transcription

#### Import

``` python
from cjm_transcription_plugin_gemini.plugin import (
    GeminiPluginConfig,
    GeminiPlugin
)
```

#### Functions

``` python
@patch
def _get_api_key(
    self:GeminiPlugin
) -> str:  # The API key string
    "Get API key from config or environment."
```

``` python
@patch
def _refresh_available_models(
    self:GeminiPlugin
) -> List[str]:  # List of available model names
    "Fetch and filter available models from Gemini API."
```

``` python
@patch
def _update_max_tokens_for_model(
    self:GeminiPlugin,
    model_name: str  # Model name to update tokens for
) -> None
    "Update max_output_tokens config based on the model's token limit."
```

``` python
@patch
def update_config(
    self:GeminiPlugin,
    config: Union[Dict[str, Any], GeminiPluginConfig]  # New configuration values
) -> None
    "Update plugin configuration, adjusting max_tokens if model changes."
```

``` python
@patch
def _prepare_audio(
    self:GeminiPlugin,
    audio: Union[AudioData, str, Path]  # Audio data object or path to audio file
) -> Tuple[Path, bool]:  # Tuple of (processed audio path, whether temp file was created)
    "Prepare audio file for upload."
```

``` python
@patch
def _upload_audio_file(
    self:GeminiPlugin,
    audio_path: Path  # Path to audio file to upload
) -> Any:  # Uploaded file object
    "Upload audio file to Gemini API."
```

``` python
@patch
def _delete_uploaded_file(
    self:GeminiPlugin,
    file_name: str  # Name of file to delete
) -> None
    "Delete an uploaded file from Gemini API."
```

``` python
@patch
def get_available_models(
    self:GeminiPlugin
) -> List[str]:  # List of available model names
    "Get list of available audio-capable models."
```

``` python
@patch
def get_model_info(
    self:GeminiPlugin,
    model_name: Optional[str] = None  # Model name to get info for, defaults to current model
) -> Dict[str, Any]:  # Dict with model information
    "Get information about a specific model including token limits."
```

``` python
@patch
def supports_streaming(
    self:GeminiPlugin
) -> bool:  # True if streaming is supported
    "Check if this plugin supports streaming transcription."
```

``` python
@patch
def execute_stream(
    self:GeminiPlugin,
    audio: Union[AudioData, str, Path],  # Audio data object or path to audio file
    **kwargs  # Additional arguments to override config
) -> Generator[str, None, TranscriptionResult]:  # Yields text chunks, returns final result
    "Stream transcription results chunk by chunk."
```

#### Classes

``` python
@dataclass
class GeminiPluginConfig:
    "Configuration for Gemini transcription plugin."
    
    model: str = field(...)
    api_key: Optional[str] = field(...)
    prompt: str = field(...)
    temperature: float = field(...)
    top_p: float = field(...)
    max_output_tokens: int = field(...)
    seed: Optional[int] = field(...)
    response_mime_type: str = field(...)
    downsample_audio: bool = field(...)
    downsample_rate: int = field(...)
    downsample_channels: int = field(...)
    safety_settings: str = field(...)
    auto_refresh_models: bool = field(...)
    model_filter: List[str] = field(...)
    use_file_upload: bool = field(...)
    use_streaming: bool = field(...)
    delete_uploaded_files: bool = field(...)
```

``` python
class GeminiPlugin:
    def __init__(self):
        """Initialize the Gemini plugin with default configuration."""
        self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
        self.config: GeminiPluginConfig = None
    "Google Gemini API transcription plugin."
    
    def __init__(self):
            """Initialize the Gemini plugin with default configuration."""
            self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
            self.config: GeminiPluginConfig = None
        "Initialize the Gemini plugin with default configuration."
    
    def name(self) -> str: # Plugin name identifier
            """Return the plugin name identifier."""
            return "gemini"
        
        @property
        def version(self) -> str: # Plugin version string
        "Return the plugin name identifier."
    
    def version(self) -> str: # Plugin version string
            """Return the plugin version string."""
            return "1.0.0"
        
        @property
        def supported_formats(self) -> List[str]: # List of supported audio formats
        "Return the plugin version string."
    
    def supported_formats(self) -> List[str]: # List of supported audio formats
            """Return list of supported audio file formats."""
            return ["wav", "mp3", "aiff", "aac", "ogg", "flac"]
    
        def get_current_config(self) -> Dict[str, Any]: # Current configuration as dictionary
        "Return list of supported audio file formats."
    
    def get_current_config(self) -> Dict[str, Any]: # Current configuration as dictionary
            """Return current configuration state."""
            if not self.config
        "Return current configuration state."
    
    def get_config_schema(self) -> Dict[str, Any]: # JSON Schema for configuration
            """Return JSON Schema for UI generation."""
            return dataclass_to_jsonschema(GeminiPluginConfig)
    
        @staticmethod
        def get_config_dataclass() -> GeminiPluginConfig: # Configuration dataclass
        "Return JSON Schema for UI generation."
    
    def get_config_dataclass() -> GeminiPluginConfig: # Configuration dataclass
            """Return dataclass describing the plugin's configuration options."""
            return GeminiPluginConfig
        
        def initialize(
            self,
            config: Optional[Any] = None # Configuration dataclass, dict, or None
        ) -> None
        "Return dataclass describing the plugin's configuration options."
    
    def initialize(
            self,
            config: Optional[Any] = None # Configuration dataclass, dict, or None
        ) -> None
        "Initialize or re-configure the plugin (idempotent)."
    
    def execute(
            self,
            audio: Union[AudioData, str, Path], # Audio data object or path to audio file
            **kwargs # Additional arguments to override config
        ) -> TranscriptionResult: # Transcription result object
        "Transcribe audio using Gemini."
    
    def is_available(self) -> bool: # True if the Gemini API is available
            """Check if Gemini API is available."""
            return GEMINI_AVAILABLE
    
        def cleanup(
            self
        ) -> None
        "Check if Gemini API is available."
    
    def cleanup(
            self
        ) -> None
        "Clean up resources."
```
