-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document examples for UnmarshalSmithyDocument don't work #2751
Comments
Hi @mgomes , Can you give us a little more info about how you are trying to use this document unmarshalling? Thanks, |
Hi @RanVaknin 👋, I am using it with tool use via the converse API. When a tool is selected by the model a ToolUseBlock is returned. The It seems to work in code, but in my unit test it fails. My code looks something like this: var args map[string]interface{}
err := bedrockToolUse.Value.Input.UnmarshalSmithyDocument(&args)
if err != nil {
slog.Error("unmarshalling tool arguments.", slog.Any("error", err))
return toolCalls
} The test attempts to construct some sample arguments: name: "Valid tool use transformation",
input: &types.ContentBlockMemberToolUse{
Value: types.ToolUseBlock{
ToolUseId: aws.String("tool-id"),
Name: aws.String("test-tool"),
Input: document.NewLazyDocument(map[string]interface{}{
"param1": "value1",
}),
},
} But it fails with the same error as the reproduction code I pasted. Any recommendations for a workaround? |
Hi there, Thanks for the clarification. Admittedly I was not too familiar with the document deserializer because there are very few services that use it. Looking at the deserializer source code that gets generated for each client, there are two aws-sdk-go-v2/service/bedrockruntime/internal/document/document.go Lines 60 to 63 in d1d210d
Because that is the one that the actual API client uses. So in your case: package main
import (
"fmt"
smithydocumentjson "github.com/aws/smithy-go/document/json"
"log"
)
type mockDoc struct {
mockedValue interface{}
}
func (m *mockDoc) UnmarshalSmithyDocument(v interface{}) error {
decoder := smithydocumentjson.NewDecoder()
return decoder.DecodeJSONInterface(m.mockedValue, v)
}
func main() {
doc := mockDoc{
map[string]interface{}{
"param1": "value1",
},
}
var result map[string]interface{}
err := doc.UnmarshalSmithyDocument(&result)
if err != nil {
log.Fatalf("Error unmarshalling Smithy document: %v", err)
}
fmt.Printf("Unmarshalled result: %+v\n", result)
}
// Unmarshalled result: map[param1:value1] Thanks, |
Describe the issue
Here is a minimally reproducible example of the issue I am running into:
Running this code produces the error:
Error unmarshalling Smithy document: unsupported json type, *map[string]interface {}
Is
NewLazyDocument
storing the map as a pointer internally somehow and so it isn't getting recognized? It seems like it should work when looking at the decoder: https://github.com/aws/smithy-go/blob/main/document/json/decoder.go#L71.Links
https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/omics/document
AWS Go SDK V2 Module Versions Used
1.23.4
The text was updated successfully, but these errors were encountered: