-
Notifications
You must be signed in to change notification settings - Fork 682
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
[BUG] Use ZhipuAiChatModel to input sensitive words #1079
Comments
To address the issue where Here's a snippet to guide you through handling a 400 error: @Override
public void onFailure(EventSource eventSource, Throwable t, okhttp3.Response response) {
if (response != null && response.code() == 400) {
try {
String responseBody = response.body().string();
log.error("Encountered sensitive words: {}", responseBody);
AiMessage errorMessage = AiMessage.from("Encountered sensitive words. Please adjust your query.");
Response<AiMessage> errorResponse = Response.from(errorMessage, null, FinishReason.ERROR);
handler.onComplete(errorResponse);
} catch (IOException e) {
log.error("Error handling sensitive words response", e);
handler.onError(new RuntimeException("Failed to handle sensitive words error.", e));
}
} else if (t != null) {
handler.onError(t);
} else {
handler.onError(new RuntimeException(String.format("Unexpected error: status code: %s; body: %s", response.code(), response.body())));
}
} This approach ensures that when sensitive words are detected, resulting in a 400 error, your application can handle the situation more elegantly by logging the error and notifying the user through a custom message, thus avoiding an abrupt termination of the program.
|
cc @1402564807 |
Describe the bug
Use ZhipuAiChatModel to input some sensitive words,error message not returned properly,Leads to a direct interruption of the programme, I would like to be able to return it normally via Response .
The error message is as follows:
status code: 400; body: {"error":{"code":"1301","message":"系统检测到输入或生成内容可能包含不安全或敏感内容,请您避免输入易产生敏感内容的提示语,感谢您的配合。"}}
Response<AiMessage> resMessage = zhipuAiChatModel.generate(asList(systemMessage,userMessage));
The text was updated successfully, but these errors were encountered: