Skip to content
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

Missing components from response object for bedrock client #761

Closed
DyfanJones opened this issue Mar 11, 2024 · 1 comment · Fixed by #763
Closed

Missing components from response object for bedrock client #761

DyfanJones opened this issue Mar 11, 2024 · 1 comment · Fixed by #763
Labels
bug 🐞 Something isn't working

Comments

@DyfanJones
Copy link
Member

Hi @DyfanJones ,
thanks for the fix and apologies for the delayed response! I was on a lengthy business trip with limited hands-on-keyboard time. You were correct with your remark regarding the return object, which should and now is a json in raw bytes. Your fixes solved the issues described above.

After the latest release of paws.common-v0.7.1, I only found one minor difference in paws compared to boto3 for invoke_model.

The default contentType value is application/json (see boto3 documentation here), as shown below, re-using the Python example from above.

response = bedrock.invoke_model(body=body, modelId="anthropic.claude-v2:1")
print(response.get("contentType"))`

application/json

However, the R equivalent returns the following:

response <- bedrock$invoke_model(body = body, modelId = "anthropic.claude-v2:1")
response$contentType

logical(0)

The behavior stays the same even when setting the contentType explicitly:

response <- bedrock$invoke_model(body = body, contentType = "application/json", modelId = "anthropic.claude-v2:1")
response$contentType

logical(0)

Originally posted by @alex23lemm in #749 (comment)

@DyfanJones DyfanJones added the bug 🐞 Something isn't working label Mar 11, 2024
DyfanJones added a commit to DyfanJones/paws that referenced this issue Mar 12, 2024
@DyfanJones
Copy link
Member Author

DyfanJones commented Mar 12, 2024

I think I have a possible solution.

remotes::install_github("dyfanjones/paws/paws.common", ref ="unmarshal_header")

I believe aws sdk go v1 would have this bug as it skips the unmarshalling of headers that's first character is the same when set to lower case i.e. contentType
https://github.com/aws/aws-sdk-go/blob/main/private/protocol/rest/unmarshal.go#L117-L122

However botocore doesn't do this and would unmarshal all headers 🤔 when location is found.
https://github.com/boto/botocore/blob/7e24ee2369ef2fbd0bb89294848e2e4fc76e66a7/botocore/parsers.py#L949-L971

library(paws)
client <- bedrockruntime(config(credentials(profile = "paws")))

body <- list(prompt = "\n\nHuman: Tell me a funny joke about outer space\n\nAssistant:") |>
  jsonlite::toJSON(auto_unbox = TRUE)

response <- client$invoke_model(
  body = body,
  modelId = "ai21.j2-ultra",
)

response$contentType
#> [1] "application/json"

Created on 2024-03-12 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant