Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Googleapis Python genai Interactions Models

From Leeroopedia
Knowledge Sources
Domains Data_Modeling, SDK_Infrastructure
Last Updated 2026-02-15 14:00 GMT

Overview

Concrete tool for Pydantic model utilities, type construction, and validation used by the _interactions subsystem.

Description

The _models module provides a custom BaseModel with Pydantic v1/v2 compatibility, FinalRequestOptions for HTTP request configuration, and type construction functions (construct_type, validate_type, build). It handles discriminated unions, generic models, and extra field management.

Usage

Internal infrastructure used by the _interactions response parsing and request construction pipeline.

Code Reference

Source Location

Signature

class BaseModel(pydantic.BaseModel):
    def to_dict(
        self,
        *,
        mode: Literal["json", "python"] = "python",
        use_api_names: bool = True,
        exclude_unset: bool = True,
    ) -> dict[str, object]: ...

    def to_json(self, *, indent: int | None = 2) -> str: ...

class FinalRequestOptions(pydantic.BaseModel):
    method: str
    url: str
    json_data: Body | None
    headers: Headers | None
    max_retries: int | None
    timeout: float | httpx.Timeout | None | NotGiven

def construct_type(*, value: object, type_: object) -> object: ...
def validate_type(*, type_: type[_T], value: object) -> _T: ...
def build(base_model_cls: Callable, *args, **kwargs) -> BaseModel: ...

Import

from google.genai._interactions._models import BaseModel, FinalRequestOptions

I/O Contract

Inputs

Name Type Required Description
value object Yes Value to construct or validate
type_ type Yes Target type for construction/validation

Outputs

Name Type Description
construct_type returns object Loosely constructed typed value
validate_type returns T Strictly validated typed value
to_dict returns dict Dictionary representation with API-style keys

Usage Examples

# Internal usage pattern
from google.genai._interactions._models import construct_type

# Construct a typed value from raw API response data
result = construct_type(
    value={"name": "models/gemini-2.0-flash", "displayName": "Gemini 2.0 Flash"},
    type_=ModelInfo,
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment