Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fa17956
added kotlin location scenario
scmacdon Apr 2, 2025
ef1348b
added kotlin location scenario
scmacdon Apr 2, 2025
5f39c34
updated a snippet tag
scmacdon Apr 2, 2025
e228549
updated a snippet tag
scmacdon Apr 2, 2025
88bb4d2
updated a snippet tag
scmacdon Apr 2, 2025
6a48fbb
updated a snippet tag
scmacdon Apr 2, 2025
68bdbf1
updated Kotlin tests
scmacdon Apr 3, 2025
981ed7b
updated Kotlin location readme
scmacdon Apr 3, 2025
80460a9
updated example for linter issue
scmacdon Apr 3, 2025
6aa13c0
updated example for linter issue
scmacdon Apr 3, 2025
e9bbe31
updated example for linter issue
scmacdon Apr 3, 2025
064ec1a
updated example for linter issue
scmacdon Apr 3, 2025
b4f354d
updated example for linter issue
scmacdon Apr 3, 2025
ae6b4bf
updated example for linter issue
scmacdon Apr 3, 2025
9772d61
updated example for linter issue
scmacdon Apr 3, 2025
6767007
updated example for linter issue
scmacdon Apr 3, 2025
38cded3
updated example for linter issue
scmacdon Apr 3, 2025
cac03d3
updated example for linter issue
scmacdon Apr 3, 2025
0047e00
updated example for linter issue
scmacdon Apr 3, 2025
3bcd8fd
updated example for linter issue
scmacdon Apr 3, 2025
30b0dcf
updated example for linter issue
scmacdon Apr 3, 2025
6ff2b86
updated example for linter issue
scmacdon Apr 3, 2025
7ce09ef
updated example for linter issue
scmacdon Apr 3, 2025
4e21620
updated example for linter issue
scmacdon Apr 3, 2025
05f0c0e
updated example for linter issue
scmacdon Apr 3, 2025
57a3bf9
updated example for linter issue
scmacdon Apr 3, 2025
0755edc
added the Bedrock converse example
scmacdon Apr 3, 2025
1a582d1
added the Bedrock converse example
scmacdon Apr 3, 2025
a780ec6
added the Bedrock converse test
scmacdon Apr 4, 2025
4affacd
added the Bedrock converse test
scmacdon Apr 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .doc_gen/metadata/bedrock-runtime_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ bedrock-runtime_Scenario_ToolUse:
synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input."
category: Scenarios
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/bedrock-runtime
excerpts:
- description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool."
snippet_tags:
- bedrock.converseTool.javav2.scenario
- description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API."
genai: some
snippet_tags:
- bedrock.converseTool.javav2.weathertool
- description: "The Converse API action with a tool configuration."
genai: some
snippet_tags:
- bedrockruntime.java2.converse.main
.NET:
versions:
- sdk_version: 3
Expand Down
144 changes: 144 additions & 0 deletions .doc_gen/metadata/location_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ location_Hello:
synopsis: get started using &ALlong;.
category: Hello
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.hello.main
Java:
versions:
- sdk_version: 2
Expand All @@ -18,6 +27,15 @@ location_Hello:
location: {ListGeofencesPaginator}
location_CreateMap:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.create.map.main
Java:
versions:
- sdk_version: 2
Expand All @@ -31,6 +49,15 @@ location_CreateMap:
location: {CreateMap}
location_CreateKey:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.create.key.main
Java:
versions:
- sdk_version: 2
Expand All @@ -44,6 +71,15 @@ location_CreateKey:
location: {CreateKey}
location_CreateGeofenceCollection:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.create.collection.main
Java:
versions:
- sdk_version: 2
Expand All @@ -57,6 +93,15 @@ location_CreateGeofenceCollection:
location: {CreateGeofenceCollection}
location_PutGeofence:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.put.geo.main
Java:
versions:
- sdk_version: 2
Expand All @@ -70,6 +115,15 @@ location_PutGeofence:
location: {PutGeofence}
location_CreateTracker:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.create.tracker.main
Java:
versions:
- sdk_version: 2
Expand All @@ -83,6 +137,15 @@ location_CreateTracker:
location: {CreateTracker}
location_BatchUpdateDevicePosition:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.update.device.position.main
Java:
versions:
- sdk_version: 2
Expand All @@ -96,6 +159,15 @@ location_BatchUpdateDevicePosition:
location: {BatchUpdateDevicePosition}
location_GetDevicePosition:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.get.device.position.main
Java:
versions:
- sdk_version: 2
Expand All @@ -109,6 +181,15 @@ location_GetDevicePosition:
location: {GetDevicePosition}
location_CreateRouteCalculator:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.create.calculator.main
Java:
versions:
- sdk_version: 2
Expand All @@ -122,6 +203,15 @@ location_CreateRouteCalculator:
location: {CreateRouteCalculator}
location_CalculateRoute:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.calc.distance.main
Java:
versions:
- sdk_version: 2
Expand All @@ -135,6 +225,15 @@ location_CalculateRoute:
location: {CalculateRoute}
location_DeleteGeofenceCollection:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.delete.collection.main
Java:
versions:
- sdk_version: 2
Expand All @@ -148,6 +247,15 @@ location_DeleteGeofenceCollection:
location: {DeleteGeofenceCollection}
location_DeleteKey:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.delete.key.main
Java:
versions:
- sdk_version: 2
Expand All @@ -161,6 +269,15 @@ location_DeleteKey:
location: {DeleteKey}
location_DeleteMap:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.delete.map.main
Java:
versions:
- sdk_version: 2
Expand All @@ -174,6 +291,15 @@ location_DeleteMap:
location: {DeleteMap}
location_DeleteTracker:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.delete.tracker.main
Java:
versions:
- sdk_version: 2
Expand All @@ -187,6 +313,15 @@ location_DeleteTracker:
location: {DeleteTracker}
location_DeleteRouteCalculator:
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.delete.calculator.main
Java:
versions:
- sdk_version: 2
Expand Down Expand Up @@ -214,6 +349,15 @@ location_Scenario:
- Delete the &ALshort; Assets.
category: Basics
languages:
Kotlin:
versions:
- sdk_version: 1
github: kotlin/services/location
sdkguide:
excerpts:
- description:
snippet_tags:
- location.kotlin.scenario.main
Java:
versions:
- sdk_version: 2
Expand Down
9 changes: 9 additions & 0 deletions javav2/example_code/bedrock-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>sts</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.example.bedrockruntime.scenario;

