Skip to content

Commit 0172bad

Browse files
author
Guiners
committed
codereview fix
1 parent f253696 commit 0172bad

8 files changed

+69
-36
lines changed

genai/live/live_audiogen_with_txt.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ async def generate_content() -> None:
2424
import numpy as np
2525
import scipy.io.wavfile as wavfile
2626
from google import genai
27-
from google.genai.types import (Content, LiveConnectConfig, Modality, Part,
28-
PrebuiltVoiceConfig, SpeechConfig,
29-
VoiceConfig)
27+
from google.genai.types import (
28+
Content,
29+
LiveConnectConfig,
30+
Modality,
31+
Part,
32+
PrebuiltVoiceConfig,
33+
SpeechConfig,
34+
VoiceConfig,
35+
)
3036

3137
client = genai.Client()
3238
model = "gemini-2.0-flash-live-preview-04-09"

genai/live/live_code_exec_with_txt.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
async def generate_content() -> list[str]:
1919
# [START googlegenaisdk_live_code_exec_with_txt]
2020
from google import genai
21-
from google.genai.types import (Content, LiveConnectConfig, Modality, Part,
22-
Tool, ToolCodeExecution)
21+
from google.genai.types import (
22+
Content,
23+
LiveConnectConfig,
24+
Modality,
25+
Part,
26+
Tool,
27+
ToolCodeExecution,
28+
)
2329

2430
client = genai.Client()
2531
model_id = "gemini-2.0-flash-live-preview-04-09"

genai/live/live_func_call_with_txt.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
async def generate_content() -> list[FunctionResponse]:
2121
# [START googlegenaisdk_live_func_call_with_txt]
2222
from google import genai
23-
from google.genai.types import (Content, FunctionDeclaration,
24-
FunctionResponse, LiveConnectConfig,
25-
Modality, Part, Tool)
23+
from google.genai.types import (
24+
Content,
25+
FunctionDeclaration,
26+
FunctionResponse,
27+
LiveConnectConfig,
28+
Modality,
29+
Part,
30+
Tool,
31+
)
2632

2733
client = genai.Client()
2834
model_id = "gemini-2.0-flash-live-preview-04-09"

genai/live/live_ground_googsearch_with_txt.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@
1919
async def generate_content() -> list[str]:
2020
# [START googlegenaisdk_live_ground_googsearch_with_txt]
2121
from google import genai
22-
from google.genai.types import (Content, GoogleSearch, LiveConnectConfig,
23-
Modality, Part, Tool)
22+
from google.genai.types import (
23+
Content,
24+
GoogleSearch,
25+
LiveConnectConfig,
26+
Modality,
27+
Part,
28+
Tool,
29+
)
2430

2531
client = genai.Client()
2632
model_id = "gemini-2.0-flash-live-preview-04-09"

genai/live/live_structured_ouput_with_txt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ def generate_content() -> CalendarEvent:
3030
import google.auth.transport.requests
3131
import openai
3232
from google.auth import default
33-
from openai.types.chat import (ChatCompletionSystemMessageParam,
34-
ChatCompletionUserMessageParam)
33+
from openai.types.chat import (
34+
ChatCompletionSystemMessageParam,
35+
ChatCompletionUserMessageParam,
36+
)
3537

3638
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
3739
location = "us-central1"

genai/live/live_transcribe_with_audio.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
async def generate_content() -> list[str]:
2323
# [START googlegenaisdk_live_transcribe_with_audio]
2424
from google import genai
25-
from google.genai.types import (AudioTranscriptionConfig, Content,
26-
LiveConnectConfig, Modality, Part)
25+
from google.genai.types import (
26+
AudioTranscriptionConfig,
27+
Content,
28+
LiveConnectConfig,
29+
Modality,
30+
Part,
31+
)
2732

2833
client = genai.Client()
2934
model = "gemini-live-2.5-flash-preview-native-audio"

genai/live/live_with_txt.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
async def generate_content() -> list[str]:
1919
# [START googlegenaisdk_live_with_txt]
2020
from google import genai
21-
from google.genai.types import (Content, HttpOptions, LiveConnectConfig,
22-
Modality, Part)
21+
from google.genai.types import (
22+
Content,
23+
HttpOptions,
24+
LiveConnectConfig,
25+
Modality,
26+
Part,
27+
)
2328

2429
client = genai.Client(http_options=HttpOptions(api_version="v1beta1"))
2530
model_id = "gemini-2.0-flash-live-preview-04-09"

genai/live/test_live_examples.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,28 @@
3939
# The project name is included in the CICD pipeline
4040
# os.environ['GOOGLE_CLOUD_PROJECT'] = "add-your-project-name"
4141

42+
4243
@pytest.fixture()
4344
def mock_rag_components(mocker):
44-
mock_client_cls = mocker.patch("google.genai.Client")
45-
46-
47-
class AsyncIterator:
48-
def __aiter__(self):
49-
return self
50-
51-
52-
async def __anext__(self):
53-
if not hasattr(self, "used"):
54-
self.used = True
55-
return mocker.MagicMock(
56-
text="Mariusz Pudzianowski won in 2002, 2003, 2005, 2007, and 2008."
57-
)
58-
raise StopAsyncIteration
45+
mock_client_cls = mocker.patch("google.genai.Client")
5946

47+
class AsyncIterator:
48+
def __aiter__(self):
49+
return self
6050

61-
mock_session = mocker.AsyncMock()
62-
mock_session.__aenter__.return_value = mock_session
63-
mock_session.receive = lambda: AsyncIterator()
51+
async def __anext__(self):
52+
if not hasattr(self, "used"):
53+
self.used = True
54+
return mocker.MagicMock(
55+
text="Mariusz Pudzianowski won in 2002, 2003, 2005, 2007, and 2008."
56+
)
57+
raise StopAsyncIteration
6458

59+
mock_session = mocker.AsyncMock()
60+
mock_session.__aenter__.return_value = mock_session
61+
mock_session.receive = lambda: AsyncIterator()
6562

66-
mock_client_cls.return_value.aio.live.connect.return_value = mock_session
63+
mock_client_cls.return_value.aio.live.connect.return_value = mock_session
6764

6865

6966
@pytest.mark.asyncio
@@ -129,4 +126,4 @@ async def test_live_structured_ouput_with_txt() -> None:
129126

130127
@pytest.mark.asyncio
131128
async def test_live_ground_ragengine_with_txt(mock_rag_components) -> None:
132-
assert await live_ground_ragengine_with_txt.generate_content("test")
129+
assert await live_ground_ragengine_with_txt.generate_content("test")

0 commit comments

Comments
 (0)