Skip to content

Commit 39cad79

Browse files
authored
Merge branch 'main' into fix/non-vertex-live-resumption
2 parents 91d178b + 57d8fc7 commit 39cad79

11 files changed

Lines changed: 153 additions & 3 deletions

File tree

.github/workflows/check-file-contents.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ on:
1919
paths:
2020
- '**.py'
2121

22+
permissions:
23+
contents: read
24+
2225
jobs:
2326
check-file-contents:
2427
runs-on: ubuntu-latest

.github/workflows/discussion_answering.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
discussion_comment:
77
types: [created]
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
agent-answer-questions:
1114
if: >-

.github/workflows/mypy-new-errors.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches: [ main ]
88

99

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
mypy-diff:
1215
runs-on: ubuntu-latest

.github/workflows/mypy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Mypy Type Check
33
on:
44
workflow_dispatch:
55

6+
permissions:
7+
contents: read
8+
69
jobs:
710
mypy:
811
runs-on: ubuntu-latest

.github/workflows/pre-commit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ on:
2828
- '.pre-commit-config.yaml'
2929
- 'pyproject.toml'
3030

31+
permissions:
32+
contents: read
33+
3134
jobs:
3235
pre-commit:
3336
runs-on: ubuntu-latest

.github/workflows/python-unit-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ on:
2020
pull_request:
2121
branches: [ main ]
2222

23+
permissions:
24+
contents: read
25+
2326
jobs:
2427
test:
2528
runs-on: ubuntu-latest

.github/workflows/upload-adk-docs-to-vertex-ai-search.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
# Manual trigger for testing and fixing
88
workflow_dispatch:
99

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
upload-adk-docs-to-vertex-ai-search:
1215
if: github.repository == 'google/adk-python'

src/google/adk/models/google_llm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ async def generate_content_async(
252252
aggregator = StreamingResponseAggregator()
253253
async with Aclosing(responses) as agen:
254254
async for response in agen:
255-
logger.debug(_build_response_log(response))
255+
if logger.isEnabledFor(logging.DEBUG):
256+
logger.debug(_build_response_log(response))
256257
async with Aclosing(
257258
aggregator.process_response(response)
258259
) as aggregator_gen:
@@ -274,7 +275,8 @@ async def generate_content_async(
274275
config=llm_request.config,
275276
)
276277
logger.info('Response received from the model.')
277-
logger.debug(_build_response_log(response))
278+
if logger.isEnabledFor(logging.DEBUG):
279+
logger.debug(_build_response_log(response))
278280

279281
llm_response = LlmResponse.create(response)
280282
if cache_metadata:

src/google/adk/models/lite_llm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,8 @@ async def generate_content_async(
22242224

22252225
self._maybe_append_user_content(llm_request)
22262226
_append_fallback_user_content_if_missing(llm_request)
2227-
logger.debug(_build_request_log(llm_request))
2227+
if logger.isEnabledFor(logging.DEBUG):
2228+
logger.debug(_build_request_log(llm_request))
22282229

22292230
effective_model = llm_request.model or self.model
22302231
messages, tools, response_format, generation_params = (

tests/unittests/models/test_google_llm.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import logging
1516
import os
1617
import sys
1718
from typing import Optional
@@ -2263,3 +2264,96 @@ async def __aexit__(self, *args):
22632264
# Verify the final speech_config is still None
22642265
assert config_arg.speech_config is None
22652266
assert isinstance(connection, GeminiLlmConnection)
2267+
2268+
2269+
@pytest.mark.asyncio
2270+
@pytest.mark.parametrize(
2271+
"log_level,should_call",
2272+
[
2273+
(logging.WARNING, False),
2274+
(logging.INFO, False),
2275+
(logging.DEBUG, True),
2276+
],
2277+
)
2278+
async def test_generate_content_async_skips_response_log_build_above_debug(
2279+
gemini_llm,
2280+
llm_request,
2281+
generate_content_response,
2282+
log_level,
2283+
should_call,
2284+
):
2285+
gemini_logger = logging.getLogger("google_adk.google.adk.models.google_llm")
2286+
original_level = gemini_logger.level
2287+
gemini_logger.setLevel(log_level)
2288+
try:
2289+
with mock.patch(
2290+
"google.adk.models.google_llm._build_response_log",
2291+
return_value="log",
2292+
) as mock_build:
2293+
with mock.patch.object(gemini_llm, "api_client") as mock_client:
2294+
2295+
async def mock_coro():
2296+
return generate_content_response
2297+
2298+
mock_client.aio.models.generate_content.return_value = mock_coro()
2299+
2300+
async for _ in gemini_llm.generate_content_async(
2301+
llm_request, stream=False
2302+
):
2303+
pass
2304+
2305+
assert mock_build.called is should_call
2306+
finally:
2307+
gemini_logger.setLevel(original_level)
2308+
2309+
2310+
@pytest.mark.asyncio
2311+
@pytest.mark.parametrize(
2312+
"log_level,should_call",
2313+
[
2314+
(logging.WARNING, False),
2315+
(logging.INFO, False),
2316+
(logging.DEBUG, True),
2317+
],
2318+
)
2319+
async def test_generate_content_async_stream_skips_response_log_build_above_debug(
2320+
gemini_llm, llm_request, log_level, should_call
2321+
):
2322+
mock_responses = [
2323+
types.GenerateContentResponse(
2324+
candidates=[
2325+
types.Candidate(
2326+
content=Content(
2327+
role="model", parts=[Part.from_text(text="hi")]
2328+
),
2329+
finish_reason=types.FinishReason.STOP,
2330+
)
2331+
]
2332+
),
2333+
]
2334+
2335+
gemini_logger = logging.getLogger("google_adk.google.adk.models.google_llm")
2336+
original_level = gemini_logger.level
2337+
gemini_logger.setLevel(log_level)
2338+
try:
2339+
with mock.patch(
2340+
"google.adk.models.google_llm._build_response_log",
2341+
return_value="log",
2342+
) as mock_build:
2343+
with mock.patch.object(gemini_llm, "api_client") as mock_client:
2344+
2345+
async def mock_coro():
2346+
return MockAsyncIterator(mock_responses)
2347+
2348+
mock_client.aio.models.generate_content_stream.return_value = (
2349+
mock_coro()
2350+
)
2351+
2352+
async for _ in gemini_llm.generate_content_async(
2353+
llm_request, stream=True
2354+
):
2355+
pass
2356+
2357+
assert mock_build.called is should_call
2358+
finally:
2359+
gemini_logger.setLevel(original_level)

0 commit comments

Comments
 (0)