Skip to content
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

AWS: Region is not getting setup #154

Open
pankajjainChainThat opened this issue Dec 16, 2024 · 2 comments
Open

AWS: Region is not getting setup #154

pankajjainChainThat opened this issue Dec 16, 2024 · 2 comments

Comments

@pankajjainChainThat
Copy link

pankajjainChainThat commented Dec 16, 2024

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)

@rohitprasad15
Copy link
Collaborator

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.

@pankajjainChainThat
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants