From 73a43c1caf0b7ae813ffa6a3241142ed678583cd Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 27 Feb 2024 18:35:08 +0530 Subject: [PATCH 1/8] add go example for amazon titan text model in bedrock --- gov2/bedrock-runtime/actions/invoke_model.go | 280 +++++++++++------- .../actions/invoke_model_test.go | 26 ++ .../scenarios/scenario_invoke_models.go | 13 + 3 files changed, 220 insertions(+), 99 deletions(-) diff --git a/gov2/bedrock-runtime/actions/invoke_model.go b/gov2/bedrock-runtime/actions/invoke_model.go index 4b267b34f81..8a44159eae2 100644 --- a/gov2/bedrock-runtime/actions/invoke_model.go +++ b/gov2/bedrock-runtime/actions/invoke_model.go @@ -44,35 +44,40 @@ type ClaudeResponse struct { // Invokes Anthropic Claude on Amazon Bedrock to run an inference using the input // provided in the request body. func (wrapper InvokeModelWrapper) InvokeClaude(prompt string) (string, error) { - modelId := "anthropic.claude-v2" + modelId := "anthropic.claude-v2" // Anthropic Claude requires enclosing the prompt as follows: enclosedPrompt := "Human: " + prompt + "\n\nAssistant:" - body, err := json.Marshal(ClaudeRequest { + body, err := json.Marshal(ClaudeRequest{ Prompt: enclosedPrompt, MaxTokensToSample: 200, Temperature: 0.5, StopSequences: []string{"\n\nHuman:"}, }) - if err != nil { log.Fatal("failed to marshal", err) } + if err != nil { + log.Fatal("failed to marshal", err) + } output, err := wrapper.BedrockRuntimeClient.InvokeModel(context.TODO(), &bedrockruntime.InvokeModelInput{ - ModelId: aws.String(modelId), + ModelId: aws.String(modelId), ContentType: aws.String("application/json"), - Body: body, + Body: body, }) - if err != nil { ProcessError(err, modelId) } + if err != nil { + ProcessError(err, modelId) + } var response ClaudeResponse - if err := json.Unmarshal(output.Body, &response); err != nil { - log.Fatal("failed to unmarshal", err) - } + if err := json.Unmarshal(output.Body, &response); err != nil { + log.Fatal("failed to unmarshal", err) + } return response.Completion, nil } + // snippet-end:[gov2.bedrock-runtime.InvokeClaude] // snippet-start:[gov2.bedrock-runtime.InvokeJurassic2] @@ -82,49 +87,54 @@ func (wrapper InvokeModelWrapper) InvokeClaude(prompt string) (string, error) { // https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-jurassic2.html type Jurassic2Request struct { - Prompt string `json:"prompt"` - MaxTokens int `json:"maxTokens,omitempty"` - Temperature float64 `json:"temperature,omitempty"` + Prompt string `json:"prompt"` + MaxTokens int `json:"maxTokens,omitempty"` + Temperature float64 `json:"temperature,omitempty"` } type Jurassic2Response struct { - Completions []Completion `json:"completions"` + Completions []Completion `json:"completions"` } type Completion struct { - Data Data `json:"data"` + Data Data `json:"data"` } type Data struct { - Text string `json:"text"` + Text string `json:"text"` } // Invokes AI21 Labs Jurassic-2 on Amazon Bedrock to run an inference using the input // provided in the request body. func (wrapper InvokeModelWrapper) InvokeJurassic2(prompt string) (string, error) { - modelId := "ai21.j2-mid-v1" + modelId := "ai21.j2-mid-v1" - body, err := json.Marshal(Jurassic2Request { - Prompt: prompt, - MaxTokens: 200, - Temperature: 0.5, + body, err := json.Marshal(Jurassic2Request{ + Prompt: prompt, + MaxTokens: 200, + Temperature: 0.5, }) - if err != nil { log.Fatal("failed to marshal", err) } + if err != nil { + log.Fatal("failed to marshal", err) + } output, err := wrapper.BedrockRuntimeClient.InvokeModel(context.TODO(), &bedrockruntime.InvokeModelInput{ - ModelId: aws.String(modelId), + ModelId: aws.String(modelId), ContentType: aws.String("application/json"), - Body: body, + Body: body, }) - if err != nil { ProcessError(err, modelId) } + if err != nil { + ProcessError(err, modelId) + } var response Jurassic2Response - if err := json.Unmarshal(output.Body, &response); err != nil { - log.Fatal("failed to unmarshal", err) - } + if err := json.Unmarshal(output.Body, &response); err != nil { + log.Fatal("failed to unmarshal", err) + } return response.Completions[0].Data.Text, nil } + // snippet-end:[gov2.bedrock-runtime.InvokeJurassic2] // snippet-start:[gov2.bedrock-runtime.InvokeLlama2] @@ -134,9 +144,9 @@ func (wrapper InvokeModelWrapper) InvokeJurassic2(prompt string) (string, error) // https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-meta.html type Llama2Request struct { - Prompt string `json:"prompt"` - MaxGenLength int `json:"max_gen_len,omitempty"` - Temperature float64 `json:"temperature,omitempty"` + Prompt string `json:"prompt"` + MaxGenLength int `json:"max_gen_len,omitempty"` + Temperature float64 `json:"temperature,omitempty"` } type Llama2Response struct { @@ -146,114 +156,186 @@ type Llama2Response struct { // Invokes Meta Llama 2 Chat on Amazon Bedrock to run an inference using the input // provided in the request body. func (wrapper InvokeModelWrapper) InvokeLlama2(prompt string) (string, error) { - modelId := "meta.llama2-13b-chat-v1" + modelId := "meta.llama2-13b-chat-v1" - body, err := json.Marshal(Llama2Request { - Prompt: prompt, - MaxGenLength: 512, - Temperature: 0.5, + body, err := json.Marshal(Llama2Request{ + Prompt: prompt, + MaxGenLength: 512, + Temperature: 0.5, }) - if err != nil { log.Fatal("failed to marshal", err) } + if err != nil { + log.Fatal("failed to marshal", err) + } output, err := wrapper.BedrockRuntimeClient.InvokeModel(context.TODO(), &bedrockruntime.InvokeModelInput{ - ModelId: aws.String(modelId), + ModelId: aws.String(modelId), ContentType: aws.String("application/json"), - Body: body, + Body: body, }) - if err != nil { ProcessError(err, modelId) } + if err != nil { + ProcessError(err, modelId) + } var response Llama2Response - if err := json.Unmarshal(output.Body, &response); err != nil { - log.Fatal("failed to unmarshal", err) - } - - + if err := json.Unmarshal(output.Body, &response); err != nil { + log.Fatal("failed to unmarshal", err) + } return response.Generation, nil } + // snippet-end:[gov2.bedrock-runtime.InvokeLlama2] // snippet-start:[gov2.bedrock-runtime.InvokeTitanImage] type TitanImageRequest struct { - TaskType string `json:"taskType"` - TextToImageParams TextToImageParams `json:"textToImageParams"` - ImageGenerationConfig ImageGenerationConfig `json:"imageGenerationConfig"` + TaskType string `json:"taskType"` + TextToImageParams TextToImageParams `json:"textToImageParams"` + ImageGenerationConfig ImageGenerationConfig `json:"imageGenerationConfig"` } type TextToImageParams struct { - Text string `json:"text"` + Text string `json:"text"` } type ImageGenerationConfig struct { - NumberOfImages int `json:"numberOfImages"` - Quality string `json:"quality"` - CfgScale float64 `json:"cfgScale"` - Height int `json:"height"` - Width int `json:"width"` - Seed int64 `json:"seed"` + NumberOfImages int `json:"numberOfImages"` + Quality string `json:"quality"` + CfgScale float64 `json:"cfgScale"` + Height int `json:"height"` + Width int `json:"width"` + Seed int64 `json:"seed"` } type TitanImageResponse struct { - Images []string `json:"images"` + Images []string `json:"images"` } // Invokes the Titan Image model to create an image using the input provided // in the request body. func (wrapper InvokeModelWrapper) InvokeTitanImage(prompt string, seed int64) (string, error) { - modelId := "amazon.titan-image-generator-v1" - - body, err := json.Marshal(TitanImageRequest { - TaskType: "TEXT_IMAGE", - TextToImageParams: TextToImageParams { - Text: prompt, - }, - ImageGenerationConfig: ImageGenerationConfig { - NumberOfImages: 1, - Quality: "standard", - CfgScale: 8.0, - Height: 512, - Width: 512, - Seed: seed, - }, - }) - - if err != nil { log.Fatal("failed to marshal", err) } - - output, err := wrapper.BedrockRuntimeClient.InvokeModel(context.TODO(), &bedrockruntime.InvokeModelInput{ - ModelId: aws.String(modelId), - ContentType: aws.String("application/json"), - Body: body, - }) - - if err != nil { ProcessError(err, modelId) } - - var response TitanImageResponse - if err := json.Unmarshal(output.Body, &response); err != nil { - log.Fatal("failed to unmarshal", err) - } - - base64ImageData := response.Images[0] - - return base64ImageData, nil + modelId := "amazon.titan-image-generator-v1" + + body, err := json.Marshal(TitanImageRequest{ + TaskType: "TEXT_IMAGE", + TextToImageParams: TextToImageParams{ + Text: prompt, + }, + ImageGenerationConfig: ImageGenerationConfig{ + NumberOfImages: 1, + Quality: "standard", + CfgScale: 8.0, + Height: 512, + Width: 512, + Seed: seed, + }, + }) + + if err != nil { + log.Fatal("failed to marshal", err) + } + + output, err := wrapper.BedrockRuntimeClient.InvokeModel(context.TODO(), &bedrockruntime.InvokeModelInput{ + ModelId: aws.String(modelId), + ContentType: aws.String("application/json"), + Body: body, + }) + + if err != nil { + ProcessError(err, modelId) + } + + var response TitanImageResponse + if err := json.Unmarshal(output.Body, &response); err != nil { + log.Fatal("failed to unmarshal", err) + } + + base64ImageData := response.Images[0] + + return base64ImageData, nil } + // snippet-end:[gov2.bedrock-runtime.InvokeTitanImage] +// snippet-start:[gov2.bedrock-runtime.InvokeTitanText] + +// Each model provider has their own individual request and response formats. +// For the format, ranges, and default values for Amazon Titan Text, refer to: +// https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-text.html +type TitanTextRequest struct { + InputText string `json:"inputText"` + TextGenerationConfig TextGenerationConfig `json:"textGenerationConfig"` +} + +type TextGenerationConfig struct { + Temperature float64 `json:"temperature"` + TopP float64 `json:"topP"` + MaxTokenCount int `json:"maxTokenCount"` + StopSequences []string `json:"stopSequences"` +} + +type TitanTextResponse struct { + InputTextTokenCount int `json:"inputTextTokenCount"` + Results []Result `json:"results"` +} + +type Result struct { + TokenCount int `json:"tokenCount"` + OutputText string `json:"outputText"` + CompletionReason string `json:"completionReason"` +} + +func (wrapper InvokeModelWrapper) InvokeTitanText(prompt string) (string, error) { + modelId := "amazon.titan-text-express-v1" + + body, err := json.Marshal(TitanTextRequest{ + InputText: prompt, + TextGenerationConfig: TextGenerationConfig{ + Temperature: 0, + TopP: 1, + MaxTokenCount: 4096, + }, + }) + + if err != nil { + log.Fatal("failed to marshal", err) + } + + output, err := wrapper.BedrockRuntimeClient.InvokeModel(context.Background(), &bedrockruntime.InvokeModelInput{ + ModelId: aws.String(modelId), + ContentType: aws.String("application/json"), + Body: body, + }) + + if err != nil { + ProcessError(err, modelId) + } + + var response TitanTextResponse + if err := json.Unmarshal(output.Body, &response); err != nil { + log.Fatal("failed to unmarshal", err) + } + + return response.Results[0].OutputText, nil +} + +// snippet-end:[gov2.bedrock-runtime.InvokeTitanText] + func ProcessError(err error, modelId string) { - errMsg := err.Error() - if strings.Contains(errMsg, "no such host") { - log.Printf(`The Bedrock service is not available in the selected region. + errMsg := err.Error() + if strings.Contains(errMsg, "no such host") { + log.Printf(`The Bedrock service is not available in the selected region. Please double-check the service availability for your region at https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/.\n`) - } else if strings.Contains(errMsg, "Could not resolve the foundation model") { - log.Printf(`Could not resolve the foundation model from model identifier: \"%v\". + } else if strings.Contains(errMsg, "Could not resolve the foundation model") { + log.Printf(`Could not resolve the foundation model from model identifier: \"%v\". Please verify that the requested model exists and is accessible within the specified region.\n `, modelId) - } else { - log.Printf("Couldn't invoke model: \"%v\". Here's why: %v\n", modelId, err) - } + } else { + log.Printf("Couldn't invoke model: \"%v\". Here's why: %v\n", modelId, err) + } } -// snippet-end:[gov2.bedrock-runtime.InvokeModelWrapper.complete] \ No newline at end of file +// snippet-end:[gov2.bedrock-runtime.InvokeModelWrapper.complete] diff --git a/gov2/bedrock-runtime/actions/invoke_model_test.go b/gov2/bedrock-runtime/actions/invoke_model_test.go index 716fb4274df..9500d9d061e 100644 --- a/gov2/bedrock-runtime/actions/invoke_model_test.go +++ b/gov2/bedrock-runtime/actions/invoke_model_test.go @@ -20,6 +20,7 @@ const CLAUDE_MODEL_ID = "anthropic.claude-v2" const JURASSIC2_MODEL_ID = "ai21.j2-mid-v1" const LLAMA2_MODEL_ID = "meta.llama2-13b-chat-v1" const TITAN_IMAGE_MODEL_ID = "amazon.titan-image-generator-v1" +const TITAN_TEXT_EXPRESS_MODEL_ID = "amazon.titan-text-express-v1" const prompt = "A test prompt" @@ -58,6 +59,12 @@ func CallInvokeModelActions(sdkConfig aws.Config) { } log.Println(titanImageCompletion) + titanTextCompletion, err := wrapper.InvokeTitanText(prompt) + if err != nil { + panic(err) + } + log.Println(titanTextCompletion) + log.Printf("Thanks for watching!") } @@ -74,6 +81,8 @@ func (scenTest *InvokeModelActionsTest) SetupDataAndStubs() []testtools.Stub { stubList = append(stubList, stubInvokeModel(JURASSIC2_MODEL_ID)) stubList = append(stubList, stubInvokeModel(LLAMA2_MODEL_ID)) stubList = append(stubList, stubInvokeModel(TITAN_IMAGE_MODEL_ID)) + stubList = append(stubList, stubInvokeModel(TITAN_TEXT_EXPRESS_MODEL_ID)) + return stubList } @@ -140,6 +149,23 @@ func stubInvokeModel(modelId string) testtools.Stub { Images: []string{"FakeBase64String=="}, }) + case TITAN_TEXT_EXPRESS_MODEL_ID: + request, _ = json.Marshal(TitanTextRequest{ + InputText: prompt, + TextGenerationConfig: TextGenerationConfig{ + Temperature: 0, + TopP: 1, + MaxTokenCount: 4096, + }, + }) + response, _ = json.Marshal(TitanTextResponse{ + Results: []Result{ + { + OutputText: "A fake response", + }, + }, + }) + default: return testtools.Stub{} } diff --git a/gov2/bedrock-runtime/scenarios/scenario_invoke_models.go b/gov2/bedrock-runtime/scenarios/scenario_invoke_models.go index 42a93f71957..517190babad 100644 --- a/gov2/bedrock-runtime/scenarios/scenario_invoke_models.go +++ b/gov2/bedrock-runtime/scenarios/scenario_invoke_models.go @@ -28,6 +28,7 @@ import ( // 3. Generate text with Meta Llama 2 Chat // 4. Generate text and asynchronously process the response stream with Anthropic Claude 2 // 5. Generate and image with the Amazon Titan image generation model +// 6. Generate text with Amazon Titan Text G1 Express model type InvokeModelsScenario struct { sdkConfig aws.Config invokeModelWrapper actions.InvokeModelWrapper @@ -93,6 +94,10 @@ func (scenario InvokeModelsScenario) Run() { log.Printf("Invoking Amazon Titan with prompt: %v\n", text2ImagePrompt) scenario.InvokeTitanImage(text2ImagePrompt, seed) + log.Println(strings.Repeat("-", 77)) + log.Printf("Invoking Titan Text Express with prompt: %v\n", text2textPrompt) + scenario.InvokeTitanText(text2textPrompt) + log.Println(strings.Repeat("=", 77)) log.Println("Thanks for watching!") log.Println(strings.Repeat("=", 77)) @@ -140,6 +145,14 @@ func (scenario InvokeModelsScenario) InvokeTitanImage(prompt string, seed int64) fmt.Printf("The generated image has been saved to %s\n", imagePath) } +func (scenario InvokeModelsScenario) InvokeTitanText(prompt string) { + completion, err := scenario.invokeModelWrapper.InvokeTitanText(prompt) + if err != nil { + panic(err) + } + log.Printf("\nTitan Text Express : %v\n\n", strings.TrimSpace(completion)) +} + // snippet-end:[gov2.bedrock-runtime.Scenario_InvokeModels] func saveImage(base64ImageData string, modelId string) string { From 983b3712ba07298dfce6e5b707e762a487111433 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 29 Feb 2024 16:52:37 +0530 Subject: [PATCH 2/8] add metadata, update readme --- .doc_gen/metadata/bedrock-runtime_metadata.yaml | 8 ++++++++ gov2/bedrock-runtime/README.md | 16 ++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.doc_gen/metadata/bedrock-runtime_metadata.yaml b/.doc_gen/metadata/bedrock-runtime_metadata.yaml index 62d816b1805..fbd1e08e9e4 100644 --- a/.doc_gen/metadata/bedrock-runtime_metadata.yaml +++ b/.doc_gen/metadata/bedrock-runtime_metadata.yaml @@ -74,6 +74,14 @@ bedrock-runtime_InvokeAmazonTitanImageGeneratorForTextGeneration: - description: Invoke the Amazon Titan Text G1 foundation model to generate text. snippet_files: - javascriptv3/example_code/bedrock-runtime/actions/invoke-titan-text-express-v1.js + Go: + versions: + - sdk_version: 2 + github: gov2/bedrock-runtime + excerpts: + - description: Invoke the Amazon Titan Text G1 foundation model to generate text. + snippet_tags: + - gov2.bedrock-runtime.InvokeTitanText services: bedrock-runtime: {InvokeModel} diff --git a/gov2/bedrock-runtime/README.md b/gov2/bedrock-runtime/README.md index 0508506dbf5..53a197fc8d1 100644 --- a/gov2/bedrock-runtime/README.md +++ b/gov2/bedrock-runtime/README.md @@ -27,7 +27,6 @@ For prerequisites, see the [README](../README.md#Prerequisites) in the `gov2` fo -> ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) 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). ### Get started @@ -39,11 +38,12 @@ For prerequisites, see the [README](../README.md#Prerequisites) in the `gov2` fo Code excerpts that show you how to call individual service functions. -- [Image generation with Amazon Titan Image Generator G1](actions/invoke_model.go#L178) (`InvokeModel`) -- [Text generation with AI21 Labs Jurassic-2](actions/invoke_model.go#L78) (`InvokeModel`) +- [Image generation with Amazon Titan Image Generator G1](actions/invoke_model.go#L191) (`InvokeModel`) +- [Text generation with AI21 Labs Jurassic-2](actions/invoke_model.go#L83) (`InvokeModel`) +- [Text generation with Amazon Titan Text G1](actions/invoke_model.go#L261) (`InvokeModel`) - [Text generation with Anthropic Claude 2](actions/invoke_model.go#L27) (`InvokeModel`) - [Text generation with Anthropic Claude 2 with a response stream](actions/invoke_model_with_response_stream.go#L30) (`InvokeModelWithResponseStream`) -- [Text generation with Meta Llama 2 Chat](actions/invoke_model.go#L130) (`InvokeModel`) +- [Text generation with Meta Llama 2 Chat](actions/invoke_model.go#L140) (`InvokeModel`) ### Scenarios @@ -62,14 +62,6 @@ functions within the same service. -#### Region configuration -By default, examples are set to `us-east-1`. To specify a different region, use the `-region` flag as shown in this example: - -``` -go run ./hello -region=eu-central-1 -``` - -Be aware that not all regions may support Bedrock and its models yet. Verify service availability for your region [here](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/). For available models per region, refer to the [Bedrock dashboard](https://console.aws.amazon.com/bedrock) in the AWS Management Console. #### Hello Amazon Bedrock From d29000122cbbd165e207a06e68ea5fbc0581ffef Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 29 Feb 2024 18:20:27 +0530 Subject: [PATCH 3/8] update titan text request config struct --- gov2/bedrock-runtime/actions/invoke_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gov2/bedrock-runtime/actions/invoke_model.go b/gov2/bedrock-runtime/actions/invoke_model.go index 8a44159eae2..8d72be41355 100644 --- a/gov2/bedrock-runtime/actions/invoke_model.go +++ b/gov2/bedrock-runtime/actions/invoke_model.go @@ -272,7 +272,7 @@ type TextGenerationConfig struct { Temperature float64 `json:"temperature"` TopP float64 `json:"topP"` MaxTokenCount int `json:"maxTokenCount"` - StopSequences []string `json:"stopSequences"` + StopSequences []string `json:"stopSequences,omitempty"` } type TitanTextResponse struct { From 4f786b04ba124e77be063b6dd4e7c049a861f844 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 7 Mar 2024 13:07:45 +0530 Subject: [PATCH 4/8] add instructions that were inadvertently removed --- gov2/bedrock-runtime/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gov2/bedrock-runtime/README.md b/gov2/bedrock-runtime/README.md index 53a197fc8d1..fefcb8d12b5 100644 --- a/gov2/bedrock-runtime/README.md +++ b/gov2/bedrock-runtime/README.md @@ -54,6 +54,7 @@ functions within the same service. +> ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) 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). ## Run the examples @@ -62,6 +63,14 @@ functions within the same service. +#### Region configuration +By default, examples are set to `us-east-1`. To specify a different region, use the `-region` flag as shown in this example: + +``` +go run ./hello -region=eu-central-1 +``` + +Be aware that not all regions may support Bedrock and its models yet. Verify service availability for your region [here](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/). For available models per region, refer to the [Bedrock dashboard](https://console.aws.amazon.com/bedrock) in the AWS Management Console. #### Hello Amazon Bedrock From f1c09ee0a385ba48e79123a6cfce8a47e5e6153e Mon Sep 17 00:00:00 2001 From: ford prior <108086978+ford-at-aws@users.noreply.github.com> Date: Wed, 24 Apr 2024 08:12:57 -0400 Subject: [PATCH 5/8] Update README.md --- gov2/bedrock-runtime/README.md | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/gov2/bedrock-runtime/README.md b/gov2/bedrock-runtime/README.md index b4703c9dd3f..23036004d77 100644 --- a/gov2/bedrock-runtime/README.md +++ b/gov2/bedrock-runtime/README.md @@ -27,24 +27,13 @@ For prerequisites, see the [README](../README.md#Prerequisites) in the `gov2` fo +> ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) 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). ### Get started - [Hello Amazon Bedrock](hello/hello.go#L4) (`InvokeModel`) - -### Single actions - -Code excerpts that show you how to call individual service functions. - -- [Image generation with Amazon Titan Image Generator G1](actions/invoke_model.go#L191) (`InvokeModel`) -- [Text generation with AI21 Labs Jurassic-2](actions/invoke_model.go#L83) (`InvokeModel`) -- [Text generation with Amazon Titan Text G1](actions/invoke_model.go#L261) (`InvokeModel`) -- [Text generation with Anthropic Claude 2](actions/invoke_model.go#L27) (`InvokeModel`) -- [Text generation with Anthropic Claude 2 with a response stream](actions/invoke_model_with_response_stream.go#L30) (`InvokeModelWithResponseStream`) -- [Text generation with Meta Llama 2 Chat](actions/invoke_model.go#L140) (`InvokeModel`) - ### Scenarios Code examples that show you how to accomplish a specific task by calling multiple @@ -52,9 +41,16 @@ functions within the same service. - [Invoke multiple foundation models on Amazon Bedrock](scenarios/scenario_invoke_models.go) +### Invoke model examples + +- [AI21 Labs Jurassic-2: Text generation](actions/invoke_model.go#L78) +- [Amazon Titan: Image generation](actions/invoke_model.go#L178) +- [Anthropic Claude 2: Real-time response stream processing](actions/invoke_model_with_response_stream.go#L30) +- [Anthropic Claude 2: Text generation](actions/invoke_model.go#L27) +- [Meta Llama 2: Text generation](actions/invoke_model.go#L130) + -> ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) 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). ## Run the examples @@ -128,4 +124,4 @@ in the `gov2` folder. Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -SPDX-License-Identifier: Apache-2.0 \ No newline at end of file +SPDX-License-Identifier: Apache-2.0 From aed631ebdd56dacb76796ed641b4c7637c525483 Mon Sep 17 00:00:00 2001 From: ford prior <108086978+ford-at-aws@users.noreply.github.com> Date: Wed, 24 Apr 2024 08:18:15 -0400 Subject: [PATCH 6/8] Update README.md --- gov2/bedrock-runtime/README.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gov2/bedrock-runtime/README.md b/gov2/bedrock-runtime/README.md index 23036004d77..8029f18db94 100644 --- a/gov2/bedrock-runtime/README.md +++ b/gov2/bedrock-runtime/README.md @@ -27,13 +27,24 @@ For prerequisites, see the [README](../README.md#Prerequisites) in the `gov2` fo -> ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) 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). ### Get started - [Hello Amazon Bedrock](hello/hello.go#L4) (`InvokeModel`) + +### Single actions + +Code excerpts that show you how to call individual service functions. + +- [AI21 Labs Jurassic-2: Text generation](actions/invoke_model.go#L83) (`InvokeModel`) +- [Amazon Titan: Image generation](actions/invoke_model.go#L191) (`InvokeModel`) +- [Amazon Titan: Text generation](actions/invoke_model.go#L261) (`InvokeModel`) +- [Anthropic Claude 2: Real-time response stream processing](actions/invoke_model_with_response_stream.go#L30) (`InvokeModelWithResponseStream`) +- [Anthropic Claude 2: Text generation](actions/invoke_model.go#L27) (`InvokeModel`) +- [Meta Llama 2: Text generation](actions/invoke_model.go#L140) (`InvokeModel`) + ### Scenarios Code examples that show you how to accomplish a specific task by calling multiple @@ -41,16 +52,9 @@ functions within the same service. - [Invoke multiple foundation models on Amazon Bedrock](scenarios/scenario_invoke_models.go) -### Invoke model examples - -- [AI21 Labs Jurassic-2: Text generation](actions/invoke_model.go#L78) -- [Amazon Titan: Image generation](actions/invoke_model.go#L178) -- [Anthropic Claude 2: Real-time response stream processing](actions/invoke_model_with_response_stream.go#L30) -- [Anthropic Claude 2: Text generation](actions/invoke_model.go#L27) -- [Meta Llama 2: Text generation](actions/invoke_model.go#L130) - +> ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) 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). ## Run the examples From 6fd89ded1f4e1d30e3d76d81dd59a2d0f9758524 Mon Sep 17 00:00:00 2001 From: ford prior <108086978+ford-at-aws@users.noreply.github.com> Date: Wed, 24 Apr 2024 08:19:54 -0400 Subject: [PATCH 7/8] Update README.md From 200c2244165126426aed125c87f10a63812091fe Mon Sep 17 00:00:00 2001 From: ford-at-aws Date: Wed, 24 Apr 2024 08:28:41 -0400 Subject: [PATCH 8/8] fixed README --- gov2/bedrock-runtime/README.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/gov2/bedrock-runtime/README.md b/gov2/bedrock-runtime/README.md index 14c70c19b8f..75b1a8e7222 100644 --- a/gov2/bedrock-runtime/README.md +++ b/gov2/bedrock-runtime/README.md @@ -33,18 +33,6 @@ For prerequisites, see the [README](../README.md#Prerequisites) in the `gov2` fo - [Hello Amazon Bedrock](hello/hello.go#L4) (`InvokeModel`) - -### Single actions - -Code excerpts that show you how to call individual service functions. - -- [AI21 Labs Jurassic-2: Text generation](actions/invoke_model.go#L83) (`InvokeModel`) -- [Amazon Titan: Image generation](actions/invoke_model.go#L191) (`InvokeModel`) -- [Amazon Titan: Text generation](actions/invoke_model.go#L261) (`InvokeModel`) -- [Anthropic Claude 2: Real-time response stream processing](actions/invoke_model_with_response_stream.go#L30) (`InvokeModelWithResponseStream`) -- [Anthropic Claude 2: Text generation](actions/invoke_model.go#L27) (`InvokeModel`) -- [Meta Llama 2: Text generation](actions/invoke_model.go#L140) (`InvokeModel`) - ### Scenarios Code examples that show you how to accomplish a specific task by calling multiple @@ -52,6 +40,15 @@ functions within the same service. - [Invoke multiple foundation models on Amazon Bedrock](scenarios/scenario_invoke_models.go) +### Invoke model examples + +- [AI21 Labs Jurassic-2: Text generation](actions/invoke_model.go#L83) +- [Amazon Titan: Image generation](actions/invoke_model.go#L191) +- [Amazon Titan: Text generation](actions/invoke_model.go#L261) +- [Anthropic Claude 2: Real-time response stream processing](actions/invoke_model_with_response_stream.go#L30) +- [Anthropic Claude 2: Text generation](actions/invoke_model.go#L27) +- [Meta Llama 2: Text generation](actions/invoke_model.go#L140) + > ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) 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).