Skip to content

Commit 382900e

Browse files
poe format
1 parent 84ae371 commit 382900e

7 files changed

Lines changed: 30 additions & 42 deletions

File tree

temporalio/contrib/google_gemini_sdk/_gemini_activity.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from typing import Any, Callable, Optional
1313

1414
import google.auth.credentials
15-
from google.genai import Client as GeminiClient, types
15+
from google.genai import Client as GeminiClient
16+
from google.genai import types
1617
from google.genai.types import HttpOptions
1718
from google.genai.types import HttpResponse as SdkHttpResponse
1819

@@ -107,9 +108,7 @@ async def gemini_files_upload(
107108
else:
108109
file_arg = req.file_path
109110

110-
return await self._client.aio.files.upload(
111-
file=file_arg, config=req.config
112-
)
111+
return await self._client.aio.files.upload(file=file_arg, config=req.config)
113112

114113
@activity.defn(name="gemini_files_download")
115114
async def gemini_files_download(
@@ -149,10 +148,12 @@ async def gemini_file_search_stores_upload(
149148
else:
150149
file_arg = req.file_path
151150

152-
return await self._client.aio.file_search_stores.upload_to_file_search_store(
153-
file_search_store_name=req.file_search_store_name,
154-
file=file_arg,
155-
config=req.config,
151+
return (
152+
await self._client.aio.file_search_stores.upload_to_file_search_store(
153+
file_search_store_name=req.file_search_store_name,
154+
file=file_arg,
155+
config=req.config,
156+
)
156157
)
157158

158159
return [

temporalio/contrib/google_gemini_sdk/_gemini_plugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ def __init__(
7777
``files.register_files()``). If not provided, the
7878
client's own credentials are used.
7979
"""
80-
self._api_caller = GeminiApiCaller(
81-
client, credentials=extra_credentials
82-
)
80+
self._api_caller = GeminiApiCaller(client, credentials=extra_credentials)
8381

8482
def workflow_runner(runner: WorkflowRunner | None) -> WorkflowRunner:
8583
if not runner:

temporalio/contrib/google_gemini_sdk/_temporal_api_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def _validate_http_options(http_options: Optional[HttpOptions]) -> None:
7474

7575
# ── async_request models ──────────────────────────────────────────────────
7676

77+
7778
class _GeminiApiRequest(BaseModel):
7879
"""Serializable activity input for a Gemini SDK API call."""
7980

@@ -313,7 +314,7 @@ async def async_request_streamed(
313314
**config,
314315
)
315316

316-
async def _yield_chunks():
317+
async def _yield_chunks():
317318
for chunk in resp.chunks:
318319
yield SdkHttpResponse(headers=chunk.headers, body=chunk.body)
319320

temporalio/contrib/google_gemini_sdk/_temporal_async_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
from google.genai.client import AsyncClient
1111

12-
from temporalio.workflow import ActivityConfig
13-
1412
from temporalio.contrib.google_gemini_sdk._temporal_api_client import (
1513
TemporalApiClient,
1614
)
@@ -20,6 +18,7 @@
2018
from temporalio.contrib.google_gemini_sdk._temporal_files import (
2119
TemporalAsyncFiles,
2220
)
21+
from temporalio.workflow import ActivityConfig
2322

2423

2524
class TemporalAsyncClient(AsyncClient):

temporalio/contrib/google_gemini_sdk/_temporal_file_search_stores.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
from google.genai.types import HttpOptions
1818

1919
from temporalio import workflow as temporal_workflow
20-
from temporalio.workflow import ActivityConfig
21-
2220
from temporalio.contrib.google_gemini_sdk._temporal_api_client import (
2321
TemporalApiClient,
2422
_GeminiUploadToFileSearchStoreRequest,
2523
_validate_http_options,
2624
)
25+
from temporalio.workflow import ActivityConfig
2726

2827

2928
class TemporalAsyncFileSearchStores(AsyncFileSearchStores):

temporalio/contrib/google_gemini_sdk/_temporal_files.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212
from datetime import timedelta
1313
from typing import Optional, Union
1414

15+
import google.auth.credentials
1516
from google.genai import types
1617
from google.genai.files import AsyncFiles
1718
from google.genai.types import HttpOptions
1819

1920
from temporalio import workflow as temporal_workflow
20-
from temporalio.workflow import ActivityConfig
21-
22-
import google.auth.credentials
23-
2421
from temporalio.contrib.google_gemini_sdk._temporal_api_client import (
2522
TemporalApiClient,
2623
_GeminiDownloadFileRequest,
2724
_GeminiRegisterFilesRequest,
2825
_GeminiUploadFileRequest,
2926
_validate_http_options,
3027
)
28+
from temporalio.workflow import ActivityConfig
3129

3230

3331
class TemporalAsyncFiles(AsyncFiles):
@@ -74,13 +72,9 @@ async def upload(
7472
_validate_http_options(upload_config.http_options)
7573

7674
if isinstance(file, io.IOBase):
77-
req = _GeminiUploadFileRequest(
78-
file_bytes=file.read(), config=upload_config
79-
)
75+
req = _GeminiUploadFileRequest(file_bytes=file.read(), config=upload_config)
8076
elif isinstance(file, str):
81-
req = _GeminiUploadFileRequest(
82-
file_path=file, config=upload_config
83-
)
77+
req = _GeminiUploadFileRequest(file_path=file, config=upload_config)
8478
else:
8579
# os.PathLike — convert via __fspath__() to avoid importing os
8680
req = _GeminiUploadFileRequest(

tests/contrib/google_gemini_sdk/test_gemini.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ async def gemini_api_client_async_request_streamed(
218218
return _GeminiApiStreamedResponse(chunks=chunks)
219219

220220
@activity.defn(name="gemini_files_upload")
221-
async def gemini_files_upload(
222-
self, req: _GeminiUploadFileRequest
223-
) -> types.File:
221+
async def gemini_files_upload(self, req: _GeminiUploadFileRequest) -> types.File:
224222
self.file_upload_requests.append(req)
225223
return types.File(
226224
name="files/test-uploaded-file",
@@ -229,9 +227,7 @@ async def gemini_files_upload(
229227
)
230228

231229
@activity.defn(name="gemini_files_download")
232-
async def gemini_files_download(
233-
self, req: _GeminiDownloadFileRequest
234-
) -> bytes:
230+
async def gemini_files_download(self, req: _GeminiDownloadFileRequest) -> bytes:
235231
self.file_download_requests.append(req)
236232
return b"fake file content"
237233

@@ -1042,9 +1038,7 @@ async def test_chat_multi_turn(client: Client):
10421038
# ===========================================================================
10431039

10441040

1045-
def _apply_plugin_with_mock_client(
1046-
client: Client, mock_responses: list[str]
1047-
) -> Client:
1041+
def _apply_plugin_with_mock_client(client: Client, mock_responses: list[str]) -> Client:
10481042
"""Create a real GeminiPlugin with real activities but a mocked client.
10491043
10501044
Unlike ``apply_plugin``, this does NOT replace the activities. The
@@ -1101,16 +1095,18 @@ async def _gen():
11011095

11021096
# Mock file operations at the high-level SDK interface (these are what
11031097
# the real activities call).
1104-
gemini.aio.files.upload = AsyncMock(
1098+
gemini.aio.files.upload = AsyncMock(
11051099
return_value=types.File(
11061100
name="files/mock-uploaded",
11071101
uri="https://fake.uri/files/mock-uploaded",
11081102
size_bytes=42,
11091103
)
11101104
)
11111105
gemini.aio.files.download = AsyncMock(return_value=b"mock download content")
1112-
gemini.aio.file_search_stores.upload_to_file_search_store = AsyncMock(
1113-
return_value=types.UploadToFileSearchStoreOperation.model_construct(name="operations/mock-op")
1106+
gemini.aio.file_search_stores.upload_to_file_search_store = AsyncMock(
1107+
return_value=types.UploadToFileSearchStoreOperation.model_construct(
1108+
name="operations/mock-op"
1109+
)
11141110
)
11151111

11161112
plugin = GeminiPlugin(gemini)
@@ -1133,10 +1129,10 @@ async def test_full_integration_with_mock_client(client: Client):
11331129
new_client = _apply_plugin_with_mock_client(
11341130
client,
11351131
[
1136-
make_text_response("Real activity response"), # generate_content
1137-
make_text_response("Streamed via real activity"), # generate_content_stream
1138-
make_text_response("Grounded RAG answer"), # RAG query with file_search
1139-
make_text_response(""), # file_search_stores.delete
1132+
make_text_response("Real activity response"), # generate_content
1133+
make_text_response("Streamed via real activity"), # generate_content_stream
1134+
make_text_response("Grounded RAG answer"), # RAG query with file_search
1135+
make_text_response(""), # file_search_stores.delete
11401136
],
11411137
)
11421138

0 commit comments

Comments
 (0)