be/src/exprs/function/ai/ai_functions.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/FrontendService.h> |
21 | | #include <gen_cpp/PaloInternalService_types.h> |
22 | | #include <glog/logging.h> |
23 | | |
24 | | #include <algorithm> |
25 | | #include <cstdlib> |
26 | | #include <memory> |
27 | | #include <string> |
28 | | #include <type_traits> |
29 | | #include <utility> |
30 | | #include <vector> |
31 | | |
32 | | #include "common/config.h" |
33 | | #include "common/status.h" |
34 | | #include "core/column/column_array.h" |
35 | | #include "core/column/column_const.h" |
36 | | #include "core/column/column_nullable.h" |
37 | | #include "core/cow.h" |
38 | | #include "core/data_type/data_type_array.h" |
39 | | #include "core/data_type/data_type_nullable.h" |
40 | | #include "core/data_type/data_type_number.h" |
41 | | #include "core/data_type/define_primitive_type.h" |
42 | | #include "core/data_type/primitive_type.h" |
43 | | #include "exec/common/util.hpp" |
44 | | #include "exprs/function/ai/ai_adapter.h" |
45 | | #include "exprs/function/ai/ai_request_executor.h" |
46 | | #include "exprs/function/function.h" |
47 | | #include "runtime/query_context.h" |
48 | | #include "runtime/runtime_state.h" |
49 | | #include "util/defer_op.h" |
50 | | #include "util/string_util.h" |
51 | | #include "util/threadpool.h" |
52 | | #include "util/time.h" |
53 | | |
54 | | namespace doris { |
55 | | |
56 | | // Base class for AI-based functions |
57 | | template <typename Derived> |
58 | | class AIFunction : public IFunction { |
59 | | public: |
60 | 98 | static const char* batch_system_prompt(bool structured_batch) { |
61 | | // Cache both complete prompts per function. Requests only select an immutable string; |
62 | | // changing task wording does not depend on finding/replacing an exact sentence. |
63 | 98 | static const std::string structured_prompt = |
64 | 98 | std::string(Derived::system_prompt) + |
65 | 98 | " Return exactly one JSON object with a single field `results`, an array of " |
66 | 98 | "strings. The results array must have the same length and order as the input " |
67 | 98 | "array. Do not return input objects or indexes. Two-row output format example " |
68 | 98 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; |
69 | 98 | static const std::string legacy_prompt = |
70 | 98 | std::string(Derived::system_prompt) + |
71 | 98 | " Return exactly one JSON array of strings, with the same length and order as " |
72 | 98 | "the input array. Do not return input objects or indexes. Two-row output format " |
73 | 98 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; |
74 | 98 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); |
75 | 98 | } _ZN5doris10AIFunctionINS_16FunctionAIFilterEE19batch_system_promptEb Line | Count | Source | 60 | 5 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 5 | static const std::string structured_prompt = | 64 | 5 | std::string(Derived::system_prompt) + | 65 | 5 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 5 | "strings. The results array must have the same length and order as the input " | 67 | 5 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 5 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 5 | static const std::string legacy_prompt = | 70 | 5 | std::string(Derived::system_prompt) + | 71 | 5 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 5 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 5 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 5 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 5 | } |
_ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
_ZN5doris10AIFunctionINS_19FunctionAISentimentEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE19batch_system_promptEb Line | Count | Source | 60 | 61 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 61 | static const std::string structured_prompt = | 64 | 61 | std::string(Derived::system_prompt) + | 65 | 61 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 61 | "strings. The results array must have the same length and order as the input " | 67 | 61 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 61 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 61 | static const std::string legacy_prompt = | 70 | 61 | std::string(Derived::system_prompt) + | 71 | 61 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 61 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 61 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 61 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 61 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
_ZN5doris10AIFunctionINS_17FunctionAIExtractEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
_ZN5doris10AIFunctionINS_18FunctionAIGenerateEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
_ZN5doris10AIFunctionINS_14FunctionAIMaskEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
_ZN5doris10AIFunctionINS_20FunctionAISimilarityEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
_ZN5doris10AIFunctionINS_19FunctionAITranslateEE19batch_system_promptEb Line | Count | Source | 60 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 61 | | // Cache both complete prompts per function. Requests only select an immutable string; | 62 | | // changing task wording does not depend on finding/replacing an exact sentence. | 63 | 4 | static const std::string structured_prompt = | 64 | 4 | std::string(Derived::system_prompt) + | 65 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 66 | 4 | "strings. The results array must have the same length and order as the input " | 67 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 68 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 69 | 4 | static const std::string legacy_prompt = | 70 | 4 | std::string(Derived::system_prompt) + | 71 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 72 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 73 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 74 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 75 | 4 | } |
|
76 | | |
77 | 18 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }_ZNK5doris10AIFunctionINS_13FunctionEmbedEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 6 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 3 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_17FunctionAIExtractEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_14FunctionAIMaskEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_19FunctionAITranslateEE8get_nameB5cxx11Ev Line | Count | Source | 77 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
|
78 | | |
79 | | // If the user doesn't provide the first arg, `resource_name` |
80 | | // FE will add the `resource_name` to the arguments list using the Session Variable. |
81 | | // So the value here should be the maximum number that the function can accept. |
82 | 26 | size_t get_number_of_arguments() const override { |
83 | 26 | return assert_cast<const Derived&>(*this).number_of_arguments; |
84 | 26 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE23get_number_of_argumentsEv Line | Count | Source | 82 | 4 | size_t get_number_of_arguments() const override { | 83 | 4 | return assert_cast<const Derived&>(*this).number_of_arguments; | 84 | 4 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE23get_number_of_argumentsEv Line | Count | Source | 82 | 1 | size_t get_number_of_arguments() const override { | 83 | 1 | return assert_cast<const Derived&>(*this).number_of_arguments; | 84 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE23get_number_of_argumentsEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE23get_number_of_argumentsEv _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE23get_number_of_argumentsEv Line | Count | Source | 82 | 14 | size_t get_number_of_arguments() const override { | 83 | 14 | return assert_cast<const Derived&>(*this).number_of_arguments; | 84 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE23get_number_of_argumentsEv Line | Count | Source | 82 | 2 | size_t get_number_of_arguments() const override { | 83 | 2 | return assert_cast<const Derived&>(*this).number_of_arguments; | 84 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE23get_number_of_argumentsEv _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE23get_number_of_argumentsEv Line | Count | Source | 82 | 4 | size_t get_number_of_arguments() const override { | 83 | 4 | return assert_cast<const Derived&>(*this).number_of_arguments; | 84 | 4 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE23get_number_of_argumentsEv _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE23get_number_of_argumentsEv Line | Count | Source | 82 | 1 | size_t get_number_of_arguments() const override { | 83 | 1 | return assert_cast<const Derived&>(*this).number_of_arguments; | 84 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE23get_number_of_argumentsEv |
85 | | |
86 | 0 | bool is_blockable() const override { return true; }Unexecuted instantiation: _ZNK5doris10AIFunctionINS_13FunctionEmbedEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE12is_blockableEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12is_blockableEv |
87 | | |
88 | 43 | Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
89 | 43 | if (scope == FunctionContext::FunctionStateScope::THREAD_LOCAL) { |
90 | | // Release this execution context's cached clients. |
91 | 29 | context->set_function_state(scope, nullptr); |
92 | 29 | } |
93 | 43 | return Status::OK(); |
94 | 43 | } Unexecuted instantiation: _ZN5doris10AIFunctionINS_13FunctionEmbedEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_16FunctionAIFilterEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAISentimentEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE _ZN5doris10AIFunctionINS_19FunctionAISummarizeEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Line | Count | Source | 88 | 43 | Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { | 89 | 43 | if (scope == FunctionContext::FunctionStateScope::THREAD_LOCAL) { | 90 | | // Release this execution context's cached clients. | 91 | 29 | context->set_function_state(scope, nullptr); | 92 | 29 | } | 93 | 43 | return Status::OK(); | 94 | 43 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_18FunctionAIClassifyEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE |
95 | | |
96 | 52 | bool use_default_implementation_for_nulls() const final { return false; }_ZNK5doris10AIFunctionINS_13FunctionEmbedEE36use_default_implementation_for_nullsEv Line | Count | Source | 96 | 8 | bool use_default_implementation_for_nulls() const final { return false; } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE36use_default_implementation_for_nullsEv Line | Count | Source | 96 | 2 | bool use_default_implementation_for_nulls() const final { return false; } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE36use_default_implementation_for_nullsEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE36use_default_implementation_for_nullsEv _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE36use_default_implementation_for_nullsEv Line | Count | Source | 96 | 28 | bool use_default_implementation_for_nulls() const final { return false; } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE36use_default_implementation_for_nullsEv Line | Count | Source | 96 | 4 | bool use_default_implementation_for_nulls() const final { return false; } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE36use_default_implementation_for_nullsEv _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE36use_default_implementation_for_nullsEv Line | Count | Source | 96 | 8 | bool use_default_implementation_for_nulls() const final { return false; } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE36use_default_implementation_for_nullsEv _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE36use_default_implementation_for_nullsEv Line | Count | Source | 96 | 2 | bool use_default_implementation_for_nulls() const final { return false; } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE36use_default_implementation_for_nullsEv |
97 | | |
98 | 37 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { |
99 | 37 | bool has_nullable_argument = std::ranges::any_of( |
100 | 53 | arguments, [](const auto& argument) { return argument->is_nullable(); });_ZZNK5doris10AIFunctionINS_13FunctionEmbedEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 100 | 8 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
_ZZNK5doris10AIFunctionINS_16FunctionAIFilterEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 100 | 2 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_19FunctionAISentimentEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ _ZZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 100 | 28 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
_ZZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 100 | 6 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_17FunctionAIExtractEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ _ZZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 100 | 7 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_14FunctionAIMaskEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ _ZZNK5doris10AIFunctionINS_20FunctionAISimilarityEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 100 | 2 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_19FunctionAITranslateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ |
101 | 37 | DataTypePtr return_type = |
102 | 37 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); |
103 | 37 | return has_nullable_argument ? make_nullable(return_type) : return_type; |
104 | 37 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 5 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 5 | bool has_nullable_argument = std::ranges::any_of( | 100 | 5 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 5 | DataTypePtr return_type = | 102 | 5 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 5 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 5 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 2 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 2 | bool has_nullable_argument = std::ranges::any_of( | 100 | 2 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 2 | DataTypePtr return_type = | 102 | 2 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 2 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 2 | } |
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 1 | bool has_nullable_argument = std::ranges::any_of( | 100 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 1 | DataTypePtr return_type = | 102 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 1 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 1 | bool has_nullable_argument = std::ranges::any_of( | 100 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 1 | DataTypePtr return_type = | 102 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 1 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 15 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 15 | bool has_nullable_argument = std::ranges::any_of( | 100 | 15 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 15 | DataTypePtr return_type = | 102 | 15 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 15 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 15 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 3 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 3 | bool has_nullable_argument = std::ranges::any_of( | 100 | 3 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 3 | DataTypePtr return_type = | 102 | 3 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 3 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 3 | } |
_ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 1 | bool has_nullable_argument = std::ranges::any_of( | 100 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 1 | DataTypePtr return_type = | 102 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 1 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 5 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 5 | bool has_nullable_argument = std::ranges::any_of( | 100 | 5 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 5 | DataTypePtr return_type = | 102 | 5 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 5 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 5 | } |
_ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 1 | bool has_nullable_argument = std::ranges::any_of( | 100 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 1 | DataTypePtr return_type = | 102 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 1 | } |
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 2 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 2 | bool has_nullable_argument = std::ranges::any_of( | 100 | 2 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 2 | DataTypePtr return_type = | 102 | 2 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 2 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 98 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 99 | 1 | bool has_nullable_argument = std::ranges::any_of( | 100 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 101 | 1 | DataTypePtr return_type = | 102 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 103 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 104 | 1 | } |
|
105 | | |
106 | | using PreparedFunctionImpl::execute; |
107 | | |
108 | | virtual Status build_prompt(const Columns& prompt_columns, size_t row_num, |
109 | 121 | std::string& prompt) const { |
110 | 121 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); |
111 | 121 | prompt = std::string(text_ref.data, text_ref.size); |
112 | | |
113 | 121 | return Status::OK(); |
114 | 121 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 109 | 25 | std::string& prompt) const { | 110 | 25 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 111 | 25 | prompt = std::string(text_ref.data, text_ref.size); | 112 | | | 113 | 25 | return Status::OK(); | 114 | 25 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 109 | 65 | std::string& prompt) const { | 110 | 65 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 111 | 65 | prompt = std::string(text_ref.data, text_ref.size); | 112 | | | 113 | 65 | return Status::OK(); | 114 | 65 | } |
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 109 | 1 | std::string& prompt) const { | 110 | 1 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 111 | 1 | prompt = std::string(text_ref.data, text_ref.size); | 112 | | | 113 | 1 | return Status::OK(); | 114 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 109 | 5 | std::string& prompt) const { | 110 | 5 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 111 | 5 | prompt = std::string(text_ref.data, text_ref.size); | 112 | | | 113 | 5 | return Status::OK(); | 114 | 5 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 109 | 25 | std::string& prompt) const { | 110 | 25 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 111 | 25 | prompt = std::string(text_ref.data, text_ref.size); | 112 | | | 113 | 25 | return Status::OK(); | 114 | 25 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE |
115 | | |
116 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
117 | 106 | uint32_t result, size_t input_rows_count) const override { |
118 | 106 | auto* executor = get_executor(context); |
119 | 106 | if (block.get_by_position(arguments[0]).column->only_null()) { |
120 | 1 | if (executor->statistics()) { |
121 | 1 | executor->statistics()->record_input(input_rows_count, input_rows_count); |
122 | 1 | } |
123 | 1 | block.get_by_position(result).column = |
124 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, |
125 | 1 | Field()); |
126 | 1 | return Status::OK(); |
127 | 1 | } |
128 | | |
129 | 105 | AIResource config; |
130 | 105 | std::shared_ptr<AIAdapter> adapter; |
131 | 105 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); |
132 | 105 | !status.ok()) { |
133 | 0 | return status; |
134 | 0 | } |
135 | | |
136 | 105 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, |
137 | 105 | input_rows_count, config, adapter); |
138 | 105 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 117 | 15 | uint32_t result, size_t input_rows_count) const override { | 118 | 15 | auto* executor = get_executor(context); | 119 | 15 | if (block.get_by_position(arguments[0]).column->only_null()) { | 120 | 0 | if (executor->statistics()) { | 121 | 0 | executor->statistics()->record_input(input_rows_count, input_rows_count); | 122 | 0 | } | 123 | 0 | block.get_by_position(result).column = | 124 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 125 | 0 | Field()); | 126 | 0 | return Status::OK(); | 127 | 0 | } | 128 | | | 129 | 15 | AIResource config; | 130 | 15 | std::shared_ptr<AIAdapter> adapter; | 131 | 15 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 132 | 15 | !status.ok()) { | 133 | 0 | return status; | 134 | 0 | } | 135 | | | 136 | 15 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 137 | 15 | input_rows_count, config, adapter); | 138 | 15 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 117 | 47 | uint32_t result, size_t input_rows_count) const override { | 118 | 47 | auto* executor = get_executor(context); | 119 | 47 | if (block.get_by_position(arguments[0]).column->only_null()) { | 120 | 0 | if (executor->statistics()) { | 121 | 0 | executor->statistics()->record_input(input_rows_count, input_rows_count); | 122 | 0 | } | 123 | 0 | block.get_by_position(result).column = | 124 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 125 | 0 | Field()); | 126 | 0 | return Status::OK(); | 127 | 0 | } | 128 | | | 129 | 47 | AIResource config; | 130 | 47 | std::shared_ptr<AIAdapter> adapter; | 131 | 47 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 132 | 47 | !status.ok()) { | 133 | 0 | return status; | 134 | 0 | } | 135 | | | 136 | 47 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 137 | 47 | input_rows_count, config, adapter); | 138 | 47 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 117 | 2 | uint32_t result, size_t input_rows_count) const override { | 118 | 2 | auto* executor = get_executor(context); | 119 | 2 | if (block.get_by_position(arguments[0]).column->only_null()) { | 120 | 0 | if (executor->statistics()) { | 121 | 0 | executor->statistics()->record_input(input_rows_count, input_rows_count); | 122 | 0 | } | 123 | 0 | block.get_by_position(result).column = | 124 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 125 | 0 | Field()); | 126 | 0 | return Status::OK(); | 127 | 0 | } | 128 | | | 129 | 2 | AIResource config; | 130 | 2 | std::shared_ptr<AIAdapter> adapter; | 131 | 2 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 132 | 2 | !status.ok()) { | 133 | 0 | return status; | 134 | 0 | } | 135 | | | 136 | 2 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 137 | 2 | input_rows_count, config, adapter); | 138 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 117 | 14 | uint32_t result, size_t input_rows_count) const override { | 118 | 14 | auto* executor = get_executor(context); | 119 | 14 | if (block.get_by_position(arguments[0]).column->only_null()) { | 120 | 0 | if (executor->statistics()) { | 121 | 0 | executor->statistics()->record_input(input_rows_count, input_rows_count); | 122 | 0 | } | 123 | 0 | block.get_by_position(result).column = | 124 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 125 | 0 | Field()); | 126 | 0 | return Status::OK(); | 127 | 0 | } | 128 | | | 129 | 14 | AIResource config; | 130 | 14 | std::shared_ptr<AIAdapter> adapter; | 131 | 14 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 132 | 14 | !status.ok()) { | 133 | 0 | return status; | 134 | 0 | } | 135 | | | 136 | 14 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 137 | 14 | input_rows_count, config, adapter); | 138 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 117 | 2 | uint32_t result, size_t input_rows_count) const override { | 118 | 2 | auto* executor = get_executor(context); | 119 | 2 | if (block.get_by_position(arguments[0]).column->only_null()) { | 120 | 0 | if (executor->statistics()) { | 121 | 0 | executor->statistics()->record_input(input_rows_count, input_rows_count); | 122 | 0 | } | 123 | 0 | block.get_by_position(result).column = | 124 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 125 | 0 | Field()); | 126 | 0 | return Status::OK(); | 127 | 0 | } | 128 | | | 129 | 2 | AIResource config; | 130 | 2 | std::shared_ptr<AIAdapter> adapter; | 131 | 2 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 132 | 2 | !status.ok()) { | 133 | 0 | return status; | 134 | 0 | } | 135 | | | 136 | 2 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 137 | 2 | input_rows_count, config, adapter); | 138 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 117 | 4 | uint32_t result, size_t input_rows_count) const override { | 118 | 4 | auto* executor = get_executor(context); | 119 | 4 | if (block.get_by_position(arguments[0]).column->only_null()) { | 120 | 1 | if (executor->statistics()) { | 121 | 1 | executor->statistics()->record_input(input_rows_count, input_rows_count); | 122 | 1 | } | 123 | 1 | block.get_by_position(result).column = | 124 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, | 125 | 1 | Field()); | 126 | 1 | return Status::OK(); | 127 | 1 | } | 128 | | | 129 | 3 | AIResource config; | 130 | 3 | std::shared_ptr<AIAdapter> adapter; | 131 | 3 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 132 | 3 | !status.ok()) { | 133 | 0 | return status; | 134 | 0 | } | 135 | | | 136 | 3 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 137 | 3 | input_rows_count, config, adapter); | 138 | 3 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 117 | 22 | uint32_t result, size_t input_rows_count) const override { | 118 | 22 | auto* executor = get_executor(context); | 119 | 22 | if (block.get_by_position(arguments[0]).column->only_null()) { | 120 | 0 | if (executor->statistics()) { | 121 | 0 | executor->statistics()->record_input(input_rows_count, input_rows_count); | 122 | 0 | } | 123 | 0 | block.get_by_position(result).column = | 124 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 125 | 0 | Field()); | 126 | 0 | return Status::OK(); | 127 | 0 | } | 128 | | | 129 | 22 | AIResource config; | 130 | 22 | std::shared_ptr<AIAdapter> adapter; | 131 | 22 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 132 | 22 | !status.ok()) { | 133 | 0 | return status; | 134 | 0 | } | 135 | | | 136 | 22 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 137 | 22 | input_rows_count, config, adapter); | 138 | 22 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm |
139 | | |
140 | | protected: |
141 | | // Reads the shared AI context window size from query options. String AI batch functions and |
142 | | // ai_agg both use the same byte-based session variable so batching behavior stays consistent. |
143 | 105 | static int64_t get_ai_context_window_size(FunctionContext* context) { |
144 | 105 | DORIS_CHECK(context != nullptr); |
145 | 105 | QueryContext* query_ctx = context->state()->get_query_ctx(); |
146 | 105 | DORIS_CHECK(query_ctx != nullptr); |
147 | | |
148 | 105 | return query_ctx->query_options().ai_context_window_size; |
149 | 105 | } _ZN5doris10AIFunctionINS_13FunctionEmbedEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 143 | 11 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 144 | 11 | DORIS_CHECK(context != nullptr); | 145 | 11 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 146 | 11 | DORIS_CHECK(query_ctx != nullptr); | 147 | | | 148 | 11 | return query_ctx->query_options().ai_context_window_size; | 149 | 11 | } |
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 143 | 47 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 144 | 47 | DORIS_CHECK(context != nullptr); | 145 | 47 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 146 | 47 | DORIS_CHECK(query_ctx != nullptr); | 147 | | | 148 | 47 | return query_ctx->query_options().ai_context_window_size; | 149 | 47 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE26get_ai_context_window_sizeEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_19FunctionAISentimentEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 143 | 2 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 144 | 2 | DORIS_CHECK(context != nullptr); | 145 | 2 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 146 | 2 | DORIS_CHECK(query_ctx != nullptr); | 147 | | | 148 | 2 | return query_ctx->query_options().ai_context_window_size; | 149 | 2 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 143 | 19 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 144 | 19 | DORIS_CHECK(context != nullptr); | 145 | 19 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 146 | 19 | DORIS_CHECK(query_ctx != nullptr); | 147 | | | 148 | 19 | return query_ctx->query_options().ai_context_window_size; | 149 | 19 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 143 | 2 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 144 | 2 | DORIS_CHECK(context != nullptr); | 145 | 2 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 146 | 2 | DORIS_CHECK(query_ctx != nullptr); | 147 | | | 148 | 2 | return query_ctx->query_options().ai_context_window_size; | 149 | 2 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE26get_ai_context_window_sizeEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 143 | 2 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 144 | 2 | DORIS_CHECK(context != nullptr); | 145 | 2 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 146 | 2 | DORIS_CHECK(query_ctx != nullptr); | 147 | | | 148 | 2 | return query_ctx->query_options().ai_context_window_size; | 149 | 2 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE26get_ai_context_window_sizeEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 143 | 22 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 144 | 22 | DORIS_CHECK(context != nullptr); | 145 | 22 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 146 | 22 | DORIS_CHECK(query_ctx != nullptr); | 147 | | | 148 | 22 | return query_ctx->query_options().ai_context_window_size; | 149 | 22 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE26get_ai_context_window_sizeEPNS_15FunctionContextE |
150 | | |
151 | 25 | MutableColumnPtr create_result_column() const { return ColumnString::create(); }Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20create_result_columnEv _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20create_result_columnEv Line | Count | Source | 151 | 2 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20create_result_columnEv Line | Count | Source | 151 | 19 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20create_result_columnEv Line | Count | Source | 151 | 2 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20create_result_columnEv _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20create_result_columnEv Line | Count | Source | 151 | 2 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20create_result_columnEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20create_result_columnEv |
152 | | |
153 | | // Provider-reusable hook for AI functions(string) -> string. |
154 | | Status append_batch_results(const std::vector<std::string>& batch_results, |
155 | 30 | IColumn& col_result) const { |
156 | 30 | auto& string_col = assert_cast<ColumnString&>(col_result); |
157 | 35 | for (const auto& batch_result : batch_results) { |
158 | 35 | string_col.insert_data(batch_result.data(), batch_result.size()); |
159 | 35 | } |
160 | 30 | return Status::OK(); |
161 | 30 | } Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 155 | 2 | IColumn& col_result) const { | 156 | 2 | auto& string_col = assert_cast<ColumnString&>(col_result); | 157 | 4 | for (const auto& batch_result : batch_results) { | 158 | 4 | string_col.insert_data(batch_result.data(), batch_result.size()); | 159 | 4 | } | 160 | 2 | return Status::OK(); | 161 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 155 | 24 | IColumn& col_result) const { | 156 | 24 | auto& string_col = assert_cast<ColumnString&>(col_result); | 157 | 24 | for (const auto& batch_result : batch_results) { | 158 | 24 | string_col.insert_data(batch_result.data(), batch_result.size()); | 159 | 24 | } | 160 | 24 | return Status::OK(); | 161 | 24 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 155 | 2 | IColumn& col_result) const { | 156 | 2 | auto& string_col = assert_cast<ColumnString&>(col_result); | 157 | 2 | for (const auto& batch_result : batch_results) { | 158 | 2 | string_col.insert_data(batch_result.data(), batch_result.size()); | 159 | 2 | } | 160 | 2 | return Status::OK(); | 161 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 155 | 2 | IColumn& col_result) const { | 156 | 2 | auto& string_col = assert_cast<ColumnString&>(col_result); | 157 | 5 | for (const auto& batch_result : batch_results) { | 158 | 5 | string_col.insert_data(batch_result.data(), batch_result.size()); | 159 | 5 | } | 160 | 2 | return Status::OK(); | 161 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE |
162 | | |
163 | 112 | static void normalize_endpoint(AIResource& config) { |
164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append |
165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` |
166 | | // for other AI scalar functions. |
167 | | // 2. `:embedContent` -> `:batchEmbedContents` |
168 | 112 | if (iequal(config.provider_type, "GEMINI")) { |
169 | 4 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { |
170 | 1 | static constexpr std::string_view legacy_suffix = ":embedContent"; |
171 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), |
172 | 1 | legacy_suffix.size(), ":batchEmbedContents"); |
173 | 1 | return; |
174 | 1 | } |
175 | | |
176 | 3 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { |
177 | 1 | return; |
178 | 1 | } |
179 | | |
180 | 2 | std::string model_name = config.model_name; |
181 | 2 | if (!model_name.starts_with("models/")) { |
182 | 2 | model_name = "models/" + model_name; |
183 | 2 | } |
184 | | |
185 | 2 | config.endpoint += "/"; |
186 | 2 | config.endpoint += model_name; |
187 | 2 | config.endpoint += |
188 | 2 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; |
189 | 2 | return; |
190 | 3 | } |
191 | | |
192 | | // The endpoint `v1/completions` does not support `system_prompt`. |
193 | | // To ensure a clear structure and stable AI results. |
194 | | // Convert from `v1/completions` to `v1/chat/completions` |
195 | 108 | if (config.endpoint.ends_with("v1/completions")) { |
196 | 1 | static constexpr std::string_view legacy_suffix = "v1/completions"; |
197 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), |
198 | 1 | legacy_suffix.size(), "v1/chat/completions"); |
199 | 1 | } |
200 | 108 | } _ZN5doris10AIFunctionINS_13FunctionEmbedEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 163 | 17 | static void normalize_endpoint(AIResource& config) { | 164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 166 | | // for other AI scalar functions. | 167 | | // 2. `:embedContent` -> `:batchEmbedContents` | 168 | 17 | if (iequal(config.provider_type, "GEMINI")) { | 169 | 2 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 170 | 1 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 171 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 172 | 1 | legacy_suffix.size(), ":batchEmbedContents"); | 173 | 1 | return; | 174 | 1 | } | 175 | | | 176 | 1 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 177 | 0 | return; | 178 | 0 | } | 179 | | | 180 | 1 | std::string model_name = config.model_name; | 181 | 1 | if (!model_name.starts_with("models/")) { | 182 | 1 | model_name = "models/" + model_name; | 183 | 1 | } | 184 | | | 185 | 1 | config.endpoint += "/"; | 186 | 1 | config.endpoint += model_name; | 187 | 1 | config.endpoint += | 188 | 1 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 189 | 1 | return; | 190 | 1 | } | 191 | | | 192 | | // The endpoint `v1/completions` does not support `system_prompt`. | 193 | | // To ensure a clear structure and stable AI results. | 194 | | // Convert from `v1/completions` to `v1/chat/completions` | 195 | 15 | if (config.endpoint.ends_with("v1/completions")) { | 196 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 197 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 198 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 199 | 0 | } | 200 | 15 | } |
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 163 | 47 | static void normalize_endpoint(AIResource& config) { | 164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 166 | | // for other AI scalar functions. | 167 | | // 2. `:embedContent` -> `:batchEmbedContents` | 168 | 47 | if (iequal(config.provider_type, "GEMINI")) { | 169 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 170 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 171 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 172 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 173 | 0 | return; | 174 | 0 | } | 175 | | | 176 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 177 | 0 | return; | 178 | 0 | } | 179 | | | 180 | 0 | std::string model_name = config.model_name; | 181 | 0 | if (!model_name.starts_with("models/")) { | 182 | 0 | model_name = "models/" + model_name; | 183 | 0 | } | 184 | |
| 185 | 0 | config.endpoint += "/"; | 186 | 0 | config.endpoint += model_name; | 187 | 0 | config.endpoint += | 188 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 189 | 0 | return; | 190 | 0 | } | 191 | | | 192 | | // The endpoint `v1/completions` does not support `system_prompt`. | 193 | | // To ensure a clear structure and stable AI results. | 194 | | // Convert from `v1/completions` to `v1/chat/completions` | 195 | 47 | if (config.endpoint.ends_with("v1/completions")) { | 196 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 197 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 198 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 199 | 0 | } | 200 | 47 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE18normalize_endpointERNS_10AIResourceE _ZN5doris10AIFunctionINS_19FunctionAISentimentEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 163 | 7 | static void normalize_endpoint(AIResource& config) { | 164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 166 | | // for other AI scalar functions. | 167 | | // 2. `:embedContent` -> `:batchEmbedContents` | 168 | 7 | if (iequal(config.provider_type, "GEMINI")) { | 169 | 2 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 170 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 171 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 172 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 173 | 0 | return; | 174 | 0 | } | 175 | | | 176 | 2 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 177 | 1 | return; | 178 | 1 | } | 179 | | | 180 | 1 | std::string model_name = config.model_name; | 181 | 1 | if (!model_name.starts_with("models/")) { | 182 | 1 | model_name = "models/" + model_name; | 183 | 1 | } | 184 | | | 185 | 1 | config.endpoint += "/"; | 186 | 1 | config.endpoint += model_name; | 187 | 1 | config.endpoint += | 188 | 1 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 189 | 1 | return; | 190 | 2 | } | 191 | | | 192 | | // The endpoint `v1/completions` does not support `system_prompt`. | 193 | | // To ensure a clear structure and stable AI results. | 194 | | // Convert from `v1/completions` to `v1/chat/completions` | 195 | 5 | if (config.endpoint.ends_with("v1/completions")) { | 196 | 1 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 197 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 198 | 1 | legacy_suffix.size(), "v1/chat/completions"); | 199 | 1 | } | 200 | 5 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 163 | 14 | static void normalize_endpoint(AIResource& config) { | 164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 166 | | // for other AI scalar functions. | 167 | | // 2. `:embedContent` -> `:batchEmbedContents` | 168 | 14 | if (iequal(config.provider_type, "GEMINI")) { | 169 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 170 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 171 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 172 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 173 | 0 | return; | 174 | 0 | } | 175 | | | 176 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 177 | 0 | return; | 178 | 0 | } | 179 | | | 180 | 0 | std::string model_name = config.model_name; | 181 | 0 | if (!model_name.starts_with("models/")) { | 182 | 0 | model_name = "models/" + model_name; | 183 | 0 | } | 184 | |
| 185 | 0 | config.endpoint += "/"; | 186 | 0 | config.endpoint += model_name; | 187 | 0 | config.endpoint += | 188 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 189 | 0 | return; | 190 | 0 | } | 191 | | | 192 | | // The endpoint `v1/completions` does not support `system_prompt`. | 193 | | // To ensure a clear structure and stable AI results. | 194 | | // Convert from `v1/completions` to `v1/chat/completions` | 195 | 14 | if (config.endpoint.ends_with("v1/completions")) { | 196 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 197 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 198 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 199 | 0 | } | 200 | 14 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 163 | 2 | static void normalize_endpoint(AIResource& config) { | 164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 166 | | // for other AI scalar functions. | 167 | | // 2. `:embedContent` -> `:batchEmbedContents` | 168 | 2 | if (iequal(config.provider_type, "GEMINI")) { | 169 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 170 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 171 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 172 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 173 | 0 | return; | 174 | 0 | } | 175 | | | 176 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 177 | 0 | return; | 178 | 0 | } | 179 | | | 180 | 0 | std::string model_name = config.model_name; | 181 | 0 | if (!model_name.starts_with("models/")) { | 182 | 0 | model_name = "models/" + model_name; | 183 | 0 | } | 184 | |
| 185 | 0 | config.endpoint += "/"; | 186 | 0 | config.endpoint += model_name; | 187 | 0 | config.endpoint += | 188 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 189 | 0 | return; | 190 | 0 | } | 191 | | | 192 | | // The endpoint `v1/completions` does not support `system_prompt`. | 193 | | // To ensure a clear structure and stable AI results. | 194 | | // Convert from `v1/completions` to `v1/chat/completions` | 195 | 2 | if (config.endpoint.ends_with("v1/completions")) { | 196 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 197 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 198 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 199 | 0 | } | 200 | 2 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE18normalize_endpointERNS_10AIResourceE _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 163 | 3 | static void normalize_endpoint(AIResource& config) { | 164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 166 | | // for other AI scalar functions. | 167 | | // 2. `:embedContent` -> `:batchEmbedContents` | 168 | 3 | if (iequal(config.provider_type, "GEMINI")) { | 169 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 170 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 171 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 172 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 173 | 0 | return; | 174 | 0 | } | 175 | | | 176 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 177 | 0 | return; | 178 | 0 | } | 179 | | | 180 | 0 | std::string model_name = config.model_name; | 181 | 0 | if (!model_name.starts_with("models/")) { | 182 | 0 | model_name = "models/" + model_name; | 183 | 0 | } | 184 | |
| 185 | 0 | config.endpoint += "/"; | 186 | 0 | config.endpoint += model_name; | 187 | 0 | config.endpoint += | 188 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 189 | 0 | return; | 190 | 0 | } | 191 | | | 192 | | // The endpoint `v1/completions` does not support `system_prompt`. | 193 | | // To ensure a clear structure and stable AI results. | 194 | | // Convert from `v1/completions` to `v1/chat/completions` | 195 | 3 | if (config.endpoint.ends_with("v1/completions")) { | 196 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 197 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 198 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 199 | 0 | } | 200 | 3 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE18normalize_endpointERNS_10AIResourceE _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 163 | 22 | static void normalize_endpoint(AIResource& config) { | 164 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 165 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 166 | | // for other AI scalar functions. | 167 | | // 2. `:embedContent` -> `:batchEmbedContents` | 168 | 22 | if (iequal(config.provider_type, "GEMINI")) { | 169 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 170 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 171 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 172 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 173 | 0 | return; | 174 | 0 | } | 175 | | | 176 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 177 | 0 | return; | 178 | 0 | } | 179 | | | 180 | 0 | std::string model_name = config.model_name; | 181 | 0 | if (!model_name.starts_with("models/")) { | 182 | 0 | model_name = "models/" + model_name; | 183 | 0 | } | 184 | |
| 185 | 0 | config.endpoint += "/"; | 186 | 0 | config.endpoint += model_name; | 187 | 0 | config.endpoint += | 188 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 189 | 0 | return; | 190 | 0 | } | 191 | | | 192 | | // The endpoint `v1/completions` does not support `system_prompt`. | 193 | | // To ensure a clear structure and stable AI results. | 194 | | // Convert from `v1/completions` to `v1/chat/completions` | 195 | 22 | if (config.endpoint.ends_with("v1/completions")) { | 196 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 197 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 198 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 199 | 0 | } | 200 | 22 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE18normalize_endpointERNS_10AIResourceE |
201 | | |
202 | 539 | static AIRequestExecutor* get_executor(FunctionContext* context) { |
203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. |
204 | 539 | auto* executor = static_cast<AIRequestExecutor*>( |
205 | 539 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); |
206 | 539 | if (executor == nullptr) { |
207 | 73 | auto* runtime_state = context->state(); |
208 | | // Disabled profiles need the connection cache, but no statistics owner. |
209 | 73 | auto statistics = runtime_state->enable_profile() |
210 | 73 | ? runtime_state->get_query_ctx()->get_ai_statistics( |
211 | 12 | runtime_state->fragment_id()) |
212 | 73 | : nullptr; |
213 | 73 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); |
214 | 73 | executor = state.get(); |
215 | 73 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, |
216 | 73 | std::move(state)); |
217 | 73 | } |
218 | 539 | return executor; |
219 | 539 | } _ZN5doris10AIFunctionINS_13FunctionEmbedEE12get_executorEPNS_15FunctionContextE Line | Count | Source | 202 | 112 | static AIRequestExecutor* get_executor(FunctionContext* context) { | 203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. | 204 | 112 | auto* executor = static_cast<AIRequestExecutor*>( | 205 | 112 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 206 | 112 | if (executor == nullptr) { | 207 | 26 | auto* runtime_state = context->state(); | 208 | | // Disabled profiles need the connection cache, but no statistics owner. | 209 | 26 | auto statistics = runtime_state->enable_profile() | 210 | 26 | ? runtime_state->get_query_ctx()->get_ai_statistics( | 211 | 5 | runtime_state->fragment_id()) | 212 | 26 | : nullptr; | 213 | 26 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); | 214 | 26 | executor = state.get(); | 215 | 26 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 216 | 26 | std::move(state)); | 217 | 26 | } | 218 | 112 | return executor; | 219 | 112 | } |
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE12get_executorEPNS_15FunctionContextE Line | Count | Source | 202 | 190 | static AIRequestExecutor* get_executor(FunctionContext* context) { | 203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. | 204 | 190 | auto* executor = static_cast<AIRequestExecutor*>( | 205 | 190 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 206 | 190 | if (executor == nullptr) { | 207 | 13 | auto* runtime_state = context->state(); | 208 | | // Disabled profiles need the connection cache, but no statistics owner. | 209 | 13 | auto statistics = runtime_state->enable_profile() | 210 | 13 | ? runtime_state->get_query_ctx()->get_ai_statistics( | 211 | 0 | runtime_state->fragment_id()) | 212 | 13 | : nullptr; | 213 | 13 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); | 214 | 13 | executor = state.get(); | 215 | 13 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 216 | 13 | std::move(state)); | 217 | 13 | } | 218 | 190 | return executor; | 219 | 190 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE12get_executorEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_19FunctionAISentimentEE12get_executorEPNS_15FunctionContextE Line | Count | Source | 202 | 10 | static AIRequestExecutor* get_executor(FunctionContext* context) { | 203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. | 204 | 10 | auto* executor = static_cast<AIRequestExecutor*>( | 205 | 10 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 206 | 10 | if (executor == nullptr) { | 207 | 5 | auto* runtime_state = context->state(); | 208 | | // Disabled profiles need the connection cache, but no statistics owner. | 209 | 5 | auto statistics = runtime_state->enable_profile() | 210 | 5 | ? runtime_state->get_query_ctx()->get_ai_statistics( | 211 | 0 | runtime_state->fragment_id()) | 212 | 5 | : nullptr; | 213 | 5 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); | 214 | 5 | executor = state.get(); | 215 | 5 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 216 | 5 | std::move(state)); | 217 | 5 | } | 218 | 10 | return executor; | 219 | 10 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE12get_executorEPNS_15FunctionContextE Line | Count | Source | 202 | 120 | static AIRequestExecutor* get_executor(FunctionContext* context) { | 203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. | 204 | 120 | auto* executor = static_cast<AIRequestExecutor*>( | 205 | 120 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 206 | 120 | if (executor == nullptr) { | 207 | 18 | auto* runtime_state = context->state(); | 208 | | // Disabled profiles need the connection cache, but no statistics owner. | 209 | 18 | auto statistics = runtime_state->enable_profile() | 210 | 18 | ? runtime_state->get_query_ctx()->get_ai_statistics( | 211 | 3 | runtime_state->fragment_id()) | 212 | 18 | : nullptr; | 213 | 18 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); | 214 | 18 | executor = state.get(); | 215 | 18 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 216 | 18 | std::move(state)); | 217 | 18 | } | 218 | 120 | return executor; | 219 | 120 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE12get_executorEPNS_15FunctionContextE Line | Count | Source | 202 | 8 | static AIRequestExecutor* get_executor(FunctionContext* context) { | 203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. | 204 | 8 | auto* executor = static_cast<AIRequestExecutor*>( | 205 | 8 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 206 | 8 | if (executor == nullptr) { | 207 | 2 | auto* runtime_state = context->state(); | 208 | | // Disabled profiles need the connection cache, but no statistics owner. | 209 | 2 | auto statistics = runtime_state->enable_profile() | 210 | 2 | ? runtime_state->get_query_ctx()->get_ai_statistics( | 211 | 0 | runtime_state->fragment_id()) | 212 | 2 | : nullptr; | 213 | 2 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); | 214 | 2 | executor = state.get(); | 215 | 2 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 216 | 2 | std::move(state)); | 217 | 2 | } | 218 | 8 | return executor; | 219 | 8 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE12get_executorEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE12get_executorEPNS_15FunctionContextE Line | Count | Source | 202 | 11 | static AIRequestExecutor* get_executor(FunctionContext* context) { | 203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. | 204 | 11 | auto* executor = static_cast<AIRequestExecutor*>( | 205 | 11 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 206 | 11 | if (executor == nullptr) { | 207 | 4 | auto* runtime_state = context->state(); | 208 | | // Disabled profiles need the connection cache, but no statistics owner. | 209 | 4 | auto statistics = runtime_state->enable_profile() | 210 | 4 | ? runtime_state->get_query_ctx()->get_ai_statistics( | 211 | 2 | runtime_state->fragment_id()) | 212 | 4 | : nullptr; | 213 | 4 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); | 214 | 4 | executor = state.get(); | 215 | 4 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 216 | 4 | std::move(state)); | 217 | 4 | } | 218 | 11 | return executor; | 219 | 11 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE12get_executorEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE12get_executorEPNS_15FunctionContextE Line | Count | Source | 202 | 88 | static AIRequestExecutor* get_executor(FunctionContext* context) { | 203 | | // Retain the cache across batches/Blocks, including Blocks with only NULL inputs. | 204 | 88 | auto* executor = static_cast<AIRequestExecutor*>( | 205 | 88 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 206 | 88 | if (executor == nullptr) { | 207 | 5 | auto* runtime_state = context->state(); | 208 | | // Disabled profiles need the connection cache, but no statistics owner. | 209 | 5 | auto statistics = runtime_state->enable_profile() | 210 | 5 | ? runtime_state->get_query_ctx()->get_ai_statistics( | 211 | 2 | runtime_state->fragment_id()) | 212 | 5 | : nullptr; | 213 | 5 | auto state = std::make_shared<AIRequestExecutor>(std::move(statistics)); | 214 | 5 | executor = state.get(); | 215 | 5 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 216 | 5 | std::move(state)); | 217 | 5 | } | 218 | 88 | return executor; | 219 | 88 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE12get_executorEPNS_15FunctionContextE |
220 | | |
221 | | static void record_input(FunctionContext* context, size_t rows, |
222 | 124 | const ColumnUInt8::MutablePtr& null_map) { |
223 | 124 | if (const auto& statistics = get_executor(context)->statistics()) { |
224 | 27 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), |
225 | 16 | null_map->get_data().end(), |
226 | 49 | [](UInt8 value) { return value != 0; })_ZZN5doris10AIFunctionINS_13FunctionEmbedEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh Line | Count | Source | 226 | 27 | [](UInt8 value) { return value != 0; }) |
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_16FunctionAIFilterEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh Unexecuted instantiation: _ZZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh Unexecuted instantiation: _ZZN5doris10AIFunctionINS_19FunctionAISentimentEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh _ZZN5doris10AIFunctionINS_19FunctionAISummarizeEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh Line | Count | Source | 226 | 17 | [](UInt8 value) { return value != 0; }) |
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_18FunctionAIClassifyEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh Unexecuted instantiation: _ZZN5doris10AIFunctionINS_17FunctionAIExtractEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh _ZZN5doris10AIFunctionINS_18FunctionAIGenerateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh Line | Count | Source | 226 | 1 | [](UInt8 value) { return value != 0; }) |
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_14FunctionAIMaskEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh _ZZN5doris10AIFunctionINS_20FunctionAISimilarityEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh Line | Count | Source | 226 | 4 | [](UInt8 value) { return value != 0; }) |
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_19FunctionAITranslateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh |
227 | 27 | : 0; |
228 | 27 | statistics->record_input(rows, skipped); |
229 | 27 | } |
230 | 124 | } _ZN5doris10AIFunctionINS_13FunctionEmbedEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE Line | Count | Source | 222 | 28 | const ColumnUInt8::MutablePtr& null_map) { | 223 | 28 | if (const auto& statistics = get_executor(context)->statistics()) { | 224 | 13 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), | 225 | 8 | null_map->get_data().end(), | 226 | 8 | [](UInt8 value) { return value != 0; }) | 227 | 13 | : 0; | 228 | 13 | statistics->record_input(rows, skipped); | 229 | 13 | } | 230 | 28 | } |
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE Line | Count | Source | 222 | 47 | const ColumnUInt8::MutablePtr& null_map) { | 223 | 47 | if (const auto& statistics = get_executor(context)->statistics()) { | 224 | 0 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), | 225 | 0 | null_map->get_data().end(), | 226 | 0 | [](UInt8 value) { return value != 0; }) | 227 | 0 | : 0; | 228 | 0 | statistics->record_input(rows, skipped); | 229 | 0 | } | 230 | 47 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE _ZN5doris10AIFunctionINS_19FunctionAISentimentEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE Line | Count | Source | 222 | 2 | const ColumnUInt8::MutablePtr& null_map) { | 223 | 2 | if (const auto& statistics = get_executor(context)->statistics()) { | 224 | 0 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), | 225 | 0 | null_map->get_data().end(), | 226 | 0 | [](UInt8 value) { return value != 0; }) | 227 | 0 | : 0; | 228 | 0 | statistics->record_input(rows, skipped); | 229 | 0 | } | 230 | 2 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE Line | Count | Source | 222 | 20 | const ColumnUInt8::MutablePtr& null_map) { | 223 | 20 | if (const auto& statistics = get_executor(context)->statistics()) { | 224 | 6 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), | 225 | 6 | null_map->get_data().end(), | 226 | 6 | [](UInt8 value) { return value != 0; }) | 227 | 6 | : 0; | 228 | 6 | statistics->record_input(rows, skipped); | 229 | 6 | } | 230 | 20 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE Line | Count | Source | 222 | 2 | const ColumnUInt8::MutablePtr& null_map) { | 223 | 2 | if (const auto& statistics = get_executor(context)->statistics()) { | 224 | 0 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), | 225 | 0 | null_map->get_data().end(), | 226 | 0 | [](UInt8 value) { return value != 0; }) | 227 | 0 | : 0; | 228 | 0 | statistics->record_input(rows, skipped); | 229 | 0 | } | 230 | 2 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE Line | Count | Source | 222 | 3 | const ColumnUInt8::MutablePtr& null_map) { | 223 | 3 | if (const auto& statistics = get_executor(context)->statistics()) { | 224 | 1 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), | 225 | 1 | null_map->get_data().end(), | 226 | 1 | [](UInt8 value) { return value != 0; }) | 227 | 1 | : 0; | 228 | 1 | statistics->record_input(rows, skipped); | 229 | 1 | } | 230 | 3 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE Line | Count | Source | 222 | 22 | const ColumnUInt8::MutablePtr& null_map) { | 223 | 22 | if (const auto& statistics = get_executor(context)->statistics()) { | 224 | 7 | const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(), | 225 | 1 | null_map->get_data().end(), | 226 | 1 | [](UInt8 value) { return value != 0; }) | 227 | 7 | : 0; | 228 | 7 | statistics->record_input(rows, skipped); | 229 | 7 | } | 230 | 22 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE |
231 | | |
232 | | Status send_request_to_llm(const std::string& request_body, std::string& response, |
233 | | const AIResource& config, std::shared_ptr<AIAdapter>& adapter, |
234 | 74 | FunctionContext* context) const { |
235 | 74 | return get_executor(context)->execute(request_body, response, config, *adapter, |
236 | 74 | context->state()->get_query_ctx()); |
237 | 74 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Line | Count | Source | 234 | 37 | FunctionContext* context) const { | 235 | 37 | return get_executor(context)->execute(request_body, response, config, *adapter, | 236 | 37 | context->state()->get_query_ctx()); | 237 | 37 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Line | Count | Source | 234 | 3 | FunctionContext* context) const { | 235 | 3 | return get_executor(context)->execute(request_body, response, config, *adapter, | 236 | 3 | context->state()->get_query_ctx()); | 237 | 3 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Line | Count | Source | 234 | 34 | FunctionContext* context) const { | 235 | 34 | return get_executor(context)->execute(request_body, response, config, *adapter, | 236 | 34 | context->state()->get_query_ctx()); | 237 | 34 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE |
238 | | |
239 | | // Provider-reusable helper for string-returning functions. |
240 | | // Estimates one batch entry size using the raw prompt length plus the fixed JSON wrapper cost. |
241 | 124 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { |
242 | 124 | static constexpr size_t json_wrapper_size = 20; |
243 | 124 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; |
244 | 124 | } _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 241 | 64 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 242 | 64 | static constexpr size_t json_wrapper_size = 20; | 243 | 64 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 244 | 64 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 241 | 4 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 242 | 4 | static constexpr size_t json_wrapper_size = 20; | 243 | 4 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 244 | 4 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 241 | 24 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 242 | 24 | static constexpr size_t json_wrapper_size = 20; | 243 | 24 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 244 | 24 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 241 | 2 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 242 | 2 | static constexpr size_t json_wrapper_size = 20; | 243 | 2 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 244 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 241 | 5 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 242 | 5 | static constexpr size_t json_wrapper_size = 20; | 243 | 5 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 244 | 5 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 241 | 25 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 242 | 25 | static constexpr size_t json_wrapper_size = 20; | 243 | 25 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 244 | 25 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE |
245 | | |
246 | | // Provider-reusable helper for string-returning functions. |
247 | | // Executes one batch request and parses the provider result into one string per input row. |
248 | | Status execute_batch_request(const std::vector<std::string>& batch_prompts, |
249 | | std::vector<std::string>& results, const AIResource& config, |
250 | | std::shared_ptr<AIAdapter>& adapter, |
251 | 14 | FunctionContext* context) const { |
252 | | #ifdef BE_TEST |
253 | | const char* test_result = std::getenv("AI_TEST_RESULT"); |
254 | | if (test_result != nullptr) { |
255 | | const auto& statistics = get_executor(context)->statistics(); |
256 | | const auto parse_start = statistics ? MonotonicNanos() : 0; |
257 | | bool parse_failed = true; |
258 | | Defer record_parse([&] { |
259 | | if (statistics) { |
260 | | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); |
261 | | } |
262 | | }); |
263 | | std::vector<std::string> parsed_test_response; |
264 | | RETURN_IF_ERROR( |
265 | | adapter->parse_response(std::string(test_result), parsed_test_response)); |
266 | | if (parsed_test_response.empty()) { |
267 | | return Status::InternalError("AI returned empty result"); |
268 | | } |
269 | | if (parsed_test_response.size() != batch_prompts.size()) { |
270 | | return Status::RuntimeError( |
271 | | "Failed to parse {} batch result, expected {} items but got {}", get_name(), |
272 | | batch_prompts.size(), parsed_test_response.size()); |
273 | | } |
274 | | results = std::move(parsed_test_response); |
275 | | parse_failed = false; |
276 | | return Status::OK(); |
277 | | } |
278 | | if (config.provider_type == "MOCK") { |
279 | | results.clear(); |
280 | | results.reserve(batch_prompts.size()); |
281 | | for (const auto& prompt : batch_prompts) { |
282 | | results.emplace_back("this is a mock response. " + prompt); |
283 | | } |
284 | | return Status::OK(); |
285 | | } |
286 | | #endif |
287 | | |
288 | 14 | std::string batch_prompt; |
289 | 14 | RETURN_IF_ERROR(build_batch_prompt(batch_prompts, batch_prompt)); |
290 | | |
291 | 14 | std::vector<std::string> inputs = {batch_prompt}; |
292 | 14 | std::vector<std::string> parsed_response; |
293 | | |
294 | 14 | std::string request_body; |
295 | | // Disabling provider format constraints keeps batching and the output protocol intact. |
296 | 14 | RETURN_IF_ERROR(adapter->build_request_payload( |
297 | 14 | inputs, batch_system_prompt(adapter->supports_structured_batch()), request_body, |
298 | 14 | config.enable_structured_output && adapter->supports_structured_batch())); |
299 | | |
300 | 14 | std::string response; |
301 | 14 | RETURN_IF_ERROR(send_request_to_llm(request_body, response, config, adapter, context)); |
302 | 14 | const auto& statistics = get_executor(context)->statistics(); |
303 | 14 | const auto parse_start = statistics ? MonotonicNanos() : 0; |
304 | 14 | bool parse_failed = true; |
305 | 92 | Defer record_parse([&] { |
306 | 92 | if (statistics) { |
307 | 7 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); |
308 | 7 | } |
309 | 92 | }); _ZZNK5doris10AIFunctionINS_16FunctionAIFilterEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv Line | Count | Source | 305 | 51 | Defer record_parse([&] { | 306 | 51 | if (statistics) { | 307 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 308 | 0 | } | 309 | 51 | }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv _ZZNK5doris10AIFunctionINS_19FunctionAISentimentEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv Line | Count | Source | 305 | 1 | Defer record_parse([&] { | 306 | 1 | if (statistics) { | 307 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 308 | 0 | } | 309 | 1 | }); |
_ZZNK5doris10AIFunctionINS_19FunctionAISummarizeEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv Line | Count | Source | 305 | 14 | Defer record_parse([&] { | 306 | 14 | if (statistics) { | 307 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 308 | 0 | } | 309 | 14 | }); |
_ZZNK5doris10AIFunctionINS_18FunctionAIClassifyEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv Line | Count | Source | 305 | 2 | Defer record_parse([&] { | 306 | 2 | if (statistics) { | 307 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 308 | 0 | } | 309 | 2 | }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_17FunctionAIExtractEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv _ZZNK5doris10AIFunctionINS_18FunctionAIGenerateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv Line | Count | Source | 305 | 2 | Defer record_parse([&] { | 306 | 2 | if (statistics) { | 307 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 308 | 0 | } | 309 | 2 | }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_14FunctionAIMaskEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv _ZZNK5doris10AIFunctionINS_20FunctionAISimilarityEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv Line | Count | Source | 305 | 22 | Defer record_parse([&] { | 306 | 22 | if (statistics) { | 307 | 7 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 308 | 7 | } | 309 | 22 | }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_19FunctionAITranslateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv |
310 | 14 | RETURN_IF_ERROR(adapter->parse_batch_response(response, parsed_response)); |
311 | 14 | if (parsed_response.empty()) { |
312 | 0 | return Status::InternalError("AI returned empty result"); |
313 | 0 | } |
314 | 14 | if (parsed_response.size() != batch_prompts.size()) { |
315 | 0 | LOG(WARNING) << "AI batch result size mismatch, function=" << get_name() |
316 | 0 | << ", provider=" << config.provider_type << ", model=" << config.model_name |
317 | 0 | << ", expected_rows=" << batch_prompts.size() |
318 | 0 | << ", actual_rows=" << parsed_response.size() |
319 | 0 | << ", response_body=" << response; |
320 | 0 | return Status::RuntimeError( |
321 | 0 | "Failed to parse {} batch result, expected {} items but got {}", get_name(), |
322 | 0 | batch_prompts.size(), parsed_response.size()); |
323 | 0 | } |
324 | 14 | results = std::move(parsed_response); |
325 | 14 | parse_failed = false; |
326 | 14 | return Status::OK(); |
327 | 14 | } Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Line | Count | Source | 251 | 14 | FunctionContext* context) const { | 252 | | #ifdef BE_TEST | 253 | | const char* test_result = std::getenv("AI_TEST_RESULT"); | 254 | | if (test_result != nullptr) { | 255 | | const auto& statistics = get_executor(context)->statistics(); | 256 | | const auto parse_start = statistics ? MonotonicNanos() : 0; | 257 | | bool parse_failed = true; | 258 | | Defer record_parse([&] { | 259 | | if (statistics) { | 260 | | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 261 | | } | 262 | | }); | 263 | | std::vector<std::string> parsed_test_response; | 264 | | RETURN_IF_ERROR( | 265 | | adapter->parse_response(std::string(test_result), parsed_test_response)); | 266 | | if (parsed_test_response.empty()) { | 267 | | return Status::InternalError("AI returned empty result"); | 268 | | } | 269 | | if (parsed_test_response.size() != batch_prompts.size()) { | 270 | | return Status::RuntimeError( | 271 | | "Failed to parse {} batch result, expected {} items but got {}", get_name(), | 272 | | batch_prompts.size(), parsed_test_response.size()); | 273 | | } | 274 | | results = std::move(parsed_test_response); | 275 | | parse_failed = false; | 276 | | return Status::OK(); | 277 | | } | 278 | | if (config.provider_type == "MOCK") { | 279 | | results.clear(); | 280 | | results.reserve(batch_prompts.size()); | 281 | | for (const auto& prompt : batch_prompts) { | 282 | | results.emplace_back("this is a mock response. " + prompt); | 283 | | } | 284 | | return Status::OK(); | 285 | | } | 286 | | #endif | 287 | | | 288 | 14 | std::string batch_prompt; | 289 | 14 | RETURN_IF_ERROR(build_batch_prompt(batch_prompts, batch_prompt)); | 290 | | | 291 | 14 | std::vector<std::string> inputs = {batch_prompt}; | 292 | 14 | std::vector<std::string> parsed_response; | 293 | | | 294 | 14 | std::string request_body; | 295 | | // Disabling provider format constraints keeps batching and the output protocol intact. | 296 | 14 | RETURN_IF_ERROR(adapter->build_request_payload( | 297 | 14 | inputs, batch_system_prompt(adapter->supports_structured_batch()), request_body, | 298 | 14 | config.enable_structured_output && adapter->supports_structured_batch())); | 299 | | | 300 | 14 | std::string response; | 301 | 14 | RETURN_IF_ERROR(send_request_to_llm(request_body, response, config, adapter, context)); | 302 | 14 | const auto& statistics = get_executor(context)->statistics(); | 303 | 14 | const auto parse_start = statistics ? MonotonicNanos() : 0; | 304 | 14 | bool parse_failed = true; | 305 | 14 | Defer record_parse([&] { | 306 | 14 | if (statistics) { | 307 | 14 | statistics->record_parse(MonotonicNanos() - parse_start, parse_failed); | 308 | 14 | } | 309 | 14 | }); | 310 | 14 | RETURN_IF_ERROR(adapter->parse_batch_response(response, parsed_response)); | 311 | 14 | if (parsed_response.empty()) { | 312 | 0 | return Status::InternalError("AI returned empty result"); | 313 | 0 | } | 314 | 14 | if (parsed_response.size() != batch_prompts.size()) { | 315 | 0 | LOG(WARNING) << "AI batch result size mismatch, function=" << get_name() | 316 | 0 | << ", provider=" << config.provider_type << ", model=" << config.model_name | 317 | 0 | << ", expected_rows=" << batch_prompts.size() | 318 | 0 | << ", actual_rows=" << parsed_response.size() | 319 | 0 | << ", response_body=" << response; | 320 | 0 | return Status::RuntimeError( | 321 | 0 | "Failed to parse {} batch result, expected {} items but got {}", get_name(), | 322 | 0 | batch_prompts.size(), parsed_response.size()); | 323 | 0 | } | 324 | 14 | results = std::move(parsed_response); | 325 | 14 | parse_failed = false; | 326 | 14 | return Status::OK(); | 327 | 14 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE |
328 | | |
329 | | Status append_results_with_statistics(FunctionContext* context, |
330 | | const std::vector<std::string>& results, |
331 | 97 | IColumn& column) const { |
332 | 97 | const auto& statistics = get_executor(context)->statistics(); |
333 | 97 | const auto parse_start = statistics ? MonotonicNanos() : 0; |
334 | 97 | Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column); |
335 | 97 | if (statistics) { |
336 | 17 | statistics->record_parse(MonotonicNanos() - parse_start, !status.ok()); |
337 | 17 | } |
338 | 97 | return status; |
339 | 97 | } _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE Line | Count | Source | 331 | 45 | IColumn& column) const { | 332 | 45 | const auto& statistics = get_executor(context)->statistics(); | 333 | 45 | const auto parse_start = statistics ? MonotonicNanos() : 0; | 334 | 45 | Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column); | 335 | 45 | if (statistics) { | 336 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, !status.ok()); | 337 | 0 | } | 338 | 45 | return status; | 339 | 45 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE Line | Count | Source | 331 | 2 | IColumn& column) const { | 332 | 2 | const auto& statistics = get_executor(context)->statistics(); | 333 | 2 | const auto parse_start = statistics ? MonotonicNanos() : 0; | 334 | 2 | Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column); | 335 | 2 | if (statistics) { | 336 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, !status.ok()); | 337 | 0 | } | 338 | 2 | return status; | 339 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE Line | Count | Source | 331 | 24 | IColumn& column) const { | 332 | 24 | const auto& statistics = get_executor(context)->statistics(); | 333 | 24 | const auto parse_start = statistics ? MonotonicNanos() : 0; | 334 | 24 | Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column); | 335 | 24 | if (statistics) { | 336 | 10 | statistics->record_parse(MonotonicNanos() - parse_start, !status.ok()); | 337 | 10 | } | 338 | 24 | return status; | 339 | 24 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE Line | Count | Source | 331 | 2 | IColumn& column) const { | 332 | 2 | const auto& statistics = get_executor(context)->statistics(); | 333 | 2 | const auto parse_start = statistics ? MonotonicNanos() : 0; | 334 | 2 | Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column); | 335 | 2 | if (statistics) { | 336 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, !status.ok()); | 337 | 0 | } | 338 | 2 | return status; | 339 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE Line | Count | Source | 331 | 2 | IColumn& column) const { | 332 | 2 | const auto& statistics = get_executor(context)->statistics(); | 333 | 2 | const auto parse_start = statistics ? MonotonicNanos() : 0; | 334 | 2 | Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column); | 335 | 2 | if (statistics) { | 336 | 0 | statistics->record_parse(MonotonicNanos() - parse_start, !status.ok()); | 337 | 0 | } | 338 | 2 | return status; | 339 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE Line | Count | Source | 331 | 22 | IColumn& column) const { | 332 | 22 | const auto& statistics = get_executor(context)->statistics(); | 333 | 22 | const auto parse_start = statistics ? MonotonicNanos() : 0; | 334 | 22 | Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column); | 335 | 22 | if (statistics) { | 336 | 7 | statistics->record_parse(MonotonicNanos() - parse_start, !status.ok()); | 337 | 7 | } | 338 | 22 | return status; | 339 | 22 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE |
340 | | |
341 | | // Provider-reusable helper for string-returning functions. |
342 | | // Runs the common batch execution flow; derived classes only need to define how one batch of |
343 | | // string results is inserted into the final output column. |
344 | | Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
345 | | uint32_t result, size_t input_rows_count, const AIResource& config, |
346 | 96 | std::shared_ptr<AIAdapter>& adapter) const { |
347 | 96 | Columns prompt_columns; |
348 | 96 | prompt_columns.reserve(arguments.size() - 1); |
349 | 96 | ColumnUInt8::MutablePtr result_null_map; |
350 | 216 | for (size_t i = 1; i < arguments.size(); ++i) { |
351 | 120 | const auto& argument = block.get_by_position(arguments[i]); |
352 | 120 | if (argument.type->is_nullable()) { |
353 | 15 | const auto& [column, is_const] = unpack_if_const(argument.column); |
354 | 15 | const auto& nullable = |
355 | 15 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); |
356 | 15 | if (!result_null_map) { |
357 | 14 | result_null_map = ColumnUInt8::create(input_rows_count, 0); |
358 | 14 | } |
359 | 15 | VectorizedUtils::update_null_map(result_null_map->get_data(), |
360 | 15 | nullable.get_null_map_data(), is_const); |
361 | 15 | } |
362 | 120 | prompt_columns.emplace_back( |
363 | 120 | argument.unnest_nullable(argument.type->is_nullable() |
364 | 120 | ? argument.get_nullable_column_info() |
365 | 120 | : NullableColumnInfo {}, |
366 | 120 | false) |
367 | 120 | .column); |
368 | 120 | } |
369 | | |
370 | 96 | record_input(context, input_rows_count, result_null_map); |
371 | | |
372 | 96 | if (result_null_map && |
373 | 96 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { |
374 | 2 | block.get_by_position(result).column = |
375 | 2 | block.get_by_position(result).type->create_column_const(input_rows_count, |
376 | 2 | Field()); |
377 | 2 | return Status::OK(); |
378 | 2 | } |
379 | | |
380 | 94 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); |
381 | 94 | std::vector<std::string> batch_prompts; |
382 | 94 | size_t current_batch_size = 2; // [] |
383 | 94 | const size_t max_batch_prompt_size = |
384 | 94 | static_cast<size_t>(get_ai_context_window_size(context)); |
385 | 94 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; |
386 | | |
387 | 232 | for (size_t i = 0; i < input_rows_count; ++i) { |
388 | 138 | if (null_map && (*null_map)[i]) { |
389 | 14 | continue; |
390 | 14 | } |
391 | | |
392 | 124 | std::string prompt; |
393 | 124 | RETURN_IF_ERROR( |
394 | 124 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); |
395 | | |
396 | 124 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); |
397 | 124 | if (entry_size > max_batch_prompt_size) { |
398 | 14 | if (!batch_prompts.empty()) { |
399 | 1 | std::vector<std::string> batch_results; |
400 | 1 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, |
401 | 1 | config, adapter, context)); |
402 | 1 | RETURN_IF_ERROR( |
403 | 1 | append_results_with_statistics(context, batch_results, *col_result)); |
404 | 1 | batch_prompts.clear(); |
405 | 1 | current_batch_size = 2; |
406 | 1 | } |
407 | | |
408 | 14 | std::vector<std::string> single_prompts; |
409 | 14 | single_prompts.emplace_back(std::move(prompt)); |
410 | 14 | std::vector<std::string> single_results; |
411 | 14 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, |
412 | 14 | adapter, context)); |
413 | 14 | RETURN_IF_ERROR( |
414 | 14 | append_results_with_statistics(context, single_results, *col_result)); |
415 | 14 | continue; |
416 | 14 | } |
417 | | |
418 | 110 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); |
419 | 110 | if (!batch_prompts.empty() && |
420 | 110 | current_batch_size + additional_size > max_batch_prompt_size) { |
421 | 2 | std::vector<std::string> batch_results; |
422 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, |
423 | 2 | adapter, context)); |
424 | 2 | RETURN_IF_ERROR( |
425 | 2 | append_results_with_statistics(context, batch_results, *col_result)); |
426 | 2 | batch_prompts.clear(); |
427 | 2 | current_batch_size = 2; |
428 | 2 | additional_size = entry_size; |
429 | 2 | } |
430 | | |
431 | 110 | batch_prompts.emplace_back(std::move(prompt)); |
432 | 110 | current_batch_size += additional_size; |
433 | 110 | } |
434 | | |
435 | 94 | if (!batch_prompts.empty()) { |
436 | 86 | std::vector<std::string> batch_results; |
437 | 86 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, |
438 | 86 | adapter, context)); |
439 | 80 | RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result)); |
440 | 80 | } |
441 | | |
442 | 61 | if (!result_null_map) { |
443 | 49 | block.replace_by_position(result, std::move(col_result)); |
444 | 49 | return Status::OK(); |
445 | 49 | } |
446 | | |
447 | 12 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { |
448 | 3 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), |
449 | 3 | std::move(result_null_map))); |
450 | 3 | return Status::OK(); |
451 | 3 | } |
452 | | |
453 | 9 | auto nested_result = col_result->clone_empty(); |
454 | 9 | size_t result_row = 0; |
455 | 31 | for (UInt8 is_null : result_null_map->get_data()) { |
456 | 31 | if (is_null) { |
457 | 14 | nested_result->insert_default(); |
458 | 17 | } else { |
459 | 17 | nested_result->insert_from(*col_result, result_row++); |
460 | 17 | } |
461 | 31 | } |
462 | | |
463 | 9 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), |
464 | 9 | std::move(result_null_map))); |
465 | 9 | return Status::OK(); |
466 | 12 | } _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 346 | 47 | std::shared_ptr<AIAdapter>& adapter) const { | 347 | 47 | Columns prompt_columns; | 348 | 47 | prompt_columns.reserve(arguments.size() - 1); | 349 | 47 | ColumnUInt8::MutablePtr result_null_map; | 350 | 94 | for (size_t i = 1; i < arguments.size(); ++i) { | 351 | 47 | const auto& argument = block.get_by_position(arguments[i]); | 352 | 47 | if (argument.type->is_nullable()) { | 353 | 1 | const auto& [column, is_const] = unpack_if_const(argument.column); | 354 | 1 | const auto& nullable = | 355 | 1 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 356 | 1 | if (!result_null_map) { | 357 | 1 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 358 | 1 | } | 359 | 1 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 360 | 1 | nullable.get_null_map_data(), is_const); | 361 | 1 | } | 362 | 47 | prompt_columns.emplace_back( | 363 | 47 | argument.unnest_nullable(argument.type->is_nullable() | 364 | 47 | ? argument.get_nullable_column_info() | 365 | 47 | : NullableColumnInfo {}, | 366 | 47 | false) | 367 | 47 | .column); | 368 | 47 | } | 369 | | | 370 | 47 | record_input(context, input_rows_count, result_null_map); | 371 | | | 372 | 47 | if (result_null_map && | 373 | 47 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 374 | 0 | block.get_by_position(result).column = | 375 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 376 | 0 | Field()); | 377 | 0 | return Status::OK(); | 378 | 0 | } | 379 | | | 380 | 47 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 381 | 47 | std::vector<std::string> batch_prompts; | 382 | 47 | size_t current_batch_size = 2; // [] | 383 | 47 | const size_t max_batch_prompt_size = | 384 | 47 | static_cast<size_t>(get_ai_context_window_size(context)); | 385 | 47 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 386 | | | 387 | 113 | for (size_t i = 0; i < input_rows_count; ++i) { | 388 | 66 | if (null_map && (*null_map)[i]) { | 389 | 2 | continue; | 390 | 2 | } | 391 | | | 392 | 64 | std::string prompt; | 393 | 64 | RETURN_IF_ERROR( | 394 | 64 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 395 | | | 396 | 64 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 397 | 64 | if (entry_size > max_batch_prompt_size) { | 398 | 4 | if (!batch_prompts.empty()) { | 399 | 1 | std::vector<std::string> batch_results; | 400 | 1 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 401 | 1 | config, adapter, context)); | 402 | 1 | RETURN_IF_ERROR( | 403 | 1 | append_results_with_statistics(context, batch_results, *col_result)); | 404 | 1 | batch_prompts.clear(); | 405 | 1 | current_batch_size = 2; | 406 | 1 | } | 407 | | | 408 | 4 | std::vector<std::string> single_prompts; | 409 | 4 | single_prompts.emplace_back(std::move(prompt)); | 410 | 4 | std::vector<std::string> single_results; | 411 | 4 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 412 | 4 | adapter, context)); | 413 | 4 | RETURN_IF_ERROR( | 414 | 4 | append_results_with_statistics(context, single_results, *col_result)); | 415 | 4 | continue; | 416 | 4 | } | 417 | | | 418 | 60 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 419 | 60 | if (!batch_prompts.empty() && | 420 | 60 | current_batch_size + additional_size > max_batch_prompt_size) { | 421 | 2 | std::vector<std::string> batch_results; | 422 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 423 | 2 | adapter, context)); | 424 | 2 | RETURN_IF_ERROR( | 425 | 2 | append_results_with_statistics(context, batch_results, *col_result)); | 426 | 2 | batch_prompts.clear(); | 427 | 2 | current_batch_size = 2; | 428 | 2 | additional_size = entry_size; | 429 | 2 | } | 430 | | | 431 | 60 | batch_prompts.emplace_back(std::move(prompt)); | 432 | 60 | current_batch_size += additional_size; | 433 | 60 | } | 434 | | | 435 | 47 | if (!batch_prompts.empty()) { | 436 | 44 | std::vector<std::string> batch_results; | 437 | 44 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 438 | 44 | adapter, context)); | 439 | 38 | RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result)); | 440 | 38 | } | 441 | | | 442 | 20 | if (!result_null_map) { | 443 | 19 | block.replace_by_position(result, std::move(col_result)); | 444 | 19 | return Status::OK(); | 445 | 19 | } | 446 | | | 447 | 1 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 448 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 449 | 0 | std::move(result_null_map))); | 450 | 0 | return Status::OK(); | 451 | 0 | } | 452 | | | 453 | 1 | auto nested_result = col_result->clone_empty(); | 454 | 1 | size_t result_row = 0; | 455 | 4 | for (UInt8 is_null : result_null_map->get_data()) { | 456 | 4 | if (is_null) { | 457 | 2 | nested_result->insert_default(); | 458 | 2 | } else { | 459 | 2 | nested_result->insert_from(*col_result, result_row++); | 460 | 2 | } | 461 | 4 | } | 462 | | | 463 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 464 | 1 | std::move(result_null_map))); | 465 | 1 | return Status::OK(); | 466 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 346 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 347 | 2 | Columns prompt_columns; | 348 | 2 | prompt_columns.reserve(arguments.size() - 1); | 349 | 2 | ColumnUInt8::MutablePtr result_null_map; | 350 | 4 | for (size_t i = 1; i < arguments.size(); ++i) { | 351 | 2 | const auto& argument = block.get_by_position(arguments[i]); | 352 | 2 | if (argument.type->is_nullable()) { | 353 | 0 | const auto& [column, is_const] = unpack_if_const(argument.column); | 354 | 0 | const auto& nullable = | 355 | 0 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 356 | 0 | if (!result_null_map) { | 357 | 0 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 358 | 0 | } | 359 | 0 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 360 | 0 | nullable.get_null_map_data(), is_const); | 361 | 0 | } | 362 | 2 | prompt_columns.emplace_back( | 363 | 2 | argument.unnest_nullable(argument.type->is_nullable() | 364 | 2 | ? argument.get_nullable_column_info() | 365 | 2 | : NullableColumnInfo {}, | 366 | 2 | false) | 367 | 2 | .column); | 368 | 2 | } | 369 | | | 370 | 2 | record_input(context, input_rows_count, result_null_map); | 371 | | | 372 | 2 | if (result_null_map && | 373 | 2 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 374 | 0 | block.get_by_position(result).column = | 375 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 376 | 0 | Field()); | 377 | 0 | return Status::OK(); | 378 | 0 | } | 379 | | | 380 | 2 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 381 | 2 | std::vector<std::string> batch_prompts; | 382 | 2 | size_t current_batch_size = 2; // [] | 383 | 2 | const size_t max_batch_prompt_size = | 384 | 2 | static_cast<size_t>(get_ai_context_window_size(context)); | 385 | 2 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 386 | | | 387 | 6 | for (size_t i = 0; i < input_rows_count; ++i) { | 388 | 4 | if (null_map && (*null_map)[i]) { | 389 | 0 | continue; | 390 | 0 | } | 391 | | | 392 | 4 | std::string prompt; | 393 | 4 | RETURN_IF_ERROR( | 394 | 4 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 395 | | | 396 | 4 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 397 | 4 | if (entry_size > max_batch_prompt_size) { | 398 | 0 | if (!batch_prompts.empty()) { | 399 | 0 | std::vector<std::string> batch_results; | 400 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 401 | 0 | config, adapter, context)); | 402 | 0 | RETURN_IF_ERROR( | 403 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 404 | 0 | batch_prompts.clear(); | 405 | 0 | current_batch_size = 2; | 406 | 0 | } | 407 | | | 408 | 0 | std::vector<std::string> single_prompts; | 409 | 0 | single_prompts.emplace_back(std::move(prompt)); | 410 | 0 | std::vector<std::string> single_results; | 411 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 412 | 0 | adapter, context)); | 413 | 0 | RETURN_IF_ERROR( | 414 | 0 | append_results_with_statistics(context, single_results, *col_result)); | 415 | 0 | continue; | 416 | 0 | } | 417 | | | 418 | 4 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 419 | 4 | if (!batch_prompts.empty() && | 420 | 4 | current_batch_size + additional_size > max_batch_prompt_size) { | 421 | 0 | std::vector<std::string> batch_results; | 422 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 423 | 0 | adapter, context)); | 424 | 0 | RETURN_IF_ERROR( | 425 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 426 | 0 | batch_prompts.clear(); | 427 | 0 | current_batch_size = 2; | 428 | 0 | additional_size = entry_size; | 429 | 0 | } | 430 | | | 431 | 4 | batch_prompts.emplace_back(std::move(prompt)); | 432 | 4 | current_batch_size += additional_size; | 433 | 4 | } | 434 | | | 435 | 2 | if (!batch_prompts.empty()) { | 436 | 2 | std::vector<std::string> batch_results; | 437 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 438 | 2 | adapter, context)); | 439 | 2 | RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result)); | 440 | 2 | } | 441 | | | 442 | 2 | if (!result_null_map) { | 443 | 2 | block.replace_by_position(result, std::move(col_result)); | 444 | 2 | return Status::OK(); | 445 | 2 | } | 446 | | | 447 | 0 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 448 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 449 | 0 | std::move(result_null_map))); | 450 | 0 | return Status::OK(); | 451 | 0 | } | 452 | | | 453 | 0 | auto nested_result = col_result->clone_empty(); | 454 | 0 | size_t result_row = 0; | 455 | 0 | for (UInt8 is_null : result_null_map->get_data()) { | 456 | 0 | if (is_null) { | 457 | 0 | nested_result->insert_default(); | 458 | 0 | } else { | 459 | 0 | nested_result->insert_from(*col_result, result_row++); | 460 | 0 | } | 461 | 0 | } | 462 | |
| 463 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 464 | 0 | std::move(result_null_map))); | 465 | 0 | return Status::OK(); | 466 | 0 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 346 | 20 | std::shared_ptr<AIAdapter>& adapter) const { | 347 | 20 | Columns prompt_columns; | 348 | 20 | prompt_columns.reserve(arguments.size() - 1); | 349 | 20 | ColumnUInt8::MutablePtr result_null_map; | 350 | 40 | for (size_t i = 1; i < arguments.size(); ++i) { | 351 | 20 | const auto& argument = block.get_by_position(arguments[i]); | 352 | 20 | if (argument.type->is_nullable()) { | 353 | 8 | const auto& [column, is_const] = unpack_if_const(argument.column); | 354 | 8 | const auto& nullable = | 355 | 8 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 356 | 8 | if (!result_null_map) { | 357 | 8 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 358 | 8 | } | 359 | 8 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 360 | 8 | nullable.get_null_map_data(), is_const); | 361 | 8 | } | 362 | 20 | prompt_columns.emplace_back( | 363 | 20 | argument.unnest_nullable(argument.type->is_nullable() | 364 | 20 | ? argument.get_nullable_column_info() | 365 | 20 | : NullableColumnInfo {}, | 366 | 20 | false) | 367 | 20 | .column); | 368 | 20 | } | 369 | | | 370 | 20 | record_input(context, input_rows_count, result_null_map); | 371 | | | 372 | 20 | if (result_null_map && | 373 | 20 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 374 | 1 | block.get_by_position(result).column = | 375 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, | 376 | 1 | Field()); | 377 | 1 | return Status::OK(); | 378 | 1 | } | 379 | | | 380 | 19 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 381 | 19 | std::vector<std::string> batch_prompts; | 382 | 19 | size_t current_batch_size = 2; // [] | 383 | 19 | const size_t max_batch_prompt_size = | 384 | 19 | static_cast<size_t>(get_ai_context_window_size(context)); | 385 | 19 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 386 | | | 387 | 48 | for (size_t i = 0; i < input_rows_count; ++i) { | 388 | 29 | if (null_map && (*null_map)[i]) { | 389 | 5 | continue; | 390 | 5 | } | 391 | | | 392 | 24 | std::string prompt; | 393 | 24 | RETURN_IF_ERROR( | 394 | 24 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 395 | | | 396 | 24 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 397 | 24 | if (entry_size > max_batch_prompt_size) { | 398 | 10 | if (!batch_prompts.empty()) { | 399 | 0 | std::vector<std::string> batch_results; | 400 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 401 | 0 | config, adapter, context)); | 402 | 0 | RETURN_IF_ERROR( | 403 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 404 | 0 | batch_prompts.clear(); | 405 | 0 | current_batch_size = 2; | 406 | 0 | } | 407 | | | 408 | 10 | std::vector<std::string> single_prompts; | 409 | 10 | single_prompts.emplace_back(std::move(prompt)); | 410 | 10 | std::vector<std::string> single_results; | 411 | 10 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 412 | 10 | adapter, context)); | 413 | 10 | RETURN_IF_ERROR( | 414 | 10 | append_results_with_statistics(context, single_results, *col_result)); | 415 | 10 | continue; | 416 | 10 | } | 417 | | | 418 | 14 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 419 | 14 | if (!batch_prompts.empty() && | 420 | 14 | current_batch_size + additional_size > max_batch_prompt_size) { | 421 | 0 | std::vector<std::string> batch_results; | 422 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 423 | 0 | adapter, context)); | 424 | 0 | RETURN_IF_ERROR( | 425 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 426 | 0 | batch_prompts.clear(); | 427 | 0 | current_batch_size = 2; | 428 | 0 | additional_size = entry_size; | 429 | 0 | } | 430 | | | 431 | 14 | batch_prompts.emplace_back(std::move(prompt)); | 432 | 14 | current_batch_size += additional_size; | 433 | 14 | } | 434 | | | 435 | 19 | if (!batch_prompts.empty()) { | 436 | 14 | std::vector<std::string> batch_results; | 437 | 14 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 438 | 14 | adapter, context)); | 439 | 14 | RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result)); | 440 | 14 | } | 441 | | | 442 | 19 | if (!result_null_map) { | 443 | 12 | block.replace_by_position(result, std::move(col_result)); | 444 | 12 | return Status::OK(); | 445 | 12 | } | 446 | | | 447 | 7 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 448 | 2 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 449 | 2 | std::move(result_null_map))); | 450 | 2 | return Status::OK(); | 451 | 2 | } | 452 | | | 453 | 5 | auto nested_result = col_result->clone_empty(); | 454 | 5 | size_t result_row = 0; | 455 | 15 | for (UInt8 is_null : result_null_map->get_data()) { | 456 | 15 | if (is_null) { | 457 | 5 | nested_result->insert_default(); | 458 | 10 | } else { | 459 | 10 | nested_result->insert_from(*col_result, result_row++); | 460 | 10 | } | 461 | 15 | } | 462 | | | 463 | 5 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 464 | 5 | std::move(result_null_map))); | 465 | 5 | return Status::OK(); | 466 | 7 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 346 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 347 | 2 | Columns prompt_columns; | 348 | 2 | prompt_columns.reserve(arguments.size() - 1); | 349 | 2 | ColumnUInt8::MutablePtr result_null_map; | 350 | 6 | for (size_t i = 1; i < arguments.size(); ++i) { | 351 | 4 | const auto& argument = block.get_by_position(arguments[i]); | 352 | 4 | if (argument.type->is_nullable()) { | 353 | 1 | const auto& [column, is_const] = unpack_if_const(argument.column); | 354 | 1 | const auto& nullable = | 355 | 1 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 356 | 1 | if (!result_null_map) { | 357 | 1 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 358 | 1 | } | 359 | 1 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 360 | 1 | nullable.get_null_map_data(), is_const); | 361 | 1 | } | 362 | 4 | prompt_columns.emplace_back( | 363 | 4 | argument.unnest_nullable(argument.type->is_nullable() | 364 | 4 | ? argument.get_nullable_column_info() | 365 | 4 | : NullableColumnInfo {}, | 366 | 4 | false) | 367 | 4 | .column); | 368 | 4 | } | 369 | | | 370 | 2 | record_input(context, input_rows_count, result_null_map); | 371 | | | 372 | 2 | if (result_null_map && | 373 | 2 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 374 | 0 | block.get_by_position(result).column = | 375 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 376 | 0 | Field()); | 377 | 0 | return Status::OK(); | 378 | 0 | } | 379 | | | 380 | 2 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 381 | 2 | std::vector<std::string> batch_prompts; | 382 | 2 | size_t current_batch_size = 2; // [] | 383 | 2 | const size_t max_batch_prompt_size = | 384 | 2 | static_cast<size_t>(get_ai_context_window_size(context)); | 385 | 2 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 386 | | | 387 | 6 | for (size_t i = 0; i < input_rows_count; ++i) { | 388 | 4 | if (null_map && (*null_map)[i]) { | 389 | 2 | continue; | 390 | 2 | } | 391 | | | 392 | 2 | std::string prompt; | 393 | 2 | RETURN_IF_ERROR( | 394 | 2 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 395 | | | 396 | 2 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 397 | 2 | if (entry_size > max_batch_prompt_size) { | 398 | 0 | if (!batch_prompts.empty()) { | 399 | 0 | std::vector<std::string> batch_results; | 400 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 401 | 0 | config, adapter, context)); | 402 | 0 | RETURN_IF_ERROR( | 403 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 404 | 0 | batch_prompts.clear(); | 405 | 0 | current_batch_size = 2; | 406 | 0 | } | 407 | | | 408 | 0 | std::vector<std::string> single_prompts; | 409 | 0 | single_prompts.emplace_back(std::move(prompt)); | 410 | 0 | std::vector<std::string> single_results; | 411 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 412 | 0 | adapter, context)); | 413 | 0 | RETURN_IF_ERROR( | 414 | 0 | append_results_with_statistics(context, single_results, *col_result)); | 415 | 0 | continue; | 416 | 0 | } | 417 | | | 418 | 2 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 419 | 2 | if (!batch_prompts.empty() && | 420 | 2 | current_batch_size + additional_size > max_batch_prompt_size) { | 421 | 0 | std::vector<std::string> batch_results; | 422 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 423 | 0 | adapter, context)); | 424 | 0 | RETURN_IF_ERROR( | 425 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 426 | 0 | batch_prompts.clear(); | 427 | 0 | current_batch_size = 2; | 428 | 0 | additional_size = entry_size; | 429 | 0 | } | 430 | | | 431 | 2 | batch_prompts.emplace_back(std::move(prompt)); | 432 | 2 | current_batch_size += additional_size; | 433 | 2 | } | 434 | | | 435 | 2 | if (!batch_prompts.empty()) { | 436 | 2 | std::vector<std::string> batch_results; | 437 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 438 | 2 | adapter, context)); | 439 | 2 | RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result)); | 440 | 2 | } | 441 | | | 442 | 2 | if (!result_null_map) { | 443 | 1 | block.replace_by_position(result, std::move(col_result)); | 444 | 1 | return Status::OK(); | 445 | 1 | } | 446 | | | 447 | 1 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 448 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 449 | 0 | std::move(result_null_map))); | 450 | 0 | return Status::OK(); | 451 | 0 | } | 452 | | | 453 | 1 | auto nested_result = col_result->clone_empty(); | 454 | 1 | size_t result_row = 0; | 455 | 3 | for (UInt8 is_null : result_null_map->get_data()) { | 456 | 3 | if (is_null) { | 457 | 2 | nested_result->insert_default(); | 458 | 2 | } else { | 459 | 1 | nested_result->insert_from(*col_result, result_row++); | 460 | 1 | } | 461 | 3 | } | 462 | | | 463 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 464 | 1 | std::move(result_null_map))); | 465 | 1 | return Status::OK(); | 466 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 346 | 3 | std::shared_ptr<AIAdapter>& adapter) const { | 347 | 3 | Columns prompt_columns; | 348 | 3 | prompt_columns.reserve(arguments.size() - 1); | 349 | 3 | ColumnUInt8::MutablePtr result_null_map; | 350 | 6 | for (size_t i = 1; i < arguments.size(); ++i) { | 351 | 3 | const auto& argument = block.get_by_position(arguments[i]); | 352 | 3 | if (argument.type->is_nullable()) { | 353 | 3 | const auto& [column, is_const] = unpack_if_const(argument.column); | 354 | 3 | const auto& nullable = | 355 | 3 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 356 | 3 | if (!result_null_map) { | 357 | 3 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 358 | 3 | } | 359 | 3 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 360 | 3 | nullable.get_null_map_data(), is_const); | 361 | 3 | } | 362 | 3 | prompt_columns.emplace_back( | 363 | 3 | argument.unnest_nullable(argument.type->is_nullable() | 364 | 3 | ? argument.get_nullable_column_info() | 365 | 3 | : NullableColumnInfo {}, | 366 | 3 | false) | 367 | 3 | .column); | 368 | 3 | } | 369 | | | 370 | 3 | record_input(context, input_rows_count, result_null_map); | 371 | | | 372 | 3 | if (result_null_map && | 373 | 3 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 374 | 1 | block.get_by_position(result).column = | 375 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, | 376 | 1 | Field()); | 377 | 1 | return Status::OK(); | 378 | 1 | } | 379 | | | 380 | 2 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 381 | 2 | std::vector<std::string> batch_prompts; | 382 | 2 | size_t current_batch_size = 2; // [] | 383 | 2 | const size_t max_batch_prompt_size = | 384 | 2 | static_cast<size_t>(get_ai_context_window_size(context)); | 385 | 2 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 386 | | | 387 | 10 | for (size_t i = 0; i < input_rows_count; ++i) { | 388 | 8 | if (null_map && (*null_map)[i]) { | 389 | 3 | continue; | 390 | 3 | } | 391 | | | 392 | 5 | std::string prompt; | 393 | 5 | RETURN_IF_ERROR( | 394 | 5 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 395 | | | 396 | 5 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 397 | 5 | if (entry_size > max_batch_prompt_size) { | 398 | 0 | if (!batch_prompts.empty()) { | 399 | 0 | std::vector<std::string> batch_results; | 400 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 401 | 0 | config, adapter, context)); | 402 | 0 | RETURN_IF_ERROR( | 403 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 404 | 0 | batch_prompts.clear(); | 405 | 0 | current_batch_size = 2; | 406 | 0 | } | 407 | | | 408 | 0 | std::vector<std::string> single_prompts; | 409 | 0 | single_prompts.emplace_back(std::move(prompt)); | 410 | 0 | std::vector<std::string> single_results; | 411 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 412 | 0 | adapter, context)); | 413 | 0 | RETURN_IF_ERROR( | 414 | 0 | append_results_with_statistics(context, single_results, *col_result)); | 415 | 0 | continue; | 416 | 0 | } | 417 | | | 418 | 5 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 419 | 5 | if (!batch_prompts.empty() && | 420 | 5 | current_batch_size + additional_size > max_batch_prompt_size) { | 421 | 0 | std::vector<std::string> batch_results; | 422 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 423 | 0 | adapter, context)); | 424 | 0 | RETURN_IF_ERROR( | 425 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 426 | 0 | batch_prompts.clear(); | 427 | 0 | current_batch_size = 2; | 428 | 0 | additional_size = entry_size; | 429 | 0 | } | 430 | | | 431 | 5 | batch_prompts.emplace_back(std::move(prompt)); | 432 | 5 | current_batch_size += additional_size; | 433 | 5 | } | 434 | | | 435 | 2 | if (!batch_prompts.empty()) { | 436 | 2 | std::vector<std::string> batch_results; | 437 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 438 | 2 | adapter, context)); | 439 | 2 | RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result)); | 440 | 2 | } | 441 | | | 442 | 2 | if (!result_null_map) { | 443 | 0 | block.replace_by_position(result, std::move(col_result)); | 444 | 0 | return Status::OK(); | 445 | 0 | } | 446 | | | 447 | 2 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 448 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 449 | 1 | std::move(result_null_map))); | 450 | 1 | return Status::OK(); | 451 | 1 | } | 452 | | | 453 | 1 | auto nested_result = col_result->clone_empty(); | 454 | 1 | size_t result_row = 0; | 455 | 5 | for (UInt8 is_null : result_null_map->get_data()) { | 456 | 5 | if (is_null) { | 457 | 3 | nested_result->insert_default(); | 458 | 3 | } else { | 459 | 2 | nested_result->insert_from(*col_result, result_row++); | 460 | 2 | } | 461 | 5 | } | 462 | | | 463 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 464 | 1 | std::move(result_null_map))); | 465 | 1 | return Status::OK(); | 466 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 346 | 22 | std::shared_ptr<AIAdapter>& adapter) const { | 347 | 22 | Columns prompt_columns; | 348 | 22 | prompt_columns.reserve(arguments.size() - 1); | 349 | 22 | ColumnUInt8::MutablePtr result_null_map; | 350 | 66 | for (size_t i = 1; i < arguments.size(); ++i) { | 351 | 44 | const auto& argument = block.get_by_position(arguments[i]); | 352 | 44 | if (argument.type->is_nullable()) { | 353 | 2 | const auto& [column, is_const] = unpack_if_const(argument.column); | 354 | 2 | const auto& nullable = | 355 | 2 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 356 | 2 | if (!result_null_map) { | 357 | 1 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 358 | 1 | } | 359 | 2 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 360 | 2 | nullable.get_null_map_data(), is_const); | 361 | 2 | } | 362 | 44 | prompt_columns.emplace_back( | 363 | 44 | argument.unnest_nullable(argument.type->is_nullable() | 364 | 44 | ? argument.get_nullable_column_info() | 365 | 44 | : NullableColumnInfo {}, | 366 | 44 | false) | 367 | 44 | .column); | 368 | 44 | } | 369 | | | 370 | 22 | record_input(context, input_rows_count, result_null_map); | 371 | | | 372 | 22 | if (result_null_map && | 373 | 22 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 374 | 0 | block.get_by_position(result).column = | 375 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 376 | 0 | Field()); | 377 | 0 | return Status::OK(); | 378 | 0 | } | 379 | | | 380 | 22 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 381 | 22 | std::vector<std::string> batch_prompts; | 382 | 22 | size_t current_batch_size = 2; // [] | 383 | 22 | const size_t max_batch_prompt_size = | 384 | 22 | static_cast<size_t>(get_ai_context_window_size(context)); | 385 | 22 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 386 | | | 387 | 49 | for (size_t i = 0; i < input_rows_count; ++i) { | 388 | 27 | if (null_map && (*null_map)[i]) { | 389 | 2 | continue; | 390 | 2 | } | 391 | | | 392 | 25 | std::string prompt; | 393 | 25 | RETURN_IF_ERROR( | 394 | 25 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 395 | | | 396 | 25 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 397 | 25 | if (entry_size > max_batch_prompt_size) { | 398 | 0 | if (!batch_prompts.empty()) { | 399 | 0 | std::vector<std::string> batch_results; | 400 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 401 | 0 | config, adapter, context)); | 402 | 0 | RETURN_IF_ERROR( | 403 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 404 | 0 | batch_prompts.clear(); | 405 | 0 | current_batch_size = 2; | 406 | 0 | } | 407 | | | 408 | 0 | std::vector<std::string> single_prompts; | 409 | 0 | single_prompts.emplace_back(std::move(prompt)); | 410 | 0 | std::vector<std::string> single_results; | 411 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 412 | 0 | adapter, context)); | 413 | 0 | RETURN_IF_ERROR( | 414 | 0 | append_results_with_statistics(context, single_results, *col_result)); | 415 | 0 | continue; | 416 | 0 | } | 417 | | | 418 | 25 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 419 | 25 | if (!batch_prompts.empty() && | 420 | 25 | current_batch_size + additional_size > max_batch_prompt_size) { | 421 | 0 | std::vector<std::string> batch_results; | 422 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 423 | 0 | adapter, context)); | 424 | 0 | RETURN_IF_ERROR( | 425 | 0 | append_results_with_statistics(context, batch_results, *col_result)); | 426 | 0 | batch_prompts.clear(); | 427 | 0 | current_batch_size = 2; | 428 | 0 | additional_size = entry_size; | 429 | 0 | } | 430 | | | 431 | 25 | batch_prompts.emplace_back(std::move(prompt)); | 432 | 25 | current_batch_size += additional_size; | 433 | 25 | } | 434 | | | 435 | 22 | if (!batch_prompts.empty()) { | 436 | 22 | std::vector<std::string> batch_results; | 437 | 22 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 438 | 22 | adapter, context)); | 439 | 22 | RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result)); | 440 | 22 | } | 441 | | | 442 | 16 | if (!result_null_map) { | 443 | 15 | block.replace_by_position(result, std::move(col_result)); | 444 | 15 | return Status::OK(); | 445 | 15 | } | 446 | | | 447 | 1 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 448 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 449 | 0 | std::move(result_null_map))); | 450 | 0 | return Status::OK(); | 451 | 0 | } | 452 | | | 453 | 1 | auto nested_result = col_result->clone_empty(); | 454 | 1 | size_t result_row = 0; | 455 | 4 | for (UInt8 is_null : result_null_map->get_data()) { | 456 | 4 | if (is_null) { | 457 | 2 | nested_result->insert_default(); | 458 | 2 | } else { | 459 | 2 | nested_result->insert_from(*col_result, result_row++); | 460 | 2 | } | 461 | 4 | } | 462 | | | 463 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 464 | 1 | std::move(result_null_map))); | 465 | 1 | return Status::OK(); | 466 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE |
467 | | |
468 | | private: |
469 | | // The ai resource must be literal |
470 | | Status _init_from_resource(FunctionContext* context, const Block& block, |
471 | | const ColumnNumbers& arguments, AIResource& config, |
472 | 105 | std::shared_ptr<AIAdapter>& adapter) const { |
473 | 105 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); |
474 | 105 | StringRef resource_name_ref = resource_column.column->get_data_at(0); |
475 | 105 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); |
476 | | |
477 | 105 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = |
478 | 105 | context->state()->get_query_ctx()->get_ai_resources(); |
479 | 105 | DORIS_CHECK(ai_resources); |
480 | 105 | auto it = ai_resources->find(resource_name); |
481 | 105 | DORIS_CHECK(it != ai_resources->end()); |
482 | 105 | PrimitiveType input_type = INVALID_TYPE; |
483 | 105 | if (arguments.size() > 1) { |
484 | 104 | input_type = |
485 | 104 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); |
486 | 104 | } |
487 | 105 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); |
488 | | |
489 | 105 | normalize_endpoint(config); |
490 | | |
491 | 105 | adapter = AIAdapterFactory::create_adapter(config.provider_type); |
492 | 105 | DORIS_CHECK(adapter); |
493 | | |
494 | 105 | adapter->init(config); |
495 | 105 | return Status::OK(); |
496 | 105 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 472 | 15 | std::shared_ptr<AIAdapter>& adapter) const { | 473 | 15 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 474 | 15 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 475 | 15 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 476 | | | 477 | 15 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 478 | 15 | context->state()->get_query_ctx()->get_ai_resources(); | 479 | 15 | DORIS_CHECK(ai_resources); | 480 | 15 | auto it = ai_resources->find(resource_name); | 481 | 15 | DORIS_CHECK(it != ai_resources->end()); | 482 | 15 | PrimitiveType input_type = INVALID_TYPE; | 483 | 15 | if (arguments.size() > 1) { | 484 | 14 | input_type = | 485 | 14 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 486 | 14 | } | 487 | 15 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 488 | | | 489 | 15 | normalize_endpoint(config); | 490 | | | 491 | 15 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 492 | 15 | DORIS_CHECK(adapter); | 493 | | | 494 | 15 | adapter->init(config); | 495 | 15 | return Status::OK(); | 496 | 15 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 472 | 47 | std::shared_ptr<AIAdapter>& adapter) const { | 473 | 47 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 474 | 47 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 475 | 47 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 476 | | | 477 | 47 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 478 | 47 | context->state()->get_query_ctx()->get_ai_resources(); | 479 | 47 | DORIS_CHECK(ai_resources); | 480 | 47 | auto it = ai_resources->find(resource_name); | 481 | 47 | DORIS_CHECK(it != ai_resources->end()); | 482 | 47 | PrimitiveType input_type = INVALID_TYPE; | 483 | 47 | if (arguments.size() > 1) { | 484 | 47 | input_type = | 485 | 47 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 486 | 47 | } | 487 | 47 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 488 | | | 489 | 47 | normalize_endpoint(config); | 490 | | | 491 | 47 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 492 | 47 | DORIS_CHECK(adapter); | 493 | | | 494 | 47 | adapter->init(config); | 495 | 47 | return Status::OK(); | 496 | 47 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 472 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 473 | 2 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 474 | 2 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 475 | 2 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 476 | | | 477 | 2 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 478 | 2 | context->state()->get_query_ctx()->get_ai_resources(); | 479 | 2 | DORIS_CHECK(ai_resources); | 480 | 2 | auto it = ai_resources->find(resource_name); | 481 | 2 | DORIS_CHECK(it != ai_resources->end()); | 482 | 2 | PrimitiveType input_type = INVALID_TYPE; | 483 | 2 | if (arguments.size() > 1) { | 484 | 2 | input_type = | 485 | 2 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 486 | 2 | } | 487 | 2 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 488 | | | 489 | 2 | normalize_endpoint(config); | 490 | | | 491 | 2 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 492 | 2 | DORIS_CHECK(adapter); | 493 | | | 494 | 2 | adapter->init(config); | 495 | 2 | return Status::OK(); | 496 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 472 | 14 | std::shared_ptr<AIAdapter>& adapter) const { | 473 | 14 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 474 | 14 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 475 | 14 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 476 | | | 477 | 14 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 478 | 14 | context->state()->get_query_ctx()->get_ai_resources(); | 479 | 14 | DORIS_CHECK(ai_resources); | 480 | 14 | auto it = ai_resources->find(resource_name); | 481 | 14 | DORIS_CHECK(it != ai_resources->end()); | 482 | 14 | PrimitiveType input_type = INVALID_TYPE; | 483 | 14 | if (arguments.size() > 1) { | 484 | 14 | input_type = | 485 | 14 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 486 | 14 | } | 487 | 14 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 488 | | | 489 | 14 | normalize_endpoint(config); | 490 | | | 491 | 14 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 492 | 14 | DORIS_CHECK(adapter); | 493 | | | 494 | 14 | adapter->init(config); | 495 | 14 | return Status::OK(); | 496 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 472 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 473 | 2 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 474 | 2 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 475 | 2 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 476 | | | 477 | 2 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 478 | 2 | context->state()->get_query_ctx()->get_ai_resources(); | 479 | 2 | DORIS_CHECK(ai_resources); | 480 | 2 | auto it = ai_resources->find(resource_name); | 481 | 2 | DORIS_CHECK(it != ai_resources->end()); | 482 | 2 | PrimitiveType input_type = INVALID_TYPE; | 483 | 2 | if (arguments.size() > 1) { | 484 | 2 | input_type = | 485 | 2 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 486 | 2 | } | 487 | 2 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 488 | | | 489 | 2 | normalize_endpoint(config); | 490 | | | 491 | 2 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 492 | 2 | DORIS_CHECK(adapter); | 493 | | | 494 | 2 | adapter->init(config); | 495 | 2 | return Status::OK(); | 496 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 472 | 3 | std::shared_ptr<AIAdapter>& adapter) const { | 473 | 3 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 474 | 3 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 475 | 3 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 476 | | | 477 | 3 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 478 | 3 | context->state()->get_query_ctx()->get_ai_resources(); | 479 | 3 | DORIS_CHECK(ai_resources); | 480 | 3 | auto it = ai_resources->find(resource_name); | 481 | 3 | DORIS_CHECK(it != ai_resources->end()); | 482 | 3 | PrimitiveType input_type = INVALID_TYPE; | 483 | 3 | if (arguments.size() > 1) { | 484 | 3 | input_type = | 485 | 3 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 486 | 3 | } | 487 | 3 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 488 | | | 489 | 3 | normalize_endpoint(config); | 490 | | | 491 | 3 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 492 | 3 | DORIS_CHECK(adapter); | 493 | | | 494 | 3 | adapter->init(config); | 495 | 3 | return Status::OK(); | 496 | 3 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 472 | 22 | std::shared_ptr<AIAdapter>& adapter) const { | 473 | 22 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 474 | 22 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 475 | 22 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 476 | | | 477 | 22 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 478 | 22 | context->state()->get_query_ctx()->get_ai_resources(); | 479 | 22 | DORIS_CHECK(ai_resources); | 480 | 22 | auto it = ai_resources->find(resource_name); | 481 | 22 | DORIS_CHECK(it != ai_resources->end()); | 482 | 22 | PrimitiveType input_type = INVALID_TYPE; | 483 | 22 | if (arguments.size() > 1) { | 484 | 22 | input_type = | 485 | 22 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 486 | 22 | } | 487 | 22 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 488 | | | 489 | 22 | normalize_endpoint(config); | 490 | | | 491 | 22 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 492 | 22 | DORIS_CHECK(adapter); | 493 | | | 494 | 22 | adapter->init(config); | 495 | 22 | return Status::OK(); | 496 | 22 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE |
497 | | |
498 | 90 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { |
499 | 90 | return AIResource(resource); |
500 | 90 | } _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 498 | 47 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 499 | 47 | return AIResource(resource); | 500 | 47 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 498 | 2 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 499 | 2 | return AIResource(resource); | 500 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 498 | 14 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 499 | 14 | return AIResource(resource); | 500 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 498 | 2 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 499 | 2 | return AIResource(resource); | 500 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 498 | 3 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 499 | 3 | return AIResource(resource); | 500 | 3 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 498 | 22 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 499 | 22 | return AIResource(resource); | 500 | 22 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE |
501 | | |
502 | | // Serializes one text batch into the shared JSON-array prompt format consumed by LLM |
503 | | // providers for batch string functions. |
504 | | Status build_batch_prompt(const std::vector<std::string>& batch_prompts, |
505 | 29 | std::string& prompt) const { |
506 | 29 | rapidjson::StringBuffer buffer; |
507 | 29 | rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); |
508 | | |
509 | 29 | writer.StartArray(); |
510 | 63 | for (size_t i = 0; i < batch_prompts.size(); ++i) { |
511 | 34 | writer.StartObject(); |
512 | 34 | writer.Key("idx"); |
513 | 34 | writer.Uint64(i); |
514 | 34 | writer.Key("input"); |
515 | 34 | writer.String(batch_prompts[i].data(), |
516 | 34 | static_cast<rapidjson::SizeType>(batch_prompts[i].size())); |
517 | 34 | writer.EndObject(); |
518 | 34 | } |
519 | 29 | writer.EndArray(); |
520 | | |
521 | 29 | prompt = buffer.GetString(); |
522 | 29 | return Status::OK(); |
523 | 29 | } Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Line | Count | Source | 505 | 29 | std::string& prompt) const { | 506 | 29 | rapidjson::StringBuffer buffer; | 507 | 29 | rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); | 508 | | | 509 | 29 | writer.StartArray(); | 510 | 63 | for (size_t i = 0; i < batch_prompts.size(); ++i) { | 511 | 34 | writer.StartObject(); | 512 | 34 | writer.Key("idx"); | 513 | 34 | writer.Uint64(i); | 514 | 34 | writer.Key("input"); | 515 | 34 | writer.String(batch_prompts[i].data(), | 516 | 34 | static_cast<rapidjson::SizeType>(batch_prompts[i].size())); | 517 | 34 | writer.EndObject(); | 518 | 34 | } | 519 | 29 | writer.EndArray(); | 520 | | | 521 | 29 | prompt = buffer.GetString(); | 522 | 29 | return Status::OK(); | 523 | 29 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_ |
524 | | }; |
525 | | |
526 | | } // namespace doris |