googleapis / googleapis/python-genai
Finish Message is Empty when Finish Reason is Malformed Function Call, even when it is populated in logs in AI Studio
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
When the model stop because of malformed function call, the finish message is empty. This makes retries impossible because the incorrectly generated response is neither in history (`chat.get_history()`) nor in the finish message of the response.
The finish message is correctly populated in the AI Studio logs with what the model tried to generate as malformed function (generally python code instead). So this seems like a python sdk specific problem.
#### Environment details
- Programming language: Python
- OS: Mac Tahoe, Windows 11
- Language runtime version: Python 3.12.3
- Package version: 1.52.0
#### Steps to reproduce
1. Enable logging in Google AI Studio [link](https://ai.google.dev/gemini-api/docs/logs-datasets#1_enable_logging_in_google_ai_studio)
2. Run the notebook at https://github.com/radishbuild/gemini-malformed-function-fix/blob/main/gemini_retry_fix.ipynb
- Make sure to set your GEMINI_API_KEY in .env file
- The notebook runs both error and success case and prints the finish reason
- Notice the print statements in the notebook shows finish message as 'None'
3. View the first log (chronologically earlier), scroll to the bottom to find malformed function call as reason and finish message populated
This user message in a different issue port also shows that finish message is null: [comment](https://github.com/googleapis/python-genai/issues/430#issuecomment-3113739836)
Here is screenshot from google ai studio showing the finish message in logs when python sdk didn't
Contributor guide
Assessment
This issue has not been assessed yet.