Skip to content

Commit

Permalink
Merge branch 'main' into tools/spdx
Browse files Browse the repository at this point in the history
  • Loading branch information
beqqrry-aws authored Jan 16, 2024
2 parents 9d90bc1 + e6bb723 commit c5aa151
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 12 deletions.
33 changes: 32 additions & 1 deletion .doc_gen/metadata/bedrock_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,37 @@ bedrock_Hello:
versions:
- sdk_version: 3
github: dotnetv3/Bedrock
sdkguide:
excerpts:
- description:
snippet_tags:
- Bedrock.dotnetv3.BedrockActions.HelloBedrock
JavaScript:
versions:
- sdk_version: 3
github: javascriptv3/example_code/bedrock
excerpts:
- description:
snippet_files:
- javascriptv3/example_code/bedrock/hello.js
services:
bedrock: {ListFoundationModels}

bedrock_GetFoundationModel:
title: Get details about an &BRlong; foundation model using an &AWS; SDK
title_abbrev: Get details about an &BR; foundation model
synopsis: get details about an &BR; foundation model.
languages:
JavaScript:
versions:
- sdk_version: 3
github: javascriptv3/example_code/bedrock
excerpts:
- description: Get details about a foundation model.
snippet_files:
- javascriptv3/example_code/bedrock/actions/get-foundation-model.js
services:
bedrock: {GetFoundationModel}

bedrock_ListFoundationModels:
title: List the available &BRlong; foundation models using an &AWS; SDK
title_abbrev: List available &BR; foundation models
Expand All @@ -48,6 +71,14 @@ bedrock_ListFoundationModels:
- description: List the available &BRlong; foundation models.
snippet_tags:
- bedrock.java2.list_foundation_models.main
JavaScript:
versions:
- sdk_version: 3
github: javascriptv3/example_code/bedrock
excerpts:
- description: List the available foundation models.
snippet_files:
- javascriptv3/example_code/bedrock/actions/list-foundation-models.js
Kotlin:
versions:
- sdk_version: 1
Expand Down
4 changes: 4 additions & 0 deletions .tools/validation/metadata_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def __init__(self):
def append(self, item: MetadataError):
if not isinstance(item, MetadataError):
raise InvalidItemException(item)
"""
It is dangerous to go alone: 🗡️
If you're seeing duplicated Errors, and aren't sure why, uncommenting these lines may help you debug it.
"""
# if item in self._errors:
# raise DuplicateItemException(item)
self._errors.append(item)
Expand Down
2 changes: 1 addition & 1 deletion gov2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ RUN useradd -m automation && \
USER automation:automation

# Set default command
CMD ["./run_all_tests.sh", "integration"]
CMD ["/gov2/run_all_tests.sh", "integration"]
12 changes: 6 additions & 6 deletions gov2/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# SPDX-License-Identifier: Apache-2.0

function runCommand() {
dt=$(date +%Y-%m-%d)
if [ $@ ] && [ $@ == 'integration' ]
then
if [ "$1" ] && [ "$1" == 'integration' ]; then
kind='integration'
else
kind='unit'
fi
echo Running $kind tests...
for d in ./*/ ; do /bin/bash -c "(cd '$d' && go test -tags=$@ -timeout=60m ./...)"; done
echo "Running $kind tests..."
for d in /gov2/*/ ; do
/bin/bash -c "(cd '$d' && go test -tags='$1' -timeout=60m ./...)"
done
}

runCommand $1
runCommand "$1"
8 changes: 7 additions & 1 deletion java/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ AWS SDK for Java Documentation Examples

These are examples for the `AWS SDK for Java public documentation <javasdk-docs_>`_.

Prerequisites
NOTE
====

In alignment with our SDKs and Tools Maintenance Policy, the AWS SDK for Java v1.x will enter maintenance mode on July 31, 2024, and reach end-of-support on December 31, 2025.

For more information, see `Announcing end-of-support for AWS SDK for Java v1.x <https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/>`_.

=============

To build and run these examples, you'll need:
Expand Down
106 changes: 106 additions & 0 deletions javascriptv3/example_code/bedrock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Amazon Bedrock code examples for the SDK for JavaScript (v3)

## Overview

Shows how to use the AWS SDK for JavaScript (v3) to work with Amazon Bedrock.

<!--custom.overview.start-->
<!--custom.overview.end-->

_Amazon Bedrock enables you to build and scale generative AI applications with foundation models._

## ⚠ Important

* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/).
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).

<!--custom.important.start-->
<!--custom.important.end-->

## Code examples

### Prerequisites

