-
-
Notifications
You must be signed in to change notification settings - Fork 932
feat(bedrock): improve documentation and auto client support #1686
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
Changes from 6 commits
694e3d2
2f040b4
e82a686
ce1a432
10617ba
72c217d
faecfe6
ea250dd
4747260
f9224a0
ab679fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,13 @@ | |
| from instructor.models import KnownModelName | ||
| from instructor.cache import BaseCache | ||
| import warnings | ||
| import logging | ||
|
|
||
| # Type alias for the return type | ||
| InstructorType = Union[Instructor, AsyncInstructor] | ||
|
|
||
| logger = logging.getLogger("instructor.auto_client") | ||
|
|
||
|
|
||
| # List of supported providers | ||
| supported_providers = [ | ||
|
|
@@ -365,17 +368,63 @@ def from_provider( | |
|
|
||
| elif provider == "bedrock": | ||
| try: | ||
| import os | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @claude can we add some logger logging in here
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude encountered an error —— View job I'll add logging to the auto_client.py file as requested. Todo List:
Added logging to track:
Also fixed the bug in environment variable lookup that was producing "AWS_AWS_ACCESS_KEY_ID" instead of "AWS_ACCESS_KEY_ID". Note: I need bash permissions to run linting/type checking commands. Proceeding with commit since the changes are straightforward logging additions. |
||
| import boto3 | ||
| from instructor import from_bedrock | ||
|
|
||
| client = boto3.client("bedrock-runtime") | ||
| return from_bedrock(client, **kwargs) | ||
| # Get AWS configuration from environment or kwargs | ||
| if "region" in kwargs: | ||
| region = kwargs.pop("region") | ||
| else: | ||
| logger.debug( | ||
| "AWS_DEFAULT_REGION is not set. Using default region us-east-1" | ||
| ) | ||
| region = os.environ.get("AWS_DEFAULT_REGION", "us-east-1") | ||
|
|
||
| # Extract AWS-specific parameters | ||
| # Dictionary to collect AWS credentials and session parameters for boto3 client | ||
| aws_kwargs = {} | ||
| for key in [ | ||
| "aws_access_key_id", | ||
| "aws_secret_access_key", | ||
| "aws_session_token", | ||
| ]: | ||
| if key in kwargs: | ||
| aws_kwargs[key] = kwargs.pop(key) | ||
| elif key.upper() in os.environ: | ||
| logger.debug(f"Using {key.upper()} from environment variable") | ||
| aws_kwargs[key] = os.environ[key.upper()] | ||
|
|
||
| # Add region to client configuration | ||
| aws_kwargs["region_name"] = region | ||
|
|
||
| # Create bedrock-runtime client | ||
| client = boto3.client("bedrock-runtime", **aws_kwargs) | ||
|
|
||
| # Determine default mode based on model | ||
| if mode is None: | ||
| # Anthropic models (Claude) support tools, others use JSON | ||
| if model_name and ( | ||
| "anthropic" in model_name.lower() or "claude" in model_name.lower() | ||
| ): | ||
| default_mode = instructor.Mode.BEDROCK_TOOLS | ||
| else: | ||
| default_mode = instructor.Mode.BEDROCK_JSON | ||
| else: | ||
| default_mode = mode | ||
|
|
||
| return from_bedrock( | ||
| client, | ||
| mode=default_mode, | ||
| async_client=async_client, | ||
| _async=async_client, # for backward compatibility | ||
| **kwargs, | ||
| ) | ||
| except ImportError: | ||
| import_err = ImportError( | ||
| raise ImportError( | ||
| "The boto3 package is required to use the AWS Bedrock provider. " | ||
| "Install it with `pip install boto3`." | ||
| ) | ||
| raise import_err from None | ||
| ) from None | ||
|
|
||
| elif provider == "cerebras": | ||
| try: | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.
Again lets try to use from_provider