import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.bedrockruntime.model.ConverseRequest;
import software.amazon.awssdk.services.bedrockruntime.model.ConverseResponse;
import software.amazon.awssdk.services.bedrockruntime.model.Message;
import software.amazon.awssdk.services.bedrockruntime.model.SystemContentBlock;
import software.amazon.awssdk.services.bedrockruntime.model.Tool;
import software.amazon.awssdk.services.bedrockruntime.model.ToolConfiguration;
import software.amazon.awssdk.services.bedrockruntime.model.ToolSpecification;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

public class BedrockActions {

private static volatile BedrockRuntimeAsyncClient bedrockRuntimeClient;

private BedrockRuntimeAsyncClient getClient() {
if (bedrockRuntimeClient == null) {
/*
The `NettyNioAsyncHttpClient` class is part of the AWS SDK for Java, version 2,
and it is designed to provide a high-performance, asynchronous HTTP client for interacting with AWS services.
It uses the Netty framework to handle the underlying network communication and the Java NIO API to
provide a non-blocking, event-driven approach to HTTP requests and responses.
*/

SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder()
.maxConcurrency(50) // Adjust as needed.
.connectionTimeout(Duration.ofSeconds(60)) // Set the connection timeout.
.readTimeout(Duration.ofSeconds(60)) // Set the read timeout.
.writeTimeout(Duration.ofSeconds(60)) // Set the write timeout.
.build();

ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder()
.apiCallTimeout(Duration.ofMinutes(2)) // Set the overall API call timeout.
.apiCallAttemptTimeout(Duration.ofSeconds(90)) // Set the individual call attempt timeout.
.retryStrategy(RetryMode.STANDARD)
.build();

bedrockRuntimeClient = BedrockRuntimeAsyncClient.builder()
.region(Region.US_EAST_1)
.httpClient(httpClient)
.overrideConfiguration(overrideConfig)
.build();
}
return bedrockRuntimeClient;
}

// snippet-start:[bedrockruntime.java2.converse.main]
/**
* Sends an asynchronous converse request to the AI model.
*
* @param modelId the unique identifier of the AI model to be used for the converse request
* @param systemPrompt the system prompt to be included in the converse request
* @param conversation a list of messages representing the conversation history
* @param toolSpec the specification of the tool to be used in the converse request
* @return the converse response received from the AI model
*/
public ConverseResponse sendConverseRequestAsync(String modelId, String systemPrompt, List<Message> conversation, ToolSpecification toolSpec) {
List<Tool> toolList = new ArrayList<>();
Tool tool = Tool.builder()
.toolSpec(toolSpec)
.build();

toolList.add(tool);

ToolConfiguration configuration = ToolConfiguration.builder()
.tools(toolList)
.build();

SystemContentBlock block = SystemContentBlock.builder()
.text(systemPrompt)
.build();

ConverseRequest request = ConverseRequest.builder()
.modelId(modelId)
.system(block)
.messages(conversation)
.toolConfig(configuration)
.build();

try {
ConverseResponse response = getClient().converse(request).join();
return response;

} catch (Exception ex) {
ex.printStackTrace();
}

return null;
}
// snippet-end:[bedrockruntime.java2.converse.main]
}


Loading
Loading