paws-r / paws

Paws, a package for Amazon Web Services in R
https://www.paws-r-sdk.com
Other
315 stars 37 forks source link

invoke_model_with_response_stream generates lexical error: invalid char in json text, but points to blank #839

Open tonisama opened 3 days ago

tonisama commented 3 days ago

The invoke_model_with_response_stream function generates an error:

Error in parse_con(txt, bigint_as_char) : lexical error: invalid char in json text. (right here) ------^

The error occurs at the response request. The (right here) usually points to the infringing character, but points to nothing here. I replicated this same script in Python using the boto3 library and it works perfectly. In R, the invoke_model function without the streaming also works perfectly.

To ensure I wasn't making an error in the prompt encoding, I copied the hex representation from Python into R and converted it back to string which still gave me the same error.

Unfortunately, due to the error, R doesn't record the response, so I'm unable to view any server-side error messages.

DyfanJones commented 1 day ago

HI @tonisama can you provide a code example please. To help me reproduce the error.

tonisama commented 1 day ago

HI @tonisama can you provide a code example please. To help me reproduce the error.

Sure, but you'll need bedrock credentials to use it. bedrock-test-stream-v2.txt

DyfanJones commented 17 hours ago

This error is coming from https://github.com/paws-r/paws/blob/45ece0e51f9ae4d4a1722c87bba35a1ecdff59e8/paws.common/R/jsonutil.R#L4-L17

I am not sure what is going on regarding the parsing of the body. However I believe this method is not fully supported as of yet. Paws will need to develop a streaming method to parse the data. I will have to see how botocore does it and go from there. In the meantime is invoke_model method suitable?

DyfanJones commented 17 hours ago

As paws is currently built off httr. We will have to investigate this method: https://httr.r-lib.org/reference/write_stream.html or potentially go to httr2 or the underlying curl package.

tonisama commented 9 hours ago

This error is coming from

https://github.com/paws-r/paws/blob/45ece0e51f9ae4d4a1722c87bba35a1ecdff59e8/paws.common/R/jsonutil.R#L4-L17

I am not sure what is going on regarding the parsing of the body. However I believe this method is not fully supported as of yet. Paws will need to develop a streaming method to parse the data. I will have to see how botocore does it and go from there. In the meantime is invoke_model method suitable?

Thanks! invoke_model works just fine.