Skip to content

Commit 60570ea

Browse files
committed
add aws-guide
1 parent 120ed16 commit 60570ea

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

aisuite/providers/aws_bedrock_provider.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import boto3
24
from aisuite.provider import Provider, LLMError
35
from aisuite.framework import ChatCompletionResponse
@@ -31,7 +33,10 @@ def __init__(self, **config):
3133
**config: Configuration options for the provider.
3234
3335
"""
34-
self.client = boto3.client("bedrock-runtime", region_name="us-west-2")
36+
self.region_name = config.get(
37+
"region_name", os.getenv("AWS_REGION_NAME", "us-west-2")
38+
)
39+
self.client = boto3.client("bedrock-runtime", region_name=self.region_name)
3540
self.inference_parameters = [
3641
"maxTokens",
3742
"temperature",

guides/aws_bedrock.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# AWS Bedrock
2+
3+
To use AWS Bedrock with `aisuite` you will need to create an AWS account and
4+
navigate to `https://us-west-2.console.aws.amazon.com/bedrock/home`. This route
5+
will be redirected to your default region. In this example the region has been set to
6+
`us-west-2`. Anywhere that is listed can be replaced with your desired region.
7+
8+
Navigate to the `[overview](https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/overview)` page
9+
directly or by clicking on the `Get started` link.
10+
11+
## Foundation Model Access
12+
13+
You will first need to give your AWS account access to the foundation models by
14+
visiting the `[modelaccess](https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/modelaccess)`
15+
page to enable the models you would like to use. Make note of the `Model ID` for the model you would like to use,
16+
this will be used when using the chat completion example below.
17+
18+
Once that has been enabled set your Access Key and Secret in the env variables:
19+
20+
```shell
21+
export AWS_ACCESS_KEY="your-access-key"
22+
export AWS_SECRET_KEY="your-secret-key"
23+
export AWS_REGION_NAME="region-name"
24+
```
25+
## Create a Chat Completion
26+
27+
Install the boto3 client using your package installer
28+
29+
Example with pip
30+
```shell
31+
pip install boto3
32+
```
33+
34+
Example with poetry
35+
```shell
36+
poetry add boto3
37+
```
38+
39+
In your code:
40+
```python
41+
import aisuite as ai
42+
client = ai.Client()
43+
44+
45+
model_id = "meta.llama3-1-405b-instruct-v1:0" # Mode ID from above
46+
provider = "aws-bedrock"
47+
48+
messages = [
49+
{"role": "system", "content": "Respond in Pirate English."},
50+
{"role": "user", "content": "Tell me a joke."},
51+
]
52+
53+
response = client.chat.completions.create(
54+
model=f"{provider}:{model_id}",
55+
messages=messages,
56+
)
57+
58+
print(response.choices[0].message.content)
59+
```
60+
61+
Happy coding! If you would like to contribute, please read our [Contributing Guide](CONTRIBUTING.md).
62+
63+
64+
65+
66+

0 commit comments

Comments
 (0)