最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I override how Aider connects to AWS Bedrock models? - Stack Overflow

programmeradmin1浏览0评论

My company exposed AWS Bedrock models for us to use. I have working python code to connect to the API. Note: there is no api-key. We connect via an access token. I really want to use Aider with this LLM but don't understand how I have to customize the Aider configuration. I'm looking for guidance on how I can use our way of connecting to the model with Aider. I've tried creating a custom provider with YAML file but Aider still expects an api-key.

This is how I can successfully connect to AWS Bedrock models directly in python.

def create_client():
    os.environ['AWS_ACCESS_KEY_ID'] = 'my_access_key'
    os.environ['AWS_SECRET_ACCESS_KEY'] = 'my_secret_access_key'
    os.environ['AWS_DEFAULT_REGION'] = 'us-east-1'
    access_token = "MY ACCESS TOKEN"
    base_url = os.getenv('BASE_URL', '')
    api_version = os.getenv('API_VERSION', 'v1.0')    
    bedrock_endpoint = f'{base_url}/{api_version}/model/bedrock'
    model_id = "claude-35-sonnet"

    class CustomHTTPAdapter(URLLib3Session):
        def send(self, request: AWSRequest, **kwargs):
            request.headers['authorization-token'] = access_token
            return super().send(request, **kwargs)

    try:
        bedrock_client = boto3.client(
            service_name='bedrock-runtime',
            region_name='us-east-1',
            endpoint_url=bedrock_endpoint,
        )
        
        # Assign the CustomHTTPAdapter to the bedrock_client's HTTP session
        bedrock_client._endpoint.http_session = CustomHTTPAdapter()
        
        model = ChatBedrockConverse(
            client=bedrock_client,
            model_id=model_id,
            temperature=0,
            max_tokens=None
        )
    
        return model

    except ClientError as err:
        print("A client error occurred:", err)    

def main():    
    load_dotenv()
    model = create_client()
发布评论

评论列表(0)

  1. 暂无评论