Cookie の設定を選択する

当社は、当社のサイトおよびサービスを提供するために必要な必須 Cookie および類似のツールを使用しています。当社は、パフォーマンス Cookie を使用して匿名の統計情報を収集することで、お客様が当社のサイトをどのように利用しているかを把握し、改善に役立てています。必須 Cookie は無効化できませんが、[カスタマイズ] または [拒否] をクリックしてパフォーマンス Cookie を拒否することはできます。

お客様が同意した場合、AWS および承認された第三者は、Cookie を使用して便利なサイト機能を提供したり、お客様の選択を記憶したり、関連する広告を含む関連コンテンツを表示したりします。すべての必須ではない Cookie を受け入れるか拒否するには、[受け入れる] または [拒否] をクリックしてください。より詳細な選択を行うには、[カスタマイズ] をクリックしてください。

SDK for Kotlin を使用した Amazon Bedrock ランタイムの例 - AWS SDK コードの例

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

SDK for Kotlin を使用した Amazon Bedrock ランタイムの例

次のコード例は、Amazon Bedrock ランタイムで AWS SDK for Kotlin を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

トピック

Amazon Titan Text

次のコード例は、Invoke Model API を使用して Amazon Titan Text にテキストメッセージを送信する方法を示しています。

SDK for Kotlin
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

モデル呼び出し API を使用して、ショートストーリーを生成します。

import aws.sdk.kotlin.services.bedrockruntime.BedrockRuntimeClient import aws.sdk.kotlin.services.bedrockruntime.model.InvokeModelRequest import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json /** * Before running this Kotlin code example, set up your development environment, including your credentials. * * This example demonstrates how to invoke the Titan Text model (amazon.titan-text-lite-v1). * Remember that you must enable the model before you can use it. See notes in the README.md file. * * For more information, see the following documentation topic: * https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html */ suspend fun main() { val prompt = """ Write a short, funny story about a time-traveling cat who ends up in ancient Egypt at the time of the pyramids. """.trimIndent() val response = invokeModel(prompt, "amazon.titan-text-lite-v1") println("Generated story:\n$response") } suspend fun invokeModel(prompt: String, modelId: String): String { BedrockRuntimeClient { region = "eu-central-1" }.use { client -> val request = InvokeModelRequest { this.modelId = modelId contentType = "application/json" accept = "application/json" body = """ { "inputText": "${prompt.replace(Regex("\\s+"), " ").trim()}", "textGenerationConfig": { "maxTokenCount": 1000, "stopSequences": [], "temperature": 1, "topP": 0.7 } } """.trimIndent().toByteArray() } val response = client.invokeModel(request) val responseBody = response.body.toString(Charsets.UTF_8) val jsonParser = Json { ignoreUnknownKeys = true } return jsonParser .decodeFromString<BedrockResponse>(responseBody) .results .first() .outputText } } @Serializable private data class BedrockResponse(val results: List<Result>) @Serializable private data class Result(val outputText: String)
  • API の詳細については、 AWS SDK for Kotlin API InvokeModel」を参照してください。

次のコード例は、Invoke Model API を使用して Amazon Titan Text にテキストメッセージを送信する方法を示しています。

SDK for Kotlin
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

モデル呼び出し API を使用して、ショートストーリーを生成します。

import aws.sdk.kotlin.services.bedrockruntime.BedrockRuntimeClient import aws.sdk.kotlin.services.bedrockruntime.model.InvokeModelRequest import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json /** * Before running this Kotlin code example, set up your development environment, including your credentials. * * This example demonstrates how to invoke the Titan Text model (amazon.titan-text-lite-v1). * Remember that you must enable the model before you can use it. See notes in the README.md file. * * For more information, see the following documentation topic: * https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html */ suspend fun main() { val prompt = """ Write a short, funny story about a time-traveling cat who ends up in ancient Egypt at the time of the pyramids. """.trimIndent() val response = invokeModel(prompt, "amazon.titan-text-lite-v1") println("Generated story:\n$response") } suspend fun invokeModel(prompt: String, modelId: String): String { BedrockRuntimeClient { region = "eu-central-1" }.use { client -> val request = InvokeModelRequest { this.modelId = modelId contentType = "application/json" accept = "application/json" body = """ { "inputText": "${prompt.replace(Regex("\\s+"), " ").trim()}", "textGenerationConfig": { "maxTokenCount": 1000, "stopSequences": [], "temperature": 1, "topP": 0.7 } } """.trimIndent().toByteArray() } val response = client.invokeModel(request) val responseBody = response.body.toString(Charsets.UTF_8) val jsonParser = Json { ignoreUnknownKeys = true } return jsonParser .decodeFromString<BedrockResponse>(responseBody) .results .first() .outputText } } @Serializable private data class BedrockResponse(val results: List<Result>) @Serializable private data class Result(val outputText: String)
  • API の詳細については、 AWS SDK for Kotlin API InvokeModel」を参照してください。

プライバシーサイト規約Cookie の設定
© 2025, Amazon Web Services, Inc. or its affiliates.All rights reserved.