Skip to content

Commit 249f1af

Browse files
qiaodevcopybara-github
authored andcommitted
fix: fix AFC logging
PiperOrigin-RevId: 808221859
1 parent 91bd2c4 commit 249f1af

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

google/genai/models.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6565,10 +6565,6 @@ def generate_content(
65656565
response = self._generate_content(
65666566
model=model, contents=contents, config=parsed_config
65676567
)
6568-
logger.info(f'AFC remote call {i} is done.')
6569-
remaining_remote_calls_afc -= 1
6570-
if remaining_remote_calls_afc == 0:
6571-
logger.info('Reached max remote calls for automatic function calling.')
65726568

65736569
function_map = _extra_utils.get_function_map(parsed_config)
65746570
if not function_map:
@@ -6586,6 +6582,11 @@ def generate_content(
65866582
)
65876583
if not func_response_parts:
65886584
break
6585+
logger.info(f'AFC remote call {i} is done.')
6586+
remaining_remote_calls_afc -= 1
6587+
if remaining_remote_calls_afc == 0:
6588+
logger.info('Reached max remote calls for automatic function calling.')
6589+
65896590
func_call_content = response.candidates[0].content
65906591
func_response_content = types.Content(
65916592
role='user',
@@ -6703,10 +6704,6 @@ def generate_content_stream(
67036704
response = self._generate_content_stream(
67046705
model=model, contents=contents, config=parsed_config
67056706
)
6706-
logger.info(f'AFC remote call {i} is done.')
6707-
remaining_remote_calls_afc -= 1
6708-
if remaining_remote_calls_afc == 0:
6709-
logger.info('Reached max remote calls for automatic function calling.')
67106707

67116708
function_map = _extra_utils.get_function_map(parsed_config)
67126709

@@ -6756,6 +6753,10 @@ def generate_content_stream(
67566753
break
67576754
if not func_response_parts:
67586755
break
6756+
logger.info(f'AFC remote call {i} is done.')
6757+
remaining_remote_calls_afc -= 1
6758+
if remaining_remote_calls_afc == 0:
6759+
logger.info('Reached max remote calls for automatic function calling.')
67596760

67606761
# Append function response parts to contents for the next request.
67616762
if chunk is not None and chunk.candidates is not None:

google/genai/tests/models/test_generate_content_tools.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ def test_afc_logs_to_logger_instance(client, caplog):
14111411
'tools': [divide_integers],
14121412
'automatic_function_calling': {
14131413
'disable': False,
1414-
'maximum_remote_calls': 2,
1414+
'maximum_remote_calls': 1,
14151415
'ignore_call_history': True,
14161416
},
14171417
},
@@ -1420,9 +1420,8 @@ def test_afc_logs_to_logger_instance(client, caplog):
14201420
assert log.levelname == 'INFO'
14211421
assert log.name == 'google_genai.models'
14221422

1423-
assert 'AFC is enabled with max remote calls: 2' in caplog.text
1423+
assert 'AFC is enabled with max remote calls: 1' in caplog.text
14241424
assert 'remote call 1 is done' in caplog.text
1425-
assert 'remote call 2 is done' in caplog.text
14261425
assert 'Reached max remote calls' in caplog.text
14271426

14281427

0 commit comments

Comments
 (0)