google-gemini / generative-ai-python

The official Python library for the Google Gemini API
https://pypi.org/project/google-generativeai/
Apache License 2.0
1.19k stars 227 forks source link

Fix bugs, improve code clarity, and enhance overall reliability across several files. #339

Closed Faisal-Alsrheed closed 1 month ago

Faisal-Alsrheed commented 1 month ago

General Updates

  1. Documentation and Error Messages: Improved clarity and accuracy in documentation and error messages across multiple files. This includes providing more descriptive error messages and consistent usage examples to help developers better understand code functionalities and constraints.

  2. Typo Corrections: Fixed typos in comments and function names, notably correcting get_dafault_permission_client to get_default_permission_client and its asynchronous counterpart in client.py and types/permission_types.py. These changes prevent potential bugs and improve overall code quality.

Specific File Changes

unittest vs pytest

I noticed discrepancies in the number of tests discovered when using unittest and pytest.

When running our test suite with unittest using the command:

python -m unittest discover -s /workspaces/generative-ai-python/tests unittest reported that it ran 603 tests.

However, when we ran the same test suite with pytest using the command:

pytest /workspaces/generative-ai-python/tests pytest reported that it collected and ran 607 tests.

TODO:

I have broken down test_generate_text in notebook/text_model_test.py for better debugging. beacuse after using pytest i got this

======================================================================================== short test summary info ========================================================================================
FAILED tests/notebook/text_model_test.py::TextModelTestCase::test_generate_text_with_args_candidate_count - AssertionError: '5' != 5
FAILED tests/notebook/text_model_test.py::TextModelTestCase::test_generate_text_with_args_temperature - AssertionError: '0.42' != 0.42
FAILED tests/notebook/text_model_test.py::TextModelTestCase::test_generate_text_without_args_none_results - AssertionError: 'None' is not None
============================================================================== 3 failed, 609 passed, 35 warnings in 5.15s ===============================================================================

The call_model method of the TestModel class seems to be returning these values as strings, which is causing the tests to fail.

Please review the changes and provide any additional feedback.

Thank You! 😊

Faisal-Alsrheed commented 1 month ago

Hi @MarkDaoust :)

Let me know if you would like me to split this into multiple PRs.

mayureshagashe2105 commented 1 month ago

Wait I need to look at that TODO before merging this.

The one in the permission_types? I should submit it in a separate PR.

@Faisal-Alsrheed thank you for the typos and other fixes :)

MarkDaoust commented 1 month ago

The one in the permission_types? I should submit it in a separate PR.

No I meant the one at the end of the PR description.

I think this is good to submit.