aisuite icon indicating copy to clipboard operation
aisuite copied to clipboard

AWS: Region is not getting setup

Open pankajjainChainThat opened this issue 11 months ago • 2 comments

I am setting the AWS_REGION but it is taking default 'us-west-2' region. I tried to set in system environment variables also, but code doesn't pick it up and give error "An error occurred (AccessDeniedException) when calling the Converse operation: You don't have access to the model with the specified model ID." Although if I create my own program then it is working fine.

import aisuite as ai import os from dotenv import load_dotenv, find_dotenv

def configure_environment(additional_env_vars=None): load_dotenv(find_dotenv()) if additional_env_vars: for key, value in additional_env_vars.items(): os.environ[key] = value

additional_keys = { 'AWS_ACCESS_KEY_ID': 'xxxx', 'AWS_SECRET_ACCESS_KEY': 'xxxxx', 'AWS_REGION': 'us-east-1' }

configure_environment(additional_env_vars=additional_keys)

client = ai.Client()

messages = [ {"role": "system", "content": "Respond in Pirate English."}, {"role": "user", "content": "Tell me a joke."}, ]

model = "aws:anthropic.claude-3-5-sonnet-20240620-v1:0" response = client.chat.completions.create(model=model , messages=messages) print(response.choices[0].message.content)

pankajjainChainThat avatar Dec 16 '24 14:12 pankajjainChainThat

Are you using the above code snippet ? additional_keys is overriding your env variables. Can you remove the additional_keys or make it empty. Can you retry and let me know if it works.

rohitprasad15 avatar Dec 17 '24 02:12 rohitprasad15

It is not working after removing the additional keys. Refer the below code which gives me error ->botocore.errorfactory.AccessDeniedException: An error occurred (AccessDeniedException) when calling the Converse operation: You don't have access to the model with the specified model ID. I have set "region = us-east-1" in system param.

import aisuite as ai

#aws bedrock with AI suite - NOT working client = ai.Client() messages = [ {"role": "system", "content": "Respond in Pirate English."}, {"role": "user", "content": "Tell me a joke."}, ]

model = "aws:anthropic.claude-3-5-sonnet-20240620-v1:0" response = client.chat.completions.create(model=model, messages=messages) print(response.choices[0].message.content)

To check the access to model I have executed below code which is working. In both cases AWS Keys and Region is coming from system parameters. #direct AWS bedrock code - Working import boto3 client = boto3.client("bedrock-runtime") messages = [ {"role": "user", "content": [{"text": "Who is the PM of India?"}]}, {"role": "assistant", "content": [{"text": "You are an advisor."}]}, {"role": "user", "content": [{"text": "Who is the PM of India?"}]} ] response = client.converse( modelId="anthropic.claude-3-5-sonnet-20240620-v1:0",
messages=messages ) print (response)

pankajjainChainThat avatar Dec 17 '24 03:12 pankajjainChainThat