Yida Wu has posted comments on this change. ( http://gerrit.cloudera.org:8080/21493 )
Change subject: IMPALA-13131: Azure OpenAI API expects 'api-key' instead of 'Authorization' in the request header ...................................................................... Patch Set 5: Code-Review+1 (2 comments) http://gerrit.cloudera.org:8080/#/c/21493/4/be/src/exprs/ai-functions-ir.cc File be/src/exprs/ai-functions-ir.cc: http://gerrit.cloudera.org:8080/#/c/21493/4/be/src/exprs/ai-functions-ir.cc@146 PS4, Line 146: StringVal AiFunctions::AiGenerateText(FunctionContext* ctx, const StringVal& endpoint, : const StringVal& prompt, const StringVal& model, : const StringVal& api_key_jceks_secret, const StringVal& params) { : std::string_view endpoint_sv(FLAGS_ai_endpoint); : // endpoint validation : if (endpoint.ptr != nullptr && endpoint.len != 0) { : endpoint_sv = std::string_view(reinterpret_cast<char*>(endpoint.ptr), endpoint.len); : // Simple validation for endpoint. It should start with https:// : if (!is_api_endpoint_valid(endpoint_sv)) { : LOG(ERROR) << "AI Generate Text: \ninvalid protocol: " << endpoint_sv; : return StringVal(AI_GENERATE_TXT_INVALID_PROTOCOL_ERROR.c_str()); : } : } : AI_PLATFORM platform = GetAiPlatformFromEndpoint(endpoint_sv); : switch(platform) { : case AI_PLATFORM::OPEN_AI: : return AiGenerateTextInternal<false, AI_PLATFORM::OPEN_AI>( : ctx, endpoint_sv, prompt, model, api_key_jceks_secret, params, false); : case AI_PLATFORM::AZURE_OPEN_AI: : return AiGenerateTextInternal<false, AI_PLATFORM::AZURE_OPEN_AI>( : ctx, endpoint_sv, prompt, model, api_key_jceks_secret, params, false); : default: : LOG(ERROR) << "AI Generate Text: \nunsupported endpoint: " << endpoint_sv; : return StringVal(AI_GENERATE_TXT_UNSUPPORTED_ENDPOINT_ERROR.c_str()); : } : } : : StringVal AiFunctions::AiGenerateTextDefault( : FunctionContext* ctx, const StringVal& prompt) { : AI_PLATFORM platform = GetAiPlatformFromEndpoint(FLAGS_ai_endpoint); : switch(platform) { : case AI_PLATFORM::OPEN_AI: : return AiGenerateTextInternal<true, AI_PLATFORM::OPEN_AI>(ctx, FLAGS_ai_endpoint, : prompt, NULL_STRINGVAL, NULL_STRINGVAL, NULL_STRINGVAL, false); : case AI_PLATFORM::AZURE_OPEN_AI: : return AiGenerateTextInternal<true, AI_PLATFORM::AZURE_OPEN_AI>(ctx, : FLAGS_ai_endpoint, prompt, NULL_STRINGVAL, NULL_STRINGVAL, NULL_STRINGVAL, : false); : default: : DCHECK(false) << "Default endpoint " << FLAGS_ai_endpoint << "must be supported"; : LOG(ERROR) << "AI Generate Text: \nunsupported endpoint: " << FLAGS_ai_endpoint; : return StringVal(AI_GENERATE_TXT_UNSUPPORTED_ENDPOINT_ERROR.c_str()); : } : } > We can't. Note that there is template specialization and so you can't move I see. How about using a template for use_fast_path? template <bool use_fast_path> StringVal AiFunctions::HandleAiGenerateText(FunctionContext* ctx, const StringVal& endpoint, const StringVal& prompt, const StringVal& model, const StringVal& api_key_jceks_secret, const StringVal& params) { std::string_view endpoint_sv(FLAGS_ai_endpoint); if (endpoint.ptr != nullptr && endpoint.len != 0) { endpoint_sv = std::string_view(reinterpret_cast<char*>(endpoint.ptr), endpoint.len); if (!is_api_endpoint_valid(endpoint_sv)) { LOG(ERROR) << "AI Generate Text: \ninvalid protocol: " << endpoint_sv; return StringVal(AI_GENERATE_TXT_INVALID_PROTOCOL_ERROR.c_str()); } } AI_PLATFORM platform = GetAiPlatformFromEndpoint(endpoint_sv); switch (platform) { case AI_PLATFORM::OPEN_AI: return AiGenerateTextInternal<use_fast_path, AI_PLATFORM::OPEN_AI>( ctx, endpoint_sv, prompt, model, api_key_jceks_secret, params, false); case AI_PLATFORM::AZURE_OPEN_AI: return AiGenerateTextInternal<use_fast_path, AI_PLATFORM::AZURE_OPEN_AI>( ctx, endpoint_sv, prompt, model, api_key_jceks_secret, params, false); default: LOG(ERROR) << "AI Generate Text: \nunsupported endpoint: " << endpoint_sv; if (use_fast_path) { DCHECK(false) << "Default endpoint " << FLAGS_ai_endpoint << "must be supported"; } return StringVal(AI_GENERATE_TXT_UNSUPPORTED_ENDPOINT_ERROR.c_str()); } } StringVal AiFunctions::AiGenerateText(FunctionContext* ctx, const StringVal& endpoint, const StringVal& prompt, const StringVal& model, const StringVal& api_key_jceks_secret, const StringVal& params) { return HandleAiGenerateText<false>(ctx, endpoint, prompt, model, api_key_jceks_secret, params); } StringVal AiFunctions::AiGenerateTextDefault( FunctionContext* ctx, const StringVal& prompt) { return HandleAiGenerateText<true>(ctx, StringVal(), prompt, NULL_STRINGVAL, NULL_STRINGVAL, NULL_STRINGVAL); } http://gerrit.cloudera.org:8080/#/c/21493/4/be/src/exprs/ai-functions.inline.h File be/src/exprs/ai-functions.inline.h: http://gerrit.cloudera.org:8080/#/c/21493/4/be/src/exprs/ai-functions.inline.h@79 PS4, Line 79: string api_key_secret( : reinterpret_cast<char*>(api_key_jceks_secret.ptr), api_key_jcek > I think I had a missing parenthesis somewhere so the original macro seems t That is great, thanks. -- To view, visit http://gerrit.cloudera.org:8080/21493 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-Project: Impala-ASF Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: If9cc07940ce355d511bcf0ee615ff31042d13eb5 Gerrit-Change-Number: 21493 Gerrit-PatchSet: 5 Gerrit-Owner: Abhishek Rawat <[email protected]> Gerrit-Reviewer: Abhishek Rawat <[email protected]> Gerrit-Reviewer: Impala Public Jenkins <[email protected]> Gerrit-Reviewer: Wenzhe Zhou <[email protected]> Gerrit-Reviewer: Yida Wu <[email protected]> Gerrit-Comment-Date: Tue, 11 Jun 2024 21:49:07 +0000 Gerrit-HasComments: Yes
