feat: add Google Gemini and HuggingFace provider adapters#17
Merged
Conversation
- GeminiAdapter patches `google.genai.models.Models.generate_content` and `generate_content_stream` to track tokens via `usage_metadata` - HuggingFaceAdapter patches `InferenceClient.chat_completion` with OpenAI- compatible token extraction; handles missing usage in streaming gracefully - New pricing entries: gemini-2.0-flash, gemini-2.5-flash, gemini-2.5-pro - Cross-provider fallback validation extended to gemini and huggingface - Integration tests, unit tests, examples, and docs for both adapters - New optional extras: `shekel[gemini]`, `shekel[huggingface]` - CI: adds HUGGING_FACE_API secret to integration test step Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Add tests for all previously uncovered lines in shekel/_patch.py, shekel/providers/gemini.py, and shekel/providers/huggingface.py: - _validate_same_provider: gemini/huggingface cross-provider rejection - _gemini_sync_wrapper / _gemini_stream_wrapper: normal flow + no-original error - _wrap_gemini_stream: attribute error handling + usage recording - _extract_gemini_tokens: AttributeError and None usage_metadata paths - _huggingface_sync_wrapper: non-stream, stream, and no-original paths - _wrap_huggingface_stream: attribute error handling + usage recording - GeminiAdapter.remove_patches(): ImportError path - GeminiAdapter.wrap_stream(): AttributeError on broken usage_metadata - HuggingFaceAdapter.remove_patches(): ImportError path - HuggingFaceAdapter.wrap_stream(): AttributeError on broken usage Key insight: budget() calls install_patches() on entry, which overwrites _originals — tests that use budget() must include the adapter's sentinel keys in patch.dict to prevent re-installation from overwriting test fakes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…files Add CLAUDE.md naming rule: test files must be organized by domain, not by implementation unit or coverage goal. Deleted: - tests/test_patch_coverage.py — generic coverage-focused file - tests/test_patching.py — generic patching file Added domain-organized files: - tests/test_openai_wrappers.py — OpenAI sync/async wrapper edge cases - tests/test_anthropic_wrappers.py — Anthropic sync/async wrapper edge cases - tests/test_litellm_wrappers.py — LiteLLM sync/async wrapper edge cases - tests/test_gemini_wrappers.py — Gemini sync/stream wrapper edge cases - tests/test_huggingface_wrappers.py — HuggingFace sync/stream wrapper edge cases Moved into existing files: - Cross-provider fallback validation tests → tests/test_fallback.py - _record exception-swallowing tests → tests/test_budget.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ini and HuggingFace Add test_gemini_import_error_is_swallowed and test_huggingface_import_error_is_swallowed to TestAdapterRegistrySingleton, following the existing litellm pattern: reload shekel.providers with the submodule blocked in sys.modules to exercise lines 30-31 and 37-38. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
google.genai.models.Models.generate_content(sync) andgenerate_content_stream(streaming) to track token usage viausage_metadata; supports fallback model validation for gemini providerInferenceClient.chat_completionwith OpenAI-compatible token extraction; gracefully handles missing usage in streaming responsesgemini-2.0-flash,gemini-2.5-flash,gemini-2.5-propip install shekel[gemini]andpip install shekel[huggingface]examples/gemini_demo.py,examples/huggingface_demo.py), and docs (docs/integrations/gemini.md,docs/integrations/huggingface.md)HUGGING_FACE_APIsecret to integration test stepTest plan
pytest tests/providers/test_gemini_adapter.py tests/providers/test_huggingface_adapter.py -vpytest tests/ --ignore=tests/integrations --ignore=tests/performanceGEMINI_API_KEYandHUGGING_FACE_APIsecrets setpip install shekel[gemini]andpip install shekel[huggingface]install correctlymkdocs serve🤖 Generated with Claude Code