-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Standardize provider factory methods in codebase #1898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jxnl
merged 25 commits into
main
from
claude/standardize-from-provider-methods-011CUr7MGdVWLMPsmGogNZUy
Nov 12, 2025
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f3fcb9e
test(core): standardize provider tests with from_provider() parameter…
claude 6fd61f5
feat(tests): consolidate providers into core test suite
claude 74e2e56
docs(tests): add workflow update instructions for maintainers
claude c44fffa
fix(tests): update models to claude-haiku-4-5-latest and gemini-2.5-f…
claude c796c1c
fix(tests): complete model updates in util.py and README
claude 7c1fc73
docs(tests): add comprehensive parameterization and provider-specific…
claude 3866388
docs(tests): answer key questions about parameterization and provider…
claude c7cd45e
feat(tests): add unified multimodal tests to core suite
claude 7f26778
refactor(tests): massive cleanup - delete all duplicate tests
claude 2fbf2fc
Refactor: Update instructor modes for Fireworks and Perplexity
cursoragent eaf5a05
feat(tests): add unified multimodal tests to core suite
claude e6c6cf3
docs(tests): remove temporary analysis markdown files
claude 04c8017
Refactor: Separate core provider tests and update test matrix
cursoragent afe8c14
refactor(tests): delete more duplicate test files
claude 4f15c89
feat(xai): enhance tool handling and add capability definitions for p…
jxnl e5ce61a
fix(tests): stabilize core provider response modes
jxnl a3d0fc0
fix(ci): fix ruff linting errors and type check issues
jxnl 515ac81
fix(types): add type ignores for xAI SDK method calls
jxnl 8209d5a
fix(anthropic): respect strict JSON control character handling
jxnl de36d2b
Merge remote-tracking branch 'origin/main' into claude/standardize-fr…
jxnl 5a6b0b2
refactor(tests): remove provider-specific tests and utility configura…
jxnl 9ff3df0
fix(tests): update test commands to use asyncio mode
jxnl ad165b5
feat(tests): expand core provider tests for OpenAI, Anthropic, Google…
jxnl 6da9110
fix(tests): skip unsupported provider capabilities for Google Gemini
jxnl ef2af12
docs(google): add known limitations as of Nov 12, 2024
jxnl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| """ | ||
| Shared configuration for multi-provider tests. | ||
|
|
||
| This module provides common test configuration for running the same tests | ||
| across multiple providers (OpenAI, Anthropic, Google, Cohere, xAI, Mistral, | ||
| Cerebras, Fireworks, Writer, Perplexity). | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| import instructor | ||
| import pytest | ||
|
|
||
|
|
||
| # Provider configurations: (model_string, mode, required_env_var, required_package) | ||
| PROVIDER_CONFIGS = [ | ||
| ( | ||
| "openai/gpt-5-nano", | ||
| instructor.Mode.TOOLS, | ||
| "OPENAI_API_KEY", | ||
| "openai", | ||
| ), | ||
| ( | ||
| "anthropic/claude-3-5-haiku-latest", | ||
| instructor.Mode.ANTHROPIC_TOOLS, | ||
| "ANTHROPIC_API_KEY", | ||
| "anthropic", | ||
| ), | ||
| ( | ||
| "google/gemini-2.5-flash", | ||
| instructor.Mode.GENAI_TOOLS, | ||
| "GOOGLE_API_KEY", | ||
| "google.genai", | ||
| ), | ||
| ( | ||
| "cohere/command-a-03-2025", | ||
| instructor.Mode.COHERE_TOOLS, | ||
| "COHERE_API_KEY", | ||
| "cohere", | ||
| ), | ||
| ( | ||
| "xai/grok-3-mini", | ||
| instructor.Mode.XAI_TOOLS, | ||
| "XAI_API_KEY", | ||
| "xai_sdk", | ||
| ), | ||
| ( | ||
| "mistral/ministral-8b-latest", | ||
| instructor.Mode.MISTRAL_TOOLS, | ||
| "MISTRAL_API_KEY", | ||
| "mistralai", | ||
| ), | ||
| ( | ||
| "cerebras/llama3.1-70b", | ||
| instructor.Mode.CEREBRAS_TOOLS, | ||
| "CEREBRAS_API_KEY", | ||
| "cerebras", | ||
| ), | ||
| ( | ||
| "fireworks/llama-v3p1-70b-instruct", | ||
| instructor.Mode.FIREWORKS_TOOLS, | ||
| "FIREWORKS_API_KEY", | ||
| "fireworks", | ||
| ), | ||
| ( | ||
| "writer/palmyra-x-004", | ||
| instructor.Mode.WRITER_TOOLS, | ||
| "WRITER_API_KEY", | ||
| "writerai", | ||
| ), | ||
| ( | ||
| "perplexity/llama-3.1-sonar-large-128k-online", | ||
| instructor.Mode.PERPLEXITY_JSON, | ||
| "PERPLEXITY_API_KEY", | ||
| "openai", # Perplexity transports over OpenAI-compatible API | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def get_available_providers() -> list[tuple[str, instructor.Mode]]: | ||
| """ | ||
| Get list of available providers based on API keys and installed packages. | ||
|
|
||
| Returns: | ||
| List of tuples (model_string, mode) for available providers | ||
| """ | ||
| available = [] | ||
|
|
||
| for model, mode, env_var, package in PROVIDER_CONFIGS: | ||
| # Check if API key is set | ||
| if not os.getenv(env_var): | ||
| continue | ||
|
|
||
| # Check if package is installed | ||
| try: | ||
| parts = package.split(".") | ||
| if len(parts) > 1: | ||
| __import__(parts[0]) | ||
| # For nested imports like google.genai | ||
| __import__(package) | ||
| else: | ||
| __import__(package) | ||
| available.append((model, mode)) | ||
| except ImportError: | ||
| continue | ||
|
|
||
| return available | ||
|
|
||
|
|
||
| def pytest_generate_tests(metafunc): | ||
| """ | ||
| Pytest hook to generate parametrized tests for available providers. | ||
|
|
||
| This is used in test files that have 'provider_config' as a parameter. | ||
| """ | ||
| if "provider_config" in metafunc.fixturenames: | ||
| available = get_available_providers() | ||
| if not available: | ||
| pytest.skip("No providers available (missing API keys or packages)") | ||
|
|
||
| # Generate test IDs like "openai" "anthropic" "google" | ||
| ids = [model.split("/")[0] for model, _ in available] | ||
| metafunc.parametrize("provider_config", available, ids=ids) | ||
|
|
||
|
|
||
| def pytest_configure(config): | ||
| """Register custom markers for provider-specific tests.""" | ||
| config.addinivalue_line("markers", "openai: mark test as requiring OpenAI provider") | ||
| config.addinivalue_line( | ||
| "markers", "anthropic: mark test as requiring Anthropic provider" | ||
| ) | ||
| config.addinivalue_line("markers", "google: mark test as requiring Google provider") | ||
| config.addinivalue_line("markers", "cohere: mark test as requiring Cohere provider") | ||
| config.addinivalue_line("markers", "xai: mark test as requiring xAI provider") | ||
| config.addinivalue_line( | ||
| "markers", "mistral: mark test as requiring Mistral provider" | ||
| ) | ||
| config.addinivalue_line( | ||
| "markers", "cerebras: mark test as requiring Cerebras provider" | ||
| ) | ||
| config.addinivalue_line( | ||
| "markers", "fireworks: mark test as requiring Fireworks provider" | ||
| ) | ||
| config.addinivalue_line("markers", "writer: mark test as requiring Writer provider") | ||
| config.addinivalue_line( | ||
| "markers", "perplexity: mark test as requiring Perplexity provider" | ||
| ) | ||
|
|
||
|
|
||
| # Convenience function to skip if specific provider not available | ||
| def skip_if_provider_unavailable(provider_name: str): | ||
| """ | ||
| Skip test if specific provider is not available. | ||
|
|
||
| Args: | ||
| provider_name: One of "openai", "anthropic", "google", "cohere", "xai", | ||
| "mistral", "cerebras", "fireworks", "writer", "perplexity" | ||
| """ | ||
| config_map = { | ||
| "openai": ("OPENAI_API_KEY", "openai"), | ||
| "anthropic": ("ANTHROPIC_API_KEY", "anthropic"), | ||
| "google": ("GOOGLE_API_KEY", "google.genai"), | ||
| "cohere": ("COHERE_API_KEY", "cohere"), | ||
| "xai": ("XAI_API_KEY", "xai_sdk"), | ||
| "mistral": ("MISTRAL_API_KEY", "mistralai"), | ||
| "cerebras": ("CEREBRAS_API_KEY", "cerebras"), | ||
| "fireworks": ("FIREWORKS_API_KEY", "fireworks"), | ||
| "writer": ("WRITER_API_KEY", "writerai"), | ||
| "perplexity": ("PERPLEXITY_API_KEY", "openai"), | ||
| } | ||
|
|
||
| if provider_name not in config_map: | ||
| pytest.skip(f"Unknown provider: {provider_name}") | ||
|
|
||
| env_var, package = config_map[provider_name] | ||
|
|
||
| if not os.getenv(env_var): | ||
| pytest.skip(f"{env_var} not set") | ||
|
|
||
| try: | ||
| __import__(package) | ||
| except ImportError: | ||
| pytest.skip(f"{package} package not installed") | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shared provider matrix assigns
instructor.Mode.TOOLSto the Fireworks model, butfrom_fireworks()only acceptsFIREWORKS_TOOLSorFIREWORKS_JSON. When a Fireworks API key and package are present,from_provider()will raise aModeErrorbefore any test runs. This makes the whole Fireworks test suite unusable. The mode should be switched to one of the supported Fireworks modes so that tests can actually execute.Useful? React with 👍 / 👎.