For prerequisites, see the [README](../../README.md#Prerequisites) in the `javascriptv3` folder.


<!--custom.prerequisites.start-->
> ⚠ You must request access to a foundation model before you can use it. If you try to use the foundation model before you have requested access to it, you will receive an error message. For more information, see [Model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html).
<!--custom.prerequisites.end-->
### Get started

- [Hello Amazon Bedrock](javascriptv3/example_code/bedrock/hello.js) (`ListFoundationModels`)


### Single actions

Code excerpts that show you how to call individual service functions.

- [Get details about an Amazon Bedrock foundation model](javascriptv3/example_code/bedrock/actions/get-foundation-model.js) (`GetFoundationModel`)
- [List available Amazon Bedrock foundation models](javascriptv3/example_code/bedrock/actions/list-foundation-models.js) (`ListFoundationModels`)


<!--custom.examples.start-->
<!--custom.examples.end-->

## Run the examples

### Instructions

**Note**: All code examples are written in ECMAscript 6 (ES6). For guidelines on converting to CommonJS, see
[JavaScript ES6/CommonJS syntax](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/sdk-examples-javascript-syntax.html).

**Run a single action**

```bash
node ./actions/<fileName>
```

**Run a scenario**
Most scenarios can be run with the following command:
```bash
node ./scenarios/<fileName>
```

<!--custom.instructions.start-->
<!--custom.instructions.end-->

#### Hello Amazon Bedrock

This example shows you how to get started using Amazon Bedrock.

```bash
node ./hello.js
```


### Tests

⚠ Running tests might result in charges to your AWS account.


To find instructions for running these tests, see the [README](../../README.md#Tests)
in the `javascriptv3` folder.



<!--custom.tests.start-->
<!--custom.tests.end-->

## Additional resources

- [Amazon Bedrock User Guide](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html)
- [Amazon Bedrock API Reference](https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html)
- [SDK for JavaScript (v3) Amazon Bedrock reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock)

<!--custom.resources.start-->
<!--custom.resources.end-->

---

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
31 changes: 31 additions & 0 deletions javascriptv3/example_code/bedrock/actions/get-foundation-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import { fileURLToPath } from 'url';

import { BedrockClient, GetFoundationModelCommand } from '@aws-sdk/client-bedrock';

/**
* Get details about an Amazon Bedrock foundation model.
*
* @return {FoundationModelDetails} - The list of available bedrock foundation models.
*/
export const getFoundationModel = async () => {
const client = new BedrockClient();

const command = new GetFoundationModelCommand({
modelIdentifier: 'amazon.titan-embed-text-v1'
});

const response = await client.send(command);

return response.modelDetails;
};

// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const model = await getFoundationModel();
console.log(model);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import { fileURLToPath } from 'url';

import { BedrockClient, ListFoundationModelsCommand } from '@aws-sdk/client-bedrock';

/**
* List the available Amazon Bedrock foundation models.
*
* @return {FoundationModelSummary[]} - The list of available bedrock foundation models.
*/
export const listFoundationModels = async () => {
const client = new BedrockClient();

const input = {
// byProvider: 'STRING_VALUE',
// byCustomizationType: 'FINE_TUNING' || 'CONTINUED_PRE_TRAINING',
// byOutputModality: 'TEXT' || 'IMAGE' || 'EMBEDDING',
// byInferenceType: 'ON_DEMAND' || 'PROVISIONED',
};

const command = new ListFoundationModelsCommand(input);

const response = await client.send(command);

return response.modelSummaries;
}

// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const models = await listFoundationModels();
console.log(models);
}
47 changes: 47 additions & 0 deletions javascriptv3/example_code/bedrock/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import { fileURLToPath } from 'url';

import { BedrockClient, ListFoundationModelsCommand } from '@aws-sdk/client-bedrock';

const REGION = 'us-east-1';
const client = new BedrockClient( { region: REGION } );

export const main = async () => {
const command = new ListFoundationModelsCommand({});

const response = await client.send(command);
const models = response.modelSummaries;

console.log('Listing the available Bedrock foundation models:');

for (let model of models) {
console.log('='.repeat(42));
console.log(` Model: ${model.modelId}`);
console.log('-'.repeat(42));
console.log(` Name: ${model.modelName}`);
console.log(` Provider: ${model.providerName}`);
console.log(` Model ARN: ${model.modelArn}`);
console.log(` Input modalities: ${model.inputModalities}`);
console.log(` Output modalities: ${model.outputModalities}`);
console.log(` Supported customizations: ${model.customizationsSupported}`);
console.log(` Supported inference types: ${model.inferenceTypesSupported}`);
console.log(` Lifecycle status: ${model.modelLifecycle.status}`);
console.log('='.repeat(42) + '\n');
}

const active = models.filter(m => m.modelLifecycle.status === 'ACTIVE').length;
const legacy = models.filter(m => m.modelLifecycle.status === 'LEGACY').length;

console.log(`There are ${active} active and ${legacy} legacy foundation models in ${REGION}.`);

return response;
};

// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
await main();
}
17 changes: 17 additions & 0 deletions javascriptv3/example_code/bedrock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "bedrock-examples",
"version": "1.0.0",
"author": "Dennis Traub <[email protected]>",
"license": "Apache-2.0",
"type": "module",
"scripts": {
"integration-test": "vitest run **/*.integration.test.js"
},
"dependencies": {
"@aws-sdk/client-bedrock": "^3.485.0"
},
"devDependencies": {
"vitest": "^1.1.3",
"zod": "^3.22.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import { z } from 'zod';
import { describe, it, expect } from 'vitest';

import { getFoundationModel } from '../actions/get-foundation-model.js';

const ExpectedSchema = z.object({
modelId: z.string(),
modelName: z.string()
});

describe('get-foundation-model', () => {
it('should return the model\' details', async () => {
let modelDetails = await getFoundationModel();
expect(modelDetails).not.toBeNull();

const isModelDetails = ExpectedSchema.safeParse(modelDetails).success;
expect(isModelDetails).toBe(true);
});
});
Loading

0 comments on commit c5aa151

Please sign in to comment.