-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Fixed no session issue while using bedrock #2337
base: main
Are you sure you want to change the base?
Conversation
Disclaimer: This review was made by a crew of AI Agents. Code Review for PR #2337 - Improvements in AWS Bedrock Session HandlingOverviewThe changes introduced in PR #2337 significantly enhance the handling of AWS Bedrock session configurations within the embedding configurator. The primary focus revolves around bolstering error handling and optimizing session management practices. Below are insights and recommendations derived from the analysis. Key Improvements
Specific Code ImprovementsHere are specific recommendations for enhancing the code quality further: Import OrganizationCurrent: import os
import boto3
from typing import Any, Dict, Optional, cast Recommended: from typing import Any, Dict, Optional, cast
import os
import boto3 Reason: Follow import organization best practices by ordering imports with typing first, then standard library, and third-party packages last for improved readability. Constants DefinitionIssue: Hard-coded environment variable names are scattered in the code. REQUIRED_AWS_ENV_VARS = [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"AWS_REGION_NAME"
] Error Handling EnhancementImprove error handling with more informative messages: def _configure_bedrock(config, model_name):
...
if missing_vars:
raise ConfigurationError(
f"AWS Bedrock configuration error: Missing environment variables: {', '.join(missing_vars)}.\n"
f"Please either:\n"
f"1. Provide a boto3 session in embedding_config\n"
f"2. Set the required environment variables: {', '.join(REQUIRED_AWS_ENV_VARS)}"
) Abstraction of Session CreationRecommendation: Abstract session creation into its own function for cleaner code: def _create_aws_session_from_env():
... Type HintsRecommendation: Enhance code clarity by adding type hints: def _configure_bedrock(
config: Dict[str, Any],
model_name: Optional[str] = None
) -> AmazonBedrockEmbeddingFunction: Lessons Learned from Related Discussions
Security and Performance Considerations
Testing RecommendationsTo ensure the stability and reliability of these changes:
Documentation SuggestionsAugment the In summary, while this PR marks a significant improvement in the management of AWS Bedrock sessions, implementing the above recommendations can further enhance code maintainability and usability. The focus on robust error handling, user-friendly messaging, and adherence to best practices illustrates a strong commitment to quality software development. |
Fixes #2299