generative-ai-js
generative-ai-js copied to clipboard
fixed the generateContent() produces empty text output
Code Changes Summary: Robust Response Validation:
Added optional chaining (?.) to safely check nested properties in the API response, preventing runtime errors if the response is empty or malformed.
Retry Mechanism:
Introduced a retry mechanism to handle transient issues (e.g., network errors or empty responses). The function retries the API call up to 3 times (configurable) to increase reliability.
Error Handling and Logging:
Added detailed error logging for each failed attempt, including the attempt number, error message, and full response (if available), making debugging easier.
Early Exit on Success:
The function exits early if a valid response is received, avoiding unnecessary retries and improving efficiency.
Code Structure:
Consolidated logic into a single function (getCapitalOfFranceWithRetry) for better readability and maintainability.
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.