Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions temporalio/contrib/google_genai/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Version-compatibility shims for the ``google-genai`` SDK.

Single home for workarounds that keep the plugin importable and
type-checkable across the supported ``google-genai`` range; remove entries
as upstream fixes land.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
# google-genai 2.12.0 exports two ``Interaction`` names: the interaction
# resource class and a ``TypeAliasType`` over the trigger-request
# variants. At runtime we get the resource class but type checkers
# resolve to the alias which causes failures (the alias has no ``id``,
# etc.). Force the type checker to see the class' defining module (in
# the same location in 2.10 and 2.12).
from google.genai._gaos.types.interactions.interaction import Interaction
else:
# At runtime, Interaction resolves properly for 2.10 and 2.12
from google.genai.interactions import Interaction

__all__ = ["Interaction"]
2 changes: 1 addition & 1 deletion temporalio/contrib/google_genai/_gemini_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from google.genai import Client as GeminiClient
from google.genai import errors as genai_errors
from google.genai import types
from google.genai.interactions import Interaction
from google.genai.types import HttpOptions
from google.genai.types import HttpResponse as SdkHttpResponse

from temporalio import activity
from temporalio.contrib.google_genai._compat import Interaction
from temporalio.contrib.google_genai._models import (
_GeminiApiRequest,
_GeminiApiResponse,
Expand Down
3 changes: 2 additions & 1 deletion temporalio/contrib/google_genai/_temporal_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
from typing import Any, cast

import pydantic
from google.genai.interactions import Interaction, InteractionSSEEvent
from google.genai.interactions import InteractionSSEEvent

from temporalio import workflow as temporal_workflow
from temporalio.contrib.google_genai._compat import Interaction
from temporalio.contrib.google_genai._models import (
_GeminiInteractionIdRequest,
_GeminiInteractionRequest,
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/google_genai/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from google.genai import types
from google.genai.interactions import (
Agent, # pyright: ignore[reportPrivateImportUsage]
Interaction,
InteractionSSEEvent,
)
from google.genai.types import HttpResponse as SdkHttpResponse
Expand All @@ -45,6 +44,7 @@
GoogleGenAIPlugin,
activity_as_tool,
)
from temporalio.contrib.google_genai._compat import Interaction
from temporalio.contrib.google_genai._models import (
_GeminiApiRequest,
_GeminiApiResponse,
Expand Down
Loading