Skip to content

GeminiModelConfig

Base classes

Name Children Inherits
BaseModelConfig
llmling_models_config.configs
Base for model configurations.

â‹” Inheritance diagram

graph TD
  4186269012["configs.GeminiModelConfig"]
  3497727833["configs.BaseModelConfig"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  3497727833 --> 4186269012
  330168112 --> 3497727833
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseModelConfig

Configuration for Gemini models.

Source code in src/llmling_models_config/configs.py
class GeminiModelConfig(BaseModelConfig):
    """Configuration for Gemini models."""

    model_config = ConfigDict(json_schema_extra={"x-doc-title": "Gemini model"})

    type: Literal["gemini"] = Field(default="gemini", init=False)
    """Type identifier for Gemini model."""

    identifier: GeminiModelName | str = Field(
        examples=["gemini-2.0-flash", "gemini-1.5-pro"],
        title="Model identifier",
    )
    """String identifier for the model."""

    max_tokens: int | None = Field(
        default=None,
        ge=1,
        examples=[1024, 2048, 4096],
        title="Maximum tokens",
    )
    """The maximum number of tokens to generate before stopping."""

    temperature: float | None = Field(
        default=None,
        ge=0.0,
        examples=[0.0, 0.7, 1.0, 2.0],
        title="Temperature",
    )
    """Amount of randomness injected into the response."""

    top_p: float | None = Field(
        default=None,
        ge=0.0,
        le=1.0,
        examples=[0.1, 0.9, 1.0],
        title="Top-p (nucleus sampling)",
    )
    """An alternative to sampling with temperature, called nucleus sampling."""

    timeout: float | None = Field(
        default=None,
        examples=[30.0, 60.0, 120.0],
        title="Request timeout",
    )
    """Override the client-level default timeout for a request, in seconds."""

    parallel_tool_calls: bool | None = Field(
        default=None,
        title="Allow parallel tool calls",
    )
    """Whether to allow parallel tool calls."""

    seed: int | None = Field(
        default=None,
        examples=[42, 123, 999],
        title="Random seed",
    )
    """The random seed to use for the model, theoretically allowing for deterministic results."""

    presence_penalty: float | None = Field(
        default=None,
        ge=-2.0,
        le=2.0,
        examples=[-1.0, 0.0, 0.5, 1.0],
        title="Presence penalty",
    )
    """Penalize new tokens based on whether they have appeared in the text so far."""

    frequency_penalty: float | None = Field(
        default=None,
        ge=-2.0,
        le=2.0,
        examples=[-1.0, 0.0, 0.5, 1.0],
        title="Frequency penalty",
    )
    """Penalize new tokens based on their existing frequency in the text so far."""

    logit_bias: dict[str, int] | None = Field(
        default=None,
        title="Logit bias",
        examples=[{"5678": -100}, {"1234": 100}],
    )
    """Modify the likelihood of specified tokens appearing in the completion."""

    stop_sequences: list[str] | None = Field(
        default=None,
        examples=[["STOP", "END"], ["\n\n"]],
        title="Stop sequences",
    )
    """Sequences that will cause the model to stop generating."""

    extra_headers: dict[str, str] | None = Field(
        default=None,
        examples=[{"Custom-Header": "value"}],
        title="Extra headers",
    )
    """Extra headers to send to the model."""

    extra_body: Any | None = Field(
        default=None,
        title="Extra body",
    )
    """Extra body to send to the model."""

    safety_settings: list[dict[str, Any]] | None = Field(
        default=None,
        title="Safety settings",
    )
    """Safety settings options for Gemini model request."""

    thinking_config: dict[str, Any] | None = Field(
        default=None,
        title="Thinking configuration",
    )
    """Thinking features configuration."""

    labels: dict[str, str] | None = Field(
        default=None,
        title="Vertex AI labels",
    )
    """User-defined metadata to break down billed charges."""

    def get_model_settings(self) -> GoogleModelSettings:
        """Get model settings in pydantic-ai format."""
        from pydantic_ai.models.google import GoogleModelSettings

        settings = {
            "max_tokens": self.max_tokens,
            "temperature": self.temperature,
            "top_p": self.top_p,
            "timeout": self.timeout,
            "parallel_tool_calls": self.parallel_tool_calls,
            "seed": self.seed,
            "presence_penalty": self.presence_penalty,
            "frequency_penalty": self.frequency_penalty,
            "logit_bias": self.logit_bias,
            "stop_sequences": self.stop_sequences,
            "extra_headers": self.extra_headers,
            "extra_body": self.extra_body,
            "google_safety_settings": self.safety_settings,
            "google_thinking_config": self.thinking_config,
            "google_labels": self.labels,
        }
        return GoogleModelSettings(**{k: v for k, v in settings.items() if v is not None})  # type: ignore[typeddict-item, no-any-return]

    def get_model(self) -> Any:
        from llmling_models import infer_model

        return infer_model("gemini:" + self.identifier)

extra_body class-attribute instance-attribute

extra_body: Any | None = Field(default=None, title='Extra body')

Extra body to send to the model.

extra_headers class-attribute instance-attribute

extra_headers: dict[str, str] | None = Field(
    default=None, examples=[{"Custom-Header": "value"}], title="Extra headers"
)

Extra headers to send to the model.

frequency_penalty class-attribute instance-attribute

frequency_penalty: float | None = Field(
    default=None, ge=-2.0, le=2.0, examples=[-1.0, 0.0, 0.5, 1.0], title="Frequency penalty"
)

Penalize new tokens based on their existing frequency in the text so far.

identifier class-attribute instance-attribute

identifier: GeminiModelName | str = Field(
    examples=["gemini-2.0-flash", "gemini-1.5-pro"], title="Model identifier"
)

String identifier for the model.

labels class-attribute instance-attribute

labels: dict[str, str] | None = Field(default=None, title='Vertex AI labels')

User-defined metadata to break down billed charges.

logit_bias class-attribute instance-attribute

logit_bias: dict[str, int] | None = Field(
    default=None, title="Logit bias", examples=[{"5678": -100}, {"1234": 100}]
)

Modify the likelihood of specified tokens appearing in the completion.

max_tokens class-attribute instance-attribute

max_tokens: int | None = Field(
    default=None, ge=1, examples=[1024, 2048, 4096], title="Maximum tokens"
)

The maximum number of tokens to generate before stopping.

parallel_tool_calls class-attribute instance-attribute

parallel_tool_calls: bool | None = Field(default=None, title='Allow parallel tool calls')

Whether to allow parallel tool calls.

presence_penalty class-attribute instance-attribute

presence_penalty: float | None = Field(
    default=None, ge=-2.0, le=2.0, examples=[-1.0, 0.0, 0.5, 1.0], title="Presence penalty"
)

Penalize new tokens based on whether they have appeared in the text so far.

safety_settings class-attribute instance-attribute

safety_settings: list[dict[str, Any]] | None = Field(default=None, title='Safety settings')

Safety settings options for Gemini model request.

seed class-attribute instance-attribute

seed: int | None = Field(default=None, examples=[42, 123, 999], title='Random seed')

The random seed to use for the model, theoretically allowing for deterministic results.

stop_sequences class-attribute instance-attribute

stop_sequences: list[str] | None = Field(
    default=None, examples=[["STOP", "END"], ["\n\n"]], title="Stop sequences"
)

Sequences that will cause the model to stop generating.

temperature class-attribute instance-attribute

temperature: float | None = Field(
    default=None, ge=0.0, examples=[0.0, 0.7, 1.0, 2.0], title="Temperature"
)

Amount of randomness injected into the response.

thinking_config class-attribute instance-attribute

thinking_config: dict[str, Any] | None = Field(default=None, title='Thinking configuration')

Thinking features configuration.

timeout class-attribute instance-attribute

timeout: float | None = Field(default=None, examples=[30.0, 60.0, 120.0], title='Request timeout')

Override the client-level default timeout for a request, in seconds.

top_p class-attribute instance-attribute

top_p: float | None = Field(
    default=None, ge=0.0, le=1.0, examples=[0.1, 0.9, 1.0], title="Top-p (nucleus sampling)"
)

An alternative to sampling with temperature, called nucleus sampling.

type class-attribute instance-attribute

type: Literal['gemini'] = Field(default='gemini', init=False)

Type identifier for Gemini model.

get_model_settings

get_model_settings() -> GoogleModelSettings

Get model settings in pydantic-ai format.

Source code in src/llmling_models_config/configs.py
def get_model_settings(self) -> GoogleModelSettings:
    """Get model settings in pydantic-ai format."""
    from pydantic_ai.models.google import GoogleModelSettings

    settings = {
        "max_tokens": self.max_tokens,
        "temperature": self.temperature,
        "top_p": self.top_p,
        "timeout": self.timeout,
        "parallel_tool_calls": self.parallel_tool_calls,
        "seed": self.seed,
        "presence_penalty": self.presence_penalty,
        "frequency_penalty": self.frequency_penalty,
        "logit_bias": self.logit_bias,
        "stop_sequences": self.stop_sequences,
        "extra_headers": self.extra_headers,
        "extra_body": self.extra_body,
        "google_safety_settings": self.safety_settings,
        "google_thinking_config": self.thinking_config,
        "google_labels": self.labels,
    }
    return GoogleModelSettings(**{k: v for k, v in settings.items() if v is not None})  # type: ignore[typeddict-item, no-any-return]

:fa-brands-github: Show source on GitHub