Skip to content

Commit 74d8d3e

Browse files
authored
Merge branch 'main' into update_go_examples
2 parents e4b3a64 + d40a9f4 commit 74d8d3e

8 files changed

Lines changed: 70 additions & 10 deletions

File tree

.doc_gen/metadata/bedrock-runtime_metadata.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ bedrock-runtime_Converse_AmazonNovaText:
9191
- description: Send a text message to Amazon Nova, using Bedrock's Converse API.
9292
snippet_tags:
9393
- python.example_code.bedrock-runtime.Converse_AmazonNovaText
94+
Go:
95+
versions:
96+
- sdk_version: 2
97+
github: gov2/bedrock-runtime
98+
excerpts:
99+
- description: Send a text message to Amazon Nova, using Bedrock's Converse API.
100+
snippet_tags:
101+
- gov2.bedrock-runtime.ConverseNova
94102
Swift:
95103
versions:
96104
- sdk_version: 1

.github/workflows/lint-golang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- uses: actions/setup-go@v5
2525
if: steps.changed-files.outputs.any_changed == 'true'
2626
with:
27-
go-version: '1.24'
27+
go-version: 1.24
2828
- name: install golangci-lint
2929
if: steps.changed-files.outputs.any_changed == 'true'
3030
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.8

gov2/bedrock-runtime/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ functions within the same service.
4040

4141
- [Invoke multiple foundation models on Amazon Bedrock](scenarios/scenario_invoke_models.go)
4242

43+
### Amazon Nova
44+
45+
- [Converse](actions/converse.go#L53)
46+
4347
### Amazon Titan Image Generator
4448

4549
- [InvokeModel](actions/invoke_model.go#L7)

gov2/bedrock-runtime/actions/converse.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,32 @@ func (wrapper ConverseWrapper) ConverseClaude(ctx context.Context, prompt string
4949
}
5050

5151
// snippet-end:[gov2.bedrock-runtime.ConverseClaude]
52+
53+
// snippet-start:[gov2.bedrock-runtime.ConverseNova]
54+
55+
func (wrapper ConverseWrapper) ConverseNova(ctx context.Context, prompt string) (string, error) {
56+
var content = types.ContentBlockMemberText{
57+
Value: prompt,
58+
}
59+
var message = types.Message{
60+
Content: []types.ContentBlock{&content},
61+
Role: "user",
62+
}
63+
modelId := "amazon.nova-lite-v1:0"
64+
var converseInput = bedrockruntime.ConverseInput{
65+
ModelId: aws.String(modelId),
66+
Messages: []types.Message{message},
67+
}
68+
response, err := wrapper.BedrockRuntimeClient.Converse(ctx, &converseInput)
69+
if err != nil {
70+
ProcessError(err, modelId)
71+
}
72+
73+
responseText, _ := response.Output.(*types.ConverseOutputMemberMessage)
74+
responseContentBlock := responseText.Value.Content[0]
75+
text, _ := responseContentBlock.(*types.ContentBlockMemberText)
76+
return text.Value, nil
77+
}
78+
79+
// snippet-end:[gov2.bedrock-runtime.ConverseNova]
5280
// snippet-end:[gov2.bedrock-runtime.Converse.complete]

gov2/bedrock-runtime/actions/converse_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
const CONVERSE_CLAUDE_MODEL_ID = "anthropic.claude-3-haiku-20240307-v1:0"
20+
const CONVERSE_NOVA_MODEL_ID = "amazon.nova-lite-v1:0"
2021
const CONVERSE_PROMPT = "Converse test prompt"
2122

2223
func CallConverseActions(sdkConfig aws.Config) {
@@ -36,6 +37,12 @@ func CallConverseActions(sdkConfig aws.Config) {
3637
}
3738
log.Println(claudeCompletion)
3839

40+
novaCompletion, err := wrapper.ConverseNova(ctx, CONVERSE_PROMPT)
41+
if err != nil {
42+
panic(err)
43+
}
44+
log.Println(novaCompletion)
45+
3946
log.Printf("Thanks for watching!")
4047
}
4148

@@ -71,6 +78,7 @@ func stubConverse(modelId string) testtools.Stub {
7178
func (scenTest *ConverseActionsTest) SetupDataAndStubs() []testtools.Stub {
7279
var stubList []testtools.Stub
7380
stubList = append(stubList, stubConverse(CONVERSE_CLAUDE_MODEL_ID))
81+
stubList = append(stubList, stubConverse(CONVERSE_NOVA_MODEL_ID))
7482

7583
return stubList
7684
}

gov2/bedrock-runtime/scenarios/scenario_converse.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
// ConverseScenario demonstrates how to use the Amazon Bedrock Runtime client
20-
// to Converse with Anthropic Claude
20+
// to Converse with Anthropic Claude, Amazon Nova
2121
type ConverseScenario struct {
2222
sdkConfig aws.Config
2323
questioner demotools.IQuestioner
@@ -56,6 +56,10 @@ func (scenario ConverseScenario) Run(ctx context.Context) {
5656
log.Printf("Invoking Claude with prompt: %v\n", text2textPrompt)
5757
scenario.ConverseClaude(ctx, text2textPrompt)
5858

59+
log.Println(strings.Repeat("-", 77))
60+
log.Printf("Invoking Amazon Nova with prompt: %v\n", text2textPrompt)
61+
scenario.ConverseNova(ctx, text2textPrompt)
62+
5963
log.Println(strings.Repeat("=", 77))
6064
log.Println("Thanks for watching!")
6165
log.Println(strings.Repeat("=", 77))
@@ -69,4 +73,12 @@ func (scenario ConverseScenario) ConverseClaude(ctx context.Context, prompt stri
6973
log.Printf("\nClaude : %v\n", strings.TrimSpace(completion))
7074
}
7175

76+
func (scenario ConverseScenario) ConverseNova(ctx context.Context, prompt string) {
77+
completion, err := scenario.converseWrapper.ConverseNova(ctx, prompt)
78+
if err != nil {
79+
panic(err)
80+
}
81+
log.Printf("\nAmazon Nova: %v\n", strings.TrimSpace(completion))
82+
}
83+
7284
// snippet-end:[gov2.bedrock-runtime.Scenario_Converse]

resources/clients/react/item-tracker/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/clients/react/item-tracker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"axios": "^1.15.0",
6+
"axios": "^1.15.2",
77
"react": "^18.1.0",
88
"react-bootstrap": "^2.4.0",
99
"react-dom": "^18.1.0",

0 commit comments

Comments
 (0)