描述bug
当输入消息中存在带有重音符号的字符(如á)时,AWS Bedrock聊天模型会返回验证异常。
result = {ValidationException@22166} Method threw 'software.amazon.awssdk.services.bedrockruntime.model.ValidationException' exception.
stackTrace = {StackTraceElement[49]@22173}
0 = {StackTraceElement@22182} "software.amazon.awssdk.core.internal.http.CombinedResponseHandler.handleErrorResponse(CombinedResponseHandler.java:125)"
1 = {StackTraceElement@22183} "software.amazon.awssdk.core.internal.http.CombinedResponseHandler.handleResponse(CombinedResponseHandler.java:82)"
2 = {StackTraceElement@22184} "software.amazon.awssdk.core.internal.http.CombinedResponseHandler.handle(CombinedResponseHandler.java:60)"
3 = {StackTraceElement@22185} "software.amazon.awssdk.core.internal.http.CombinedResponseHandler.handle(CombinedResponseHandler.java:41)"
4 = {StackTraceElement@22186} "software.amazon.awssdk.core.internal.http.pipeline.stages.HandleResponseStage.execute(HandleResponseStage.java:50)"
5 = {StackTraceElement@22187} "software.amazon.awssdk.core.internal.http.pipeline.stages.HandleResponseStage.execute(HandleResponseStage.java:38)"
6 = {StackTraceElement@22188} "software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)"
7 = {StackTraceElement@22189} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptTimeoutTrackingStage.execute(ApiCallAttemptTimeoutTrackingStage.java:72)"
8 = {StackTraceElement@22190} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptTimeoutTrackingStage.execute(ApiCallAttemptTimeoutTrackingStage.java:42)"
9 = {StackTraceElement@22191} "software.amazon.awssdk.core.internal.http.pipeline.stages.TimeoutExceptionHandlingStage.execute(TimeoutExceptionHandlingStage.java:78)"
10 = {StackTraceElement@22192} "software.amazon.awssdk.core.internal.http.pipeline.stages.TimeoutExceptionHandlingStage.execute(TimeoutExceptionHandlingStage.java:40)"
11 = {StackTraceElement@22193} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptMetricCollectionStage.execute(ApiCallAttemptMetricCollectionStage.java:55)"
12 = {StackTraceElement@22194} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptMetricCollectionStage.execute(ApiCallAttemptMetricCollectionStage.java:39)"
13 = {StackTraceElement@22195} "software.amazon.awssdk.core.internal.http.pipeline.stages.RetryableStage.execute(RetryableStage.java:81)"
14 = {StackTraceElement@22196} "software.amazon.awssdk.core.internal.http.pipeline.stages.RetryableStage.execute(RetryableStage.java:36)"
15 = {StackTraceElement@22197} "software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)"
16 = {StackTraceElement@22198} "software.amazon.awssdk.core.internal.http.StreamManagingStage.execute(StreamManagingStage.java:56)"
17 = {StackTraceElement@22199} "software.amazon.awssdk.core.internal.http.StreamManagingStage.execute(StreamManagingStage.java:36)"
18 = {StackTraceElement@22200} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallTimeoutTrackingStage.executeWithTimer(ApiCallTimeoutTrackingStage.java:80)"
19 = {StackTraceElement@22201} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallTimeoutTrackingStage.execute(ApiCallTimeoutTrackingStage.java:60)"
20 = {StackTraceElement@22202} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallTimeoutTrackingStage.execute(ApiCallTimeoutTrackingStage.java:42)"
21 = {StackTraceElement@22203} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallMetricCollectionStage.execute(ApiCallMetricCollectionStage.java:50)"
22 = {StackTraceElement@22204} "software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallMetricCollectionStage.execute(ApiCallMetricCollectionStage.java:32)"
23 = {StackTraceElement@22205} "software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)"
24 = {StackTraceElement@22206} "software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206)"
25 = {StackTraceElement@22207} "software.amazon.awssdk.core.internal.http.pipeline.stages.ExecutionFailureExceptionReportingStage.execute(ExecutionFailureExceptionReportingStage.java:37)"
26 = {StackTraceElement@22208} "software.amazon.awssdk.core.internal.http.pipeline.stages.ExecutionFailureExceptionReportingStage.execute(ExecutionFailureExceptionReportingStage.java:26)"
27 = {StackTraceElement@22209} "software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient$RequestExecutionBuilderImpl.execute(AmazonSyncHttpClient.java:224)"
28 = {StackTraceElement@22210} "software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.invoke(BaseSyncClientHandler.java:103)"
29 = {StackTraceElement@22211} "software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.doExecute(BaseSyncClientHandler.java:173)"
30 = {StackTraceElement@22212} "software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.lambda$execute$1(BaseSyncClientHandler.java:80)"
31 = {StackTraceElement@22213} "software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.measureApiCallSuccess(BaseSyncClientHandler.java:182)"
32 = {StackTraceElement@22214} "software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.execute(BaseSyncClientHandler.java:74)"
33 = {StackTraceElement@22215} "software.amazon.awssdk.core.client.handler.SdkSyncClientHandler.execute(SdkSyncClientHandler.java:45)"
34 = {StackTraceElement@22216} "software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.execute(AwsSyncClientHandler.java:53)"
35 = {StackTraceElement@22217} "software.amazon.awssdk.services.bedrockruntime.DefaultBedrockRuntimeClient.invokeModel(DefaultBedrockRuntimeClient.java:149)"
36 = {StackTraceElement@22218} "dev.langchain4j.model.bedrock.internal.AbstractBedrockChatModel.invoke(AbstractBedrockChatModel.java:141)"
37 = {StackTraceElement@22219} "dev.langchain4j.model.bedrock.BedrockAnthropicMessageChatModel.lambda$generate$0(BedrockAnthropicMessageChatModel.java:69)"
38 = {StackTraceElement@22220} "dev.langchain4j.internal.RetryUtils$RetryPolicy.withRetry(RetryUtils.java:192)"
39 = {StackTraceElement@22221} "dev.langchain4j.internal.RetryUtils.withRetry(RetryUtils.java:229)"
40 = {StackTraceElement@22222} "dev.langchain4j.model.bedrock.BedrockAnthropicMessageChatModel.generate(BedrockAnthropicMessageChatModel.java:69)"
awsErrorDetails = {AwsErrorDetails@22169} "AwsErrorDetails(errorMessage=Malformed input request, please reformat your input and try again., errorCode=ValidationException, serviceName=BedrockRuntime)"
clockSkew = {Duration@21122} "PT0S"
requestId = "4c40820b-8c19-4e90-97ee-225f8642398e"
extendedRequestId = null
statusCode = 400
backtrace = {Object[5]@22171}
detailMessage = "Malformed input request, please reformat your input and try again."
cause = null
depth = 49
suppressedExceptions = {Collections$EmptyList@21127} size = 0
复现方法
要复现此问题,请使用非ASCII字符(如claude 3)与AWS Bedrock聊天模型一起使用。它需要调用AbstractBedrockChatModel.java的generate函数。
预期行为
无论字符串中包含什么字符,都应该正常工作。
根本原因和修复
问题的根本原因是我们在AbstractBedrockChatModel.java的invoke函数中使用了请求的默认字符集。为了解决这个问题,我们需要将"Charset.defaultCharset()"更改为"StandardCharsets.UTF_8"。
请填写以下信息:
- LangChain4j版本:0.29
- 使用的LLM(s):Bedrock Claude 3
- Java版本:11
2条答案
按热度按时间pkbketx91#
非常感谢你提供的反馈!既然你知道解决方案,能否请你发起一个PR?
pxq42qpu2#
我进行了更多的故障排除,发现这个问题只发生在Windows系统上,而不发生在Mac/Linux系统上。看起来
Charset.defaultCharset()
在Linux/Mac系统上返回的是'utf-8'编码,而在Windows系统上返回的是'windows-1252'编码。