提交 a8d240cf 编写于 作者: O obdev 提交者: ob-robot

fix error code for ai function

上级 e6ebfb49
......@@ -53,7 +53,7 @@ int ObAIFuncExprInfo::init(ObIAllocator &allocator, const ObString &model_id, sh
} else if (OB_ISNULL(ai_model_schema)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("ai model schema is null", KR(ret), K(MTL_ID()), K(model_id));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai model not found, please check if the model exists");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_function, ai model not found, please check if the model exists");
} else {
OZ(ob_write_string(allocator, ai_model_schema->get_name(), name_));
OZ(ob_write_string(allocator, ai_model_schema->get_model_name(), model_));
......
......@@ -85,6 +85,7 @@ int ObAIFuncClient::init(common::ObIAllocator &allocator, const common::ObString
LOG_WARN("failed to convert url to cstring", K(ret));
} else {
url_ = url_str.ptr();
LOG_DEBUG("ai_function, url_", K(url_str));
}
timeout_sec_ = std::min(std::max(1L, remain_timeout_us / 1000000), CURL_MAX_TIMEOUT_SEC);
abs_timeout_ts_ = remain_timeout_us + ObTimeUtility::current_time();
......@@ -97,6 +98,8 @@ int ObAIFuncClient::init(common::ObIAllocator &allocator, const common::ObString
} else if (OB_ISNULL(header_list_ = curl_slist_append(header_list_, header_c_str.ptr()))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to append header", K(ret), K(i));
} else {
LOG_DEBUG("ai_function, header:", K(headers.at(i)));
}
}
}
......@@ -117,7 +120,10 @@ int ObAIFuncClient::error_handle(CURLcode res)
}
default:{
ret = OB_CURL_ERROR;
LOG_WARN("curl error", K(res));
LOG_WARN("curl error, error code is ", K(res));
char http_code_str[1024] = "curl error, curl error code is ";
snprintf(http_code_str, sizeof(http_code_str), "curl error, curlerror code is %d", res);
FORWARD_USER_ERROR(ret, http_code_str);
break;
}
}
......@@ -145,7 +151,7 @@ int ObAIFuncClient::send_post(ObJsonObject *data, ObJsonObject *&response)
LOG_WARN("fail to init easy handle", K(ret));
}
// retry if need
for (int64_t i = 0; OB_SUCC(ret) && i < max_retry_times_; ++i) {
for (int64_t i = 0; OB_SUCC(ret) && i <= max_retry_times_; ++i) {
http_code = 0;
if (CURLE_OK != (res = curl_easy_perform(curl_))) {
LOG_WARN("perform curl failed", K(res));
......@@ -431,12 +437,13 @@ int ObAIFuncClient::init_easy_handle(CURL *curl, ObJsonObject *body, ObStringBuf
LOG_WARN("fail to init curl", K(ret));
}
ObString body_str = j_buf.string();
LOG_DEBUG("ai_function, body_str", K(body_str));
CURLcode res;
const int64_t no_delay = 1;
const int64_t no_signal = 1;
if (OB_SUCC(ret)) {
if (CURLE_OK != (res = curl_easy_setopt(curl, CURLOPT_URL, url_))) {
LOG_WARN("set url failed", K(res));
LOG_WARN("set url failed", K(res), K(url_));
} else if (CURLE_OK !=(res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ObAIFuncClient::write_callback))) {
LOG_WARN("set write function failed", K(res));
} else if (CURLE_OK !=(res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_buf))) {
......@@ -448,19 +455,19 @@ int ObAIFuncClient::init_easy_handle(CURL *curl, ObJsonObject *body, ObStringBuf
} else if (CURLE_OK !=(res = curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 10000))) {
LOG_WARN("set connection timeout ms failed", K(res));
} else if (CURLE_OK != (res = curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout_sec_))) {
LOG_WARN("set timeout failed", K(res));
LOG_WARN("set timeout failed", K(res), K(timeout_sec_));
} else if (CURLE_OK !=(res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list_))) {
LOG_WARN("set headers failed", K(res));
} else if (CURLE_OK !=(res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_str.ptr()))) {
LOG_WARN("set post failed", K(res));
LOG_WARN("set post failed", K(res), K(body_str.ptr()));
} else if (CURLE_OK != (res = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,body_str.length()))) {
LOG_WARN("set post failed", K(res));
LOG_WARN("set post failed", K(res), K(body_str.length()));
} else if (CURLE_OK != (res = curl_easy_setopt(curl, CURLOPT_POST, 1))) {
LOG_WARN("set post method failed", K(res));
}
if (CURLE_OK != res) {
ret = OB_CURL_ERROR;
LOG_WARN("fail to set curl options", K(res), K(res));
LOG_WARN("fail to set curl options", K(ret), K(res), K(body_str.ptr()), K(timeout_sec_));
}
}
return ret;
......@@ -500,6 +507,8 @@ size_t ObAIFuncClient::write_callback(void *contents, size_t size, size_t nmemb,
result.reserve(total_size);
if (OB_FAIL(result.append(static_cast<const char *>(contents), total_size, 0))) {
LOG_WARN("failed to append to result", K(ret));
} else {
LOG_DEBUG("ai_function, http response", K(result.string()));
}
}
return OB_SUCC(ret) ? total_size : 0;
......
......@@ -199,8 +199,8 @@ int ObOpenAIUtils::ObOpenAIComplete::parse_output(common::ObIAllocator &allocato
} else if (OB_FAIL(j_tree->seek(j_path, j_path.path_node_cnt(), false, false, hit))) {
LOG_WARN("json seek failed", K(ret));
} else if (hit.size() == 0) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("hit is empty", K(ret));
ret = OB_INVALID_DATA;
LOG_WARN("http response format is not as expected, failed to get content", K(ret));
} else {
result = hit[0];
}
......@@ -266,23 +266,23 @@ int ObOpenAIUtils::ObOpenAIEmbed::parse_output(common::ObIAllocator &allocator,
if (OB_FAIL(ObAIFuncJsonUtils::get_json_array(allocator, result_array))) {
LOG_WARN("Failed to get json array", K(ret));
} else if (OB_ISNULL(data_node = http_response->get_value("data"))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("Failed to get data", K(ret));
} else {
ObJsonArray *data_array = static_cast<ObJsonArray *>(data_node);
ObJsonNode *embedding_node = nullptr;
for (int64_t i = 0; OB_SUCC(ret) && i < data_array->element_count(); i++) {
if (OB_ISNULL(embedding_node = data_array->get_value(i))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("Failed to get embedding", K(ret));
} else if (embedding_node->json_type() != ObJsonNodeType::J_OBJECT) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("Failed to get embedding node", K(ret));
} else {
ObJsonObject *embedding_obj = static_cast<ObJsonObject *>(embedding_node);
ObJsonNode *embedding = embedding_obj->get_value("embedding");
if (OB_ISNULL(embedding)) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("Failed to get embedding", K(ret));
} else if (OB_FAIL(result_array->append(embedding))) {
LOG_WARN("Failed to append embedding", K(ret));
......@@ -605,19 +605,19 @@ int ObDashscopeUtils::ObDashscopeComplete::parse_output(ObIAllocator &allocator,
ObJsonString *content_str = nullptr;
ObString response_str;
if (OB_ISNULL(output_obj = static_cast<ObJsonObject *>(http_response->get_value("output")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("output_obj is null", K(ret));
} else if (OB_ISNULL(choices_array = static_cast<ObJsonArray *>(output_obj->get_value("choices")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("choices_array is null", K(ret));
} else if (OB_ISNULL(choice_obj = static_cast<ObJsonObject *>(choices_array->get_value(0)))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("choice_obj is null", K(ret));
} else if (OB_ISNULL(message_obj = static_cast<ObJsonObject *>(choice_obj->get_value("message")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("message_obj is null", K(ret));
} else if (OB_ISNULL(content_str = static_cast<ObJsonString *>(message_obj->get_value("content")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("content_str is null", K(ret));
} else {
result = content_str;
......@@ -701,18 +701,18 @@ int ObDashscopeUtils::ObDashscopeEmbed::parse_output(common::ObIAllocator &alloc
if (OB_FAIL(ObAIFuncJsonUtils::get_json_array(allocator, result_array))) {
LOG_WARN("Failed to get json array", K(ret));
} else if (OB_ISNULL(output_obj = static_cast<ObJsonObject *>(http_response->get_value("output")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("output_obj is null", K(ret));
} else if (OB_ISNULL(embeddings_array = static_cast<ObJsonArray *>(output_obj->get_value("embeddings")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("embeddings_array is null", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < embeddings_array->element_count(); ++i) {
if (OB_ISNULL(embedding_obj = static_cast<ObJsonObject *>(embeddings_array->get_value(i)))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("embedding_obj is null", K(ret));
} else if (OB_ISNULL(embedding_array = static_cast<ObJsonArray *>(embedding_obj->get_value("embedding")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("embedding_array is null", K(ret));
} else if (OB_FAIL(result_array->append(embedding_array))) {
LOG_WARN("Failed to append embedding array", K(ret));
......@@ -812,10 +812,10 @@ int ObDashscopeUtils::ObDashscopeRerank::parse_output(common::ObIAllocator &allo
ret = OB_INVALID_ARGUMENT;
LOG_WARN("http_response is null", K(ret));
} else if (OB_ISNULL(output_obj = static_cast<ObJsonObject *>(http_response->get_value("output")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("output_obj is null", K(ret));
} else if (OB_ISNULL(results_array = static_cast<ObJsonArray *>(output_obj->get_value("results")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("results_array is null", K(ret));
} else {
result = results_array;
......@@ -891,7 +891,7 @@ int ObSiliconflowUtils::ObSiliconflowRerank::parse_output(common::ObIAllocator &
ret = OB_INVALID_ARGUMENT;
LOG_WARN("http_response is null", K(ret));
} else if (OB_ISNULL(results_array = static_cast<ObJsonArray *>(http_response->get_value("results")))) {
ret = OB_ERR_UNEXPECTED;
ret = OB_INVALID_DATA;
LOG_WARN("results_array is null", K(ret));
} else {
result = results_array;
......@@ -1232,7 +1232,7 @@ int ObAIFuncUtils::get_complete_provider(ObIAllocator &allocator, const ObString
if (provider.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("provider is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "provider is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_function, provider is empty");
} else if (ob_provider_check(provider, ObAIFuncProviderUtils::OPENAI)
|| ob_provider_check(provider, ObAIFuncProviderUtils::ALIYUN)
|| ob_provider_check(provider, ObAIFuncProviderUtils::DEEPSEEK)
......@@ -1244,7 +1244,7 @@ int ObAIFuncUtils::get_complete_provider(ObIAllocator &allocator, const ObString
} else {
ret = OB_NOT_SUPPORTED;
LOG_WARN("this provider current not support", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "this provider current not support");
LOG_USER_ERROR(OB_NOT_SUPPORTED, "this provider current is");
}
if (OB_SUCC(ret) && OB_ISNULL(complete_provider)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
......@@ -1259,7 +1259,7 @@ int ObAIFuncUtils::get_embed_provider(ObIAllocator &allocator, const ObString &p
if (provider.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("provider is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "provider is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_function, provider is empty");
} else if (ob_provider_check(provider, ObAIFuncProviderUtils::OPENAI)
|| ob_provider_check(provider, ObAIFuncProviderUtils::ALIYUN)
|| ob_provider_check(provider, ObAIFuncProviderUtils::HUNYUAN)
......@@ -1270,7 +1270,7 @@ int ObAIFuncUtils::get_embed_provider(ObIAllocator &allocator, const ObString &p
} else {
ret = OB_NOT_SUPPORTED;
LOG_WARN("this provider current not support", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "this provider current not support");
LOG_USER_ERROR(OB_NOT_SUPPORTED, "this provider current is");
}
if (OB_SUCC(ret) && OB_ISNULL(embed_provider)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
......@@ -1285,7 +1285,7 @@ int ObAIFuncUtils::get_rerank_provider(ObIAllocator &allocator, const ObString &
if (provider.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("provider is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "provider is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_function, provider is empty");
} else if (ob_provider_check(provider, ObAIFuncProviderUtils::SILICONFLOW)) {
rerank_provider = OB_NEWx(ObSiliconflowUtils::ObSiliconflowRerank, &allocator);
} else if (ob_provider_check(provider, ObAIFuncProviderUtils::DASHSCOPE)) {
......@@ -1293,7 +1293,7 @@ int ObAIFuncUtils::get_rerank_provider(ObIAllocator &allocator, const ObString &
} else {
ret = OB_NOT_SUPPORTED;
LOG_WARN("this provider current not support", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "this provider current not support");
LOG_USER_ERROR(OB_NOT_SUPPORTED, "rerank support siliconflow and ailiyun-dashscope, this provider current is");
}
if (OB_SUCC(ret) && OB_ISNULL(rerank_provider)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
......@@ -1308,11 +1308,11 @@ int ObAIFuncUtils::check_info_type_completion(const ObAIFuncExprInfo *info)
if (OB_ISNULL(info)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info is null", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info is null");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, info is null");
} else if (!is_completion_type(info)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not completion", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not completion");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, info type is not completion");
}
return ret;
}
......@@ -1323,11 +1323,11 @@ int ObAIFuncUtils::check_info_type_dense_embedding(const ObAIFuncExprInfo *info)
if (OB_ISNULL(info)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info is null", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info is null");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, info is null");
} else if (!is_dense_embedding_type(info)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not dense embedding", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not dense embedding");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, info type is not dense embedding");
}
return ret;
}
......@@ -1338,11 +1338,11 @@ int ObAIFuncUtils::check_info_type_rerank(const ObAIFuncExprInfo *info)
if (OB_ISNULL(info)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info is null", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info is null");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_rerank, info is null");
} else if (!is_rerank_type(info)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not rerank", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not rerank");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_rerank, info type is not rerank");
}
return ret;
}
......@@ -1370,7 +1370,7 @@ int ObAIFuncUtils::get_ai_func_info(ObIAllocator &allocator, const ObString &mod
if (model_id.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("model_id is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "model_id is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_function, model_id is empty");
} else {
ObAIFuncExprInfo *info_obj = OB_NEWx(ObAIFuncExprInfo, (&allocator), allocator, T_FUN_SYS_AI_COMPLETE);
if (OB_ISNULL(info_obj)) {
......@@ -1506,7 +1506,7 @@ int ObAIFuncModel::call_completion(ObString &prompt, ObJsonObject *config, ObStr
if (!is_completion_type()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not completion", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not completion");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, info type is not completion");
} else if (OB_FAIL(ObAIFuncUtils::get_complete_provider(*allocator_, endpoint_info_.get_provider(), complete_provider))) {
LOG_WARN("Failed to get complete provider", K(ret));
} else if (OB_FAIL(endpoint_info_.get_unencrypted_access_key(*allocator_, unencrypted_access_key))) {
......@@ -1524,6 +1524,19 @@ int ObAIFuncModel::call_completion(ObString &prompt, ObJsonObject *config, ObStr
} else {
result = result_str;
}
if (ret == OB_INVALID_DATA) {
ObString response_str;
if (OB_SUCCESS == ObAIFuncJsonUtils::print_json_to_str(*allocator_, response, response_str)) {
char http_message_str[1024];
snprintf(http_message_str, sizeof(http_message_str), "unexpected http message: %s", response_str.ptr());
ObString ob_http_message_str(http_message_str);
LOG_WARN("unexpected http message", K(ret), K(ob_http_message_str));
FORWARD_USER_ERROR(ret, ob_http_message_str.ptr());
} else {
LOG_WARN("unexpected http message", K(ret));
FORWARD_USER_ERROR(ret, "unexpected http message");
}
}
return ret;
}
......@@ -1544,7 +1557,7 @@ int ObAIFuncModel::call_completion_vector(ObArray<ObString> &prompts, ObJsonObje
if (!is_completion_type()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not completion", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not completion");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, info type is not completion");
} else if (OB_FAIL(ObAIFuncUtils::get_complete_provider(*allocator_, endpoint_info_.get_provider(), complete_provider))) {
LOG_WARN("Failed to get complete provider", K(ret));
} else if (OB_FAIL(endpoint_info_.get_unencrypted_access_key(*allocator_, unencrypted_access_key))) {
......@@ -1589,11 +1602,11 @@ int ObAIFuncModel::call_dense_embedding(ObString &content, ObJsonObject *config,
if (content.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("content is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "input is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, input is empty");
} else if (!is_dense_embedding_type()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not dense embedding", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not dense embedding");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, info type is not dense embedding");
} else if (OB_FAIL(contents.push_back(content))) {
LOG_WARN("Failed to push back content", K(ret));
} else if (OB_FAIL(call_dense_embedding_vector_v2(contents, config, results))) {
......@@ -1622,7 +1635,7 @@ int ObAIFuncModel::call_dense_embedding_vector(ObArray<ObString> &contents, ObJs
if (!is_dense_embedding_type()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not dense embedding", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not dense embedding");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, info type is not dense embedding");
} else if (OB_FAIL(ObAIFuncUtils::get_embed_provider(*allocator_, endpoint_info_.get_provider(), embed_provider))) {
LOG_WARN("Failed to get embed provider", K(ret));
} else if (OB_FAIL(endpoint_info_.get_unencrypted_access_key(*allocator_, unencrypted_access_key))) {
......@@ -1691,7 +1704,7 @@ int ObAIFuncModel::call_dense_embedding_vector_v2(ObArray<ObString> &content, Ob
if (!is_dense_embedding_type()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not dense embedding", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not dense embedding");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, info type is not dense embedding");
} else if (OB_FAIL(ObAIFuncUtils::get_embed_provider(*allocator_, endpoint_info_.get_provider(), embed_provider))) {
LOG_WARN("Failed to get embed provider", K(ret));
} else if (OB_FAIL(endpoint_info_.get_unencrypted_access_key(*allocator_, unencrypted_access_key))) {
......@@ -1719,7 +1732,7 @@ int ObAIFuncModel::call_dense_embedding_vector_v2(ObArray<ObString> &content, Ob
} else if (dimension > 0 && static_cast<ObJsonArray *>(j_base)->element_count() != dimension) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("result array is not equal to dimension", K(ret), K(dimension), K(static_cast<ObJsonArray *>(j_base)->element_count()));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "result dimension is not equal to dimension");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, result dimension is not equal to dimension");
} else if (OB_FAIL(ObAIFuncJsonUtils::print_json_to_str(*allocator_, j_base, result_str))) {
LOG_WARN("Failed to print json to string", K(ret));
} else {
......@@ -1728,6 +1741,19 @@ int ObAIFuncModel::call_dense_embedding_vector_v2(ObArray<ObString> &content, Ob
}
}
}
if (ret == OB_INVALID_DATA) {
ObString response_str;
if (OB_SUCCESS == ObAIFuncJsonUtils::print_json_to_str(*allocator_, response, response_str)) {
char http_message_str[1024];
snprintf(http_message_str, sizeof(http_message_str), "unexpected http message: %s", response_str.ptr());
ObString ob_http_message_str(http_message_str);
LOG_WARN("unexpected http message", K(ret), K(ob_http_message_str));
FORWARD_USER_ERROR(ret, ob_http_message_str.ptr());
} else {
LOG_WARN("unexpected http message", K(ret));
FORWARD_USER_ERROR(ret, "unexpected http message");
}
}
return ret;
}
......@@ -1745,7 +1771,7 @@ int ObAIFuncModel::call_rerank(ObString &query, ObJsonArray *contents, ObJsonArr
if (!is_rerank_type()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("info type is not rerank", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "info type is not rerank");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_rerank, info type is not rerank");
} else if (OB_FAIL(ObAIFuncUtils::get_rerank_provider(*allocator_, endpoint_info_.get_provider(), rerank_provider))) {
LOG_WARN("Failed to get rerank provider", K(ret));
} else if (OB_FAIL(endpoint_info_.get_unencrypted_access_key(*allocator_, unencrypted_access_key))) {
......@@ -1761,6 +1787,20 @@ int ObAIFuncModel::call_rerank(ObString &query, ObJsonArray *contents, ObJsonArr
} else {
results = static_cast<ObJsonArray *>(result_base);
}
if (ret == OB_INVALID_DATA) {
ObString response_str;
if (OB_SUCCESS == ObAIFuncJsonUtils::print_json_to_str(*allocator_, response, response_str)) {
char http_message_str[1024];
snprintf(http_message_str, sizeof(http_message_str), "unexpected http message: %s", response_str.ptr());
ObString ob_http_message_str(http_message_str);
LOG_WARN("unexpected http message", K(ret), K(ob_http_message_str));
FORWARD_USER_ERROR(ret, ob_http_message_str.ptr());
} else {
LOG_WARN("unexpected http message", K(ret));
FORWARD_USER_ERROR(ret, "unexpected http message");
}
}
return ret;
}
......
......@@ -93,7 +93,7 @@ int ObExprAIComplete::eval_ai_complete(const ObExpr &expr,
} else if (arg_model_id->is_null() || arg_prompt->is_null()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("parameters is null", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "parameters is null");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, parameters is null");
res.set_null();
} else {
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
......@@ -125,12 +125,12 @@ int ObExprAIComplete::eval_ai_complete(const ObExpr &expr,
} else if (!ObAIFuncPromptObjectUtils::is_valid_prompt_object(prompt_object)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("prompt is not valid", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "prompt is not valid");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, prompt is not valid");
res.set_null();
} else if (!ObAIFuncJsonUtils::ob_is_json_array_all_str(static_cast<ObJsonArray *>(prompt_object->get_value(ObAIFuncPromptObjectUtils::prompt_args_key)))) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("prompt object is not support", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "prompt object is not support");
LOG_USER_ERROR(OB_NOT_SUPPORTED, "prompt object current is");
} else if (OB_FAIL(ObAIFuncPromptObjectUtils::replace_all_str_args_in_template(temp_allocator, prompt_object, prompt))) {
LOG_WARN("fail to replace all str args in template", K(ret));
}
......@@ -151,7 +151,7 @@ int ObExprAIComplete::eval_ai_complete(const ObExpr &expr,
} else if (model_id.empty() || prompt.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("model id or input is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "model id or input is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, model id or input is empty");
res.set_null();
}
......@@ -291,7 +291,7 @@ int ObExprAIComplete::get_vector_params(const ObExpr &expr,
} else if (prompt.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("input is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "input is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_complete, input is empty");
res_vec->set_null(idx);
} else if (OB_FAIL(prompts.push_back(prompt))) {
LOG_WARN("fail to push back prompt", K(ret), K(idx));
......
......@@ -61,7 +61,7 @@ int ObExprAIEmbed::calc_result_typeN(ObExprResType &type,
} else {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("dimension parameter must be an integer, not a decimal or float", K(ret), K(types_stack[DIM_IDX].get_type()));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "dimension parameter must be an integer, not a decimal or float");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, dimension parameter must be an integer, not a decimal or float");
}
}
type.set_varchar();
......@@ -83,7 +83,7 @@ int ObExprAIEmbed::eval_ai_embed(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &re
} else if (arg_model_id->is_null() || arg_content->is_null()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("model id or content is null", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "model id or content is null");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, model id or content is null");
res.set_null();
} else {
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
......@@ -99,7 +99,7 @@ int ObExprAIEmbed::eval_ai_embed(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &re
if (model_id.empty() || content.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("model id or input is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "model id or input is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, model id or input is empty");
res.set_null();
}
int64_t dim = 0;
......@@ -111,7 +111,7 @@ int ObExprAIEmbed::eval_ai_embed(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &re
if (dim <= 0) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("dimension parameter must be a positive integer", K(ret), K(dim));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "dimension parameter must be a positive integer");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, dimension parameter must be a positive integer");
res.set_null();
} else if (OB_FAIL(ObAIFuncJsonUtils::get_json_object(temp_allocator, config))) {
LOG_WARN("fail to get json object", K(ret));
......@@ -185,7 +185,7 @@ int ObExprAIEmbed::get_vector_params(const ObExpr &expr,
if (dim <= 0) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("dimension parameter must be a positive integer", K(ret), K(dim));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "dimension parameter must be a positive integer");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, dimension parameter must be a positive integer");
}
}
if (OB_SUCC(ret)) {
......@@ -206,7 +206,7 @@ int ObExprAIEmbed::get_vector_params(const ObExpr &expr,
} else if (content.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("input is empty", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "input is empty");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, input is empty");
} else if (OB_FAIL(contents.push_back(content))) {
LOG_WARN("fail to push back content", K(ret), K(idx));
}
......@@ -330,7 +330,7 @@ int ObExprAIEmbed::eval_ai_embed_vector(const ObExpr &expr, ObEvalCtx &ctx,
} else if (!ObAIFuncUtils::is_dense_embedding_type(info)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("model type must be DENSE_EMBEDDING", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "model type must be DENSE_EMBEDDING");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_embed, model type must be DENSE_EMBEDDING");
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < contents.count(); ++i) {
ObArray<ObString> contents_array;
......
......@@ -64,7 +64,7 @@ int ObExprAIPrompt::calc_result_typeN(ObExprResType &type,
} else if (ob_is_json(types_stack[i].get_type())) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("json type is not supported", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "json type is not supported");
LOG_USER_ERROR(OB_NOT_SUPPORTED, "json type current is");
} else {
ret = OB_ERR_INVALID_TYPE_FOR_OP;
LOG_WARN("invalid data type", K(ret), K(types_stack[i].get_type()));
......@@ -121,7 +121,7 @@ int ObExprAIPrompt::eval_ai_prompt(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &
} else if (ob_is_json(arg->datum_meta_.type_)) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("json type is not supported", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "json type is not supported");
LOG_USER_ERROR(OB_NOT_SUPPORTED, "json type current is");
} else if (datum->is_null()) {
ret = OB_ERR_INVALID_TYPE_FOR_OP;
LOG_WARN("invalid data type", K(ret), K(arg->datum_meta_.type_));
......
......@@ -54,11 +54,11 @@ int ObExprAIRerank::calc_result_typeN(ObExprResType &type,
if (!ob_is_string_tc(types_stack[MODEL_IDX].get_type())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid param type", K(ret), K(types_stack[MODEL_IDX]));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "model key must be string type");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_rerank, model key must be string type");
} else if (!ob_is_string_tc(types_stack[QUERY_IDX].get_type())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid param type", K(ret), K(types_stack[QUERY_IDX]));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "query must be string type");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_rerank, query must be string type");
} else {
types_stack[MODEL_IDX].set_calc_collation_type(CS_TYPE_UTF8MB4_BIN);
types_stack[QUERY_IDX].set_calc_collation_type(CS_TYPE_UTF8MB4_BIN);
......@@ -82,7 +82,7 @@ int ObExprAIRerank::calc_result_typeN(ObExprResType &type,
} else {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid param type", K(ret), K(types_stack[DOC_KEY_IDX]));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "doc key must be string type");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_rerank, doc key must be string type");
}
}
......@@ -106,7 +106,7 @@ int ObExprAIRerank::eval_ai_rerank(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &
} else if (arg_model_id->is_null() || arg_query->is_null() || arg_documents->is_null()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("model id or query or documents is null", K(ret));
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "model id or query or documents is null");
LOG_USER_ERROR(OB_INVALID_ARGUMENT, "ai_rerank, model id or query or documents is null");
res.set_null();
} else {
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
......
......@@ -177,7 +177,7 @@ TEST_F(ObOpenAIUtilsTest, test_complete_parse_output_empty)
ASSERT_EQ(OB_SUCCESS, ObJsonBaseFactory::get_json_base(&allocator, response, ObJsonInType::JSON_TREE, ObJsonInType::JSON_TREE, j_base));
ObJsonObject *http_response = static_cast<ObJsonObject *>(j_base);
ObIJsonBase *result = nullptr;
ASSERT_EQ(OB_ERR_UNEXPECTED, completion.parse_output(allocator, http_response, result));
ASSERT_EQ(OB_INVALID_DATA, completion.parse_output(allocator, http_response, result));
}
TEST_F(ObOpenAIUtilsTest, test_embedding_get_header)
......@@ -279,7 +279,7 @@ TEST_F(ObOpenAIUtilsTest, test_embedding_parse_output_empty)
ASSERT_EQ(OB_SUCCESS, ObJsonBaseFactory::get_json_base(&allocator, response, ObJsonInType::JSON_TREE, ObJsonInType::JSON_TREE, j_base));
ObJsonObject *http_response = static_cast<ObJsonObject *>(j_base);
ObIJsonBase *result = nullptr;
ASSERT_EQ(OB_ERR_UNEXPECTED, embedding.parse_output(allocator, http_response, result));
ASSERT_EQ(OB_INVALID_DATA, embedding.parse_output(allocator, http_response, result));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册