from botocore.config import Config import boto3 BEDROCK_CONFIG = Config( read_timeout=300, ) class BedrockClient: """Generic LLM client for AWS Bedrock.""" def __init__( self, region_name: str = 'us-east-1', model_id: str = 'us.anthropic.claude-sonnet-4-5-20250929-v1:0', ): self.region_name = region_name self.model_id = model_id self.client = boto3.client( 'bedrock-runtime', region_name=region_name, config=BEDROCK_CONFIG ) def analyze_pr(self, prompt: str, max_tokens: int = 500_000) -> str: """Send PR data to Bedrock for analysis.""" # Truncate prompt if too long truncated_prompt = prompt[:max_tokens] try: model_response = self.client.converse( modelId=self.model_id, messages=[{'role': 'user', 'content': [{'text': truncated_prompt}]}], ) except Exception as e: print(f'Error analyzing PR: {e}') return f'Error analyzing PR: {e}' print(f"""Model {self.model_id} usage: {model_response['usage']} metrics: {model_response['metrics']} """) return model_response['output']['message']['content'][0]['text']