googleapis / googleapis/python-genai

generate_content and generate_content_stream show afc warning for empty config or config with empty tools

Offen
#2,902 2 Kommentare 2 Reaktionen 1 zugewiesene Person Beansprucht von @kkorpal Auf GitHub ansehen
priority: p2 type: bug
Vorherrschende Sprache
Python
Sterne
4k
Forks
1k
Ø Merge
2 T. 12 Std.
Gemergte PRs (30 T.)
41

Beschreibung

Google GenAI model methods `generate_content` and `generate_content_stream` have automatic function calling (AFC) feature which can invoke passed callables. There are alternative function calling patterns though. I.e. when generate content config has only function declarations but not callables. Recently a warning was implemented about non-recommended usage of AFC. Interestingly the warning (and AFC code path overall) is not activated when non empty function declarations are passed to model. However warning (AFC code path overall) is activated when config is empty/config tools is empty. Supposedly `_extra_tools.should_disable_afc` should return `True` for empty config/empty config tools.

#### Environment details

- Programming language: python
- OS: ubuntu 24.04
- Language runtime version: 3.12.3
- Package version: 2.19.0

#### Steps to reproduce

```python
from google import genai
from google.genai.models import Models

client = genai.Client()

print('CONFIG IS NONE')

client.models.generate_content(
model="gemini-2.5-flash",
contents="Hello",
config=None,
)

Models._logged_afc_warning = False

print('CONFIG.TOOLS IS NONE')

client.models.generate_content(
model="gemini-2.5-flash",
contents="Hello",
config={"tools": None},
)

Models._logged_afc_warning = False

print('CONFIG.TOOLS IS FUNCS')

client.models.generate_content(
model="gemini-2.5-flash",
contents="Hello",
config={
"tools": [
{
"function_declarations": [
{"name": "ping", "description": "Return pong"}
]
}
]
},
)
```

Observed result:

```
CONFIG IS NONE
Direct use of automatic function calling (AFC) in Models.generate_content is not recommended. Instead, we recommend to use AFC in Chat.send_message. Similarly, direct use of AFC in Models.generate_content_stream is not recommended. Instead, we recommend to use AFC in Chat.send_message_stream.
CONFIG.TOOLS IS NONE
Direct use of automatic function calling (AFC) in Models.generate_content is not recommended. Instead, we recommend to use AFC in Chat.send_message. Similarly, direct use of AFC in Models.generate_content_stream is not recommended. Instead, we recommend to use AFC in Chat.send_message_stream.
CONFIG.TOOLS IS FUNCS
```

Expected result:

No AFC warnings shown

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.