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/string_util.h" |
50 | | #include "util/threadpool.h" |
51 | | |
52 | | namespace doris { |
53 | | |
54 | | // Base class for AI-based functions |
55 | | template <typename Derived> |
56 | | class AIFunction : public IFunction { |
57 | | public: |
58 | 92 | static const char* batch_system_prompt(bool structured_batch) { |
59 | | // Cache both complete prompts per function. Requests only select an immutable string; |
60 | | // changing task wording does not depend on finding/replacing an exact sentence. |
61 | 92 | static const std::string structured_prompt = |
62 | 92 | std::string(Derived::system_prompt) + |
63 | 92 | " Return exactly one JSON object with a single field `results`, an array of " |
64 | 92 | "strings. The results array must have the same length and order as the input " |
65 | 92 | "array. Do not return input objects or indexes. Two-row output format example " |
66 | 92 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; |
67 | 92 | static const std::string legacy_prompt = |
68 | 92 | std::string(Derived::system_prompt) + |
69 | 92 | " Return exactly one JSON array of strings, with the same length and order as " |
70 | 92 | "the input array. Do not return input objects or indexes. Two-row output format " |
71 | 92 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; |
72 | 92 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); |
73 | 92 | } _ZN5doris10AIFunctionINS_16FunctionAIFilterEE19batch_system_promptEb Line | Count | Source | 58 | 5 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 5 | static const std::string structured_prompt = | 62 | 5 | std::string(Derived::system_prompt) + | 63 | 5 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 5 | "strings. The results array must have the same length and order as the input " | 65 | 5 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 5 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 5 | static const std::string legacy_prompt = | 68 | 5 | std::string(Derived::system_prompt) + | 69 | 5 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 5 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 5 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 5 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 5 | } |
_ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
_ZN5doris10AIFunctionINS_19FunctionAISentimentEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE19batch_system_promptEb Line | Count | Source | 58 | 55 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 55 | static const std::string structured_prompt = | 62 | 55 | std::string(Derived::system_prompt) + | 63 | 55 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 55 | "strings. The results array must have the same length and order as the input " | 65 | 55 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 55 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 55 | static const std::string legacy_prompt = | 68 | 55 | std::string(Derived::system_prompt) + | 69 | 55 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 55 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 55 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 55 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 55 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
_ZN5doris10AIFunctionINS_17FunctionAIExtractEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
_ZN5doris10AIFunctionINS_18FunctionAIGenerateEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
_ZN5doris10AIFunctionINS_14FunctionAIMaskEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
_ZN5doris10AIFunctionINS_20FunctionAISimilarityEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
_ZN5doris10AIFunctionINS_19FunctionAITranslateEE19batch_system_promptEb Line | Count | Source | 58 | 4 | static const char* batch_system_prompt(bool structured_batch) { | 59 | | // Cache both complete prompts per function. Requests only select an immutable string; | 60 | | // changing task wording does not depend on finding/replacing an exact sentence. | 61 | 4 | static const std::string structured_prompt = | 62 | 4 | std::string(Derived::system_prompt) + | 63 | 4 | " Return exactly one JSON object with a single field `results`, an array of " | 64 | 4 | "strings. The results array must have the same length and order as the input " | 65 | 4 | "array. Do not return input objects or indexes. Two-row output format example " | 66 | 4 | "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}."; | 67 | 4 | static const std::string legacy_prompt = | 68 | 4 | std::string(Derived::system_prompt) + | 69 | 4 | " Return exactly one JSON array of strings, with the same length and order as " | 70 | 4 | "the input array. Do not return input objects or indexes. Two-row output format " | 71 | 4 | "example (replace placeholders with actual results): [\"row1\",\"row2\"]."; | 72 | 4 | return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str(); | 73 | 4 | } |
|
74 | | |
75 | 16 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }_ZNK5doris10AIFunctionINS_13FunctionEmbedEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 6 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_17FunctionAIExtractEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_14FunctionAIMaskEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
_ZNK5doris10AIFunctionINS_19FunctionAITranslateEE8get_nameB5cxx11Ev Line | Count | Source | 75 | 1 | std::string get_name() const override { return assert_cast<const Derived&>(*this).name; } |
|
76 | | |
77 | | // If the user doesn't provide the first arg, `resource_name` |
78 | | // FE will add the `resource_name` to the arguments list using the Session Variable. |
79 | | // So the value here should be the maximum number that the function can accept. |
80 | 26 | size_t get_number_of_arguments() const override { |
81 | 26 | return assert_cast<const Derived&>(*this).number_of_arguments; |
82 | 26 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE23get_number_of_argumentsEv Line | Count | Source | 80 | 4 | size_t get_number_of_arguments() const override { | 81 | 4 | return assert_cast<const Derived&>(*this).number_of_arguments; | 82 | 4 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE23get_number_of_argumentsEv Line | Count | Source | 80 | 1 | size_t get_number_of_arguments() const override { | 81 | 1 | return assert_cast<const Derived&>(*this).number_of_arguments; | 82 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE23get_number_of_argumentsEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE23get_number_of_argumentsEv _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE23get_number_of_argumentsEv Line | Count | Source | 80 | 14 | size_t get_number_of_arguments() const override { | 81 | 14 | return assert_cast<const Derived&>(*this).number_of_arguments; | 82 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE23get_number_of_argumentsEv Line | Count | Source | 80 | 2 | size_t get_number_of_arguments() const override { | 81 | 2 | return assert_cast<const Derived&>(*this).number_of_arguments; | 82 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE23get_number_of_argumentsEv _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE23get_number_of_argumentsEv Line | Count | Source | 80 | 4 | size_t get_number_of_arguments() const override { | 81 | 4 | return assert_cast<const Derived&>(*this).number_of_arguments; | 82 | 4 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE23get_number_of_argumentsEv _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE23get_number_of_argumentsEv Line | Count | Source | 80 | 1 | size_t get_number_of_arguments() const override { | 81 | 1 | return assert_cast<const Derived&>(*this).number_of_arguments; | 82 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE23get_number_of_argumentsEv |
83 | | |
84 | 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 |
85 | | |
86 | 43 | Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
87 | 43 | if (scope == FunctionContext::FunctionStateScope::THREAD_LOCAL) { |
88 | | // Release this execution context's cached clients. |
89 | 29 | context->set_function_state(scope, nullptr); |
90 | 29 | } |
91 | 43 | return Status::OK(); |
92 | 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 | 86 | 43 | Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { | 87 | 43 | if (scope == FunctionContext::FunctionStateScope::THREAD_LOCAL) { | 88 | | // Release this execution context's cached clients. | 89 | 29 | context->set_function_state(scope, nullptr); | 90 | 29 | } | 91 | 43 | return Status::OK(); | 92 | 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 |
93 | | |
94 | 52 | bool use_default_implementation_for_nulls() const final { return false; }_ZNK5doris10AIFunctionINS_13FunctionEmbedEE36use_default_implementation_for_nullsEv Line | Count | Source | 94 | 8 | bool use_default_implementation_for_nulls() const final { return false; } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE36use_default_implementation_for_nullsEv Line | Count | Source | 94 | 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 | 94 | 28 | bool use_default_implementation_for_nulls() const final { return false; } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE36use_default_implementation_for_nullsEv Line | Count | Source | 94 | 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 | 94 | 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 | 94 | 2 | bool use_default_implementation_for_nulls() const final { return false; } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE36use_default_implementation_for_nullsEv |
95 | | |
96 | 37 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { |
97 | 37 | bool has_nullable_argument = std::ranges::any_of( |
98 | 53 | arguments, [](const auto& argument) { return argument->is_nullable(); });_ZZNK5doris10AIFunctionINS_13FunctionEmbedEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 98 | 8 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
_ZZNK5doris10AIFunctionINS_16FunctionAIFilterEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 98 | 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 | 98 | 28 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
_ZZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ Line | Count | Source | 98 | 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 | 98 | 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 | 98 | 2 | arguments, [](const auto& argument) { return argument->is_nullable(); }); |
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_19FunctionAITranslateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_ |
99 | 37 | DataTypePtr return_type = |
100 | 37 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); |
101 | 37 | return has_nullable_argument ? make_nullable(return_type) : return_type; |
102 | 37 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 5 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 5 | bool has_nullable_argument = std::ranges::any_of( | 98 | 5 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 5 | DataTypePtr return_type = | 100 | 5 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 5 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 5 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 2 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 2 | bool has_nullable_argument = std::ranges::any_of( | 98 | 2 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 2 | DataTypePtr return_type = | 100 | 2 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 2 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 2 | } |
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 1 | bool has_nullable_argument = std::ranges::any_of( | 98 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 1 | DataTypePtr return_type = | 100 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 1 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 1 | bool has_nullable_argument = std::ranges::any_of( | 98 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 1 | DataTypePtr return_type = | 100 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 1 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 15 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 15 | bool has_nullable_argument = std::ranges::any_of( | 98 | 15 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 15 | DataTypePtr return_type = | 100 | 15 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 15 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 15 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 3 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 3 | bool has_nullable_argument = std::ranges::any_of( | 98 | 3 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 3 | DataTypePtr return_type = | 100 | 3 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 3 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 3 | } |
_ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 1 | bool has_nullable_argument = std::ranges::any_of( | 98 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 1 | DataTypePtr return_type = | 100 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 1 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 5 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 5 | bool has_nullable_argument = std::ranges::any_of( | 98 | 5 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 5 | DataTypePtr return_type = | 100 | 5 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 5 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 5 | } |
_ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 1 | bool has_nullable_argument = std::ranges::any_of( | 98 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 1 | DataTypePtr return_type = | 100 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 1 | } |
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 2 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 2 | bool has_nullable_argument = std::ranges::any_of( | 98 | 2 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 2 | DataTypePtr return_type = | 100 | 2 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 2 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 96 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const final { | 97 | 1 | bool has_nullable_argument = std::ranges::any_of( | 98 | 1 | arguments, [](const auto& argument) { return argument->is_nullable(); }); | 99 | 1 | DataTypePtr return_type = | 100 | 1 | assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments); | 101 | 1 | return has_nullable_argument ? make_nullable(return_type) : return_type; | 102 | 1 | } |
|
103 | | |
104 | | using PreparedFunctionImpl::execute; |
105 | | |
106 | | virtual Status build_prompt(const Columns& prompt_columns, size_t row_num, |
107 | 121 | std::string& prompt) const { |
108 | 121 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); |
109 | 121 | prompt = std::string(text_ref.data, text_ref.size); |
110 | | |
111 | 121 | return Status::OK(); |
112 | 121 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 107 | 25 | std::string& prompt) const { | 108 | 25 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 109 | 25 | prompt = std::string(text_ref.data, text_ref.size); | 110 | | | 111 | 25 | return Status::OK(); | 112 | 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 | 107 | 65 | std::string& prompt) const { | 108 | 65 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 109 | 65 | prompt = std::string(text_ref.data, text_ref.size); | 110 | | | 111 | 65 | return Status::OK(); | 112 | 65 | } |
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 107 | 1 | std::string& prompt) const { | 108 | 1 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 109 | 1 | prompt = std::string(text_ref.data, text_ref.size); | 110 | | | 111 | 1 | return Status::OK(); | 112 | 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 | 107 | 5 | std::string& prompt) const { | 108 | 5 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 109 | 5 | prompt = std::string(text_ref.data, text_ref.size); | 110 | | | 111 | 5 | return Status::OK(); | 112 | 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 | 107 | 25 | std::string& prompt) const { | 108 | 25 | StringRef text_ref = prompt_columns[0]->get_data_at(row_num); | 109 | 25 | prompt = std::string(text_ref.data, text_ref.size); | 110 | | | 111 | 25 | return Status::OK(); | 112 | 25 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE |
113 | | |
114 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
115 | 106 | uint32_t result, size_t input_rows_count) const override { |
116 | 106 | if (block.get_by_position(arguments[0]).column->only_null()) { |
117 | 1 | block.get_by_position(result).column = |
118 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, |
119 | 1 | Field()); |
120 | 1 | return Status::OK(); |
121 | 1 | } |
122 | | |
123 | 105 | AIResource config; |
124 | 105 | std::shared_ptr<AIAdapter> adapter; |
125 | 105 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); |
126 | 105 | !status.ok()) { |
127 | 0 | return status; |
128 | 0 | } |
129 | | |
130 | 105 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, |
131 | 105 | input_rows_count, config, adapter); |
132 | 105 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 115 | 15 | uint32_t result, size_t input_rows_count) const override { | 116 | 15 | if (block.get_by_position(arguments[0]).column->only_null()) { | 117 | 0 | block.get_by_position(result).column = | 118 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 119 | 0 | Field()); | 120 | 0 | return Status::OK(); | 121 | 0 | } | 122 | | | 123 | 15 | AIResource config; | 124 | 15 | std::shared_ptr<AIAdapter> adapter; | 125 | 15 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 126 | 15 | !status.ok()) { | 127 | 0 | return status; | 128 | 0 | } | 129 | | | 130 | 15 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 131 | 15 | input_rows_count, config, adapter); | 132 | 15 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 115 | 47 | uint32_t result, size_t input_rows_count) const override { | 116 | 47 | if (block.get_by_position(arguments[0]).column->only_null()) { | 117 | 0 | block.get_by_position(result).column = | 118 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 119 | 0 | Field()); | 120 | 0 | return Status::OK(); | 121 | 0 | } | 122 | | | 123 | 47 | AIResource config; | 124 | 47 | std::shared_ptr<AIAdapter> adapter; | 125 | 47 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 126 | 47 | !status.ok()) { | 127 | 0 | return status; | 128 | 0 | } | 129 | | | 130 | 47 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 131 | 47 | input_rows_count, config, adapter); | 132 | 47 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 115 | 2 | uint32_t result, size_t input_rows_count) const override { | 116 | 2 | if (block.get_by_position(arguments[0]).column->only_null()) { | 117 | 0 | block.get_by_position(result).column = | 118 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 119 | 0 | Field()); | 120 | 0 | return Status::OK(); | 121 | 0 | } | 122 | | | 123 | 2 | AIResource config; | 124 | 2 | std::shared_ptr<AIAdapter> adapter; | 125 | 2 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 126 | 2 | !status.ok()) { | 127 | 0 | return status; | 128 | 0 | } | 129 | | | 130 | 2 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 131 | 2 | input_rows_count, config, adapter); | 132 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 115 | 14 | uint32_t result, size_t input_rows_count) const override { | 116 | 14 | if (block.get_by_position(arguments[0]).column->only_null()) { | 117 | 0 | block.get_by_position(result).column = | 118 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 119 | 0 | Field()); | 120 | 0 | return Status::OK(); | 121 | 0 | } | 122 | | | 123 | 14 | AIResource config; | 124 | 14 | std::shared_ptr<AIAdapter> adapter; | 125 | 14 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 126 | 14 | !status.ok()) { | 127 | 0 | return status; | 128 | 0 | } | 129 | | | 130 | 14 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 131 | 14 | input_rows_count, config, adapter); | 132 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 115 | 2 | uint32_t result, size_t input_rows_count) const override { | 116 | 2 | if (block.get_by_position(arguments[0]).column->only_null()) { | 117 | 0 | block.get_by_position(result).column = | 118 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 119 | 0 | Field()); | 120 | 0 | return Status::OK(); | 121 | 0 | } | 122 | | | 123 | 2 | AIResource config; | 124 | 2 | std::shared_ptr<AIAdapter> adapter; | 125 | 2 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 126 | 2 | !status.ok()) { | 127 | 0 | return status; | 128 | 0 | } | 129 | | | 130 | 2 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 131 | 2 | input_rows_count, config, adapter); | 132 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 115 | 4 | uint32_t result, size_t input_rows_count) const override { | 116 | 4 | if (block.get_by_position(arguments[0]).column->only_null()) { | 117 | 1 | block.get_by_position(result).column = | 118 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, | 119 | 1 | Field()); | 120 | 1 | return Status::OK(); | 121 | 1 | } | 122 | | | 123 | 3 | AIResource config; | 124 | 3 | std::shared_ptr<AIAdapter> adapter; | 125 | 3 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 126 | 3 | !status.ok()) { | 127 | 0 | return status; | 128 | 0 | } | 129 | | | 130 | 3 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 131 | 3 | input_rows_count, config, adapter); | 132 | 3 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 115 | 22 | uint32_t result, size_t input_rows_count) const override { | 116 | 22 | if (block.get_by_position(arguments[0]).column->only_null()) { | 117 | 0 | block.get_by_position(result).column = | 118 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 119 | 0 | Field()); | 120 | 0 | return Status::OK(); | 121 | 0 | } | 122 | | | 123 | 22 | AIResource config; | 124 | 22 | std::shared_ptr<AIAdapter> adapter; | 125 | 22 | if (Status status = this->_init_from_resource(context, block, arguments, config, adapter); | 126 | 22 | !status.ok()) { | 127 | 0 | return status; | 128 | 0 | } | 129 | | | 130 | 22 | return assert_cast<const Derived&>(*this).execute(context, block, arguments, result, | 131 | 22 | input_rows_count, config, adapter); | 132 | 22 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm |
133 | | |
134 | | protected: |
135 | | // Reads the shared AI context window size from query options. String AI batch functions and |
136 | | // ai_agg both use the same byte-based session variable so batching behavior stays consistent. |
137 | 105 | static int64_t get_ai_context_window_size(FunctionContext* context) { |
138 | 105 | DORIS_CHECK(context != nullptr); |
139 | 105 | QueryContext* query_ctx = context->state()->get_query_ctx(); |
140 | 105 | DORIS_CHECK(query_ctx != nullptr); |
141 | | |
142 | 105 | return query_ctx->query_options().ai_context_window_size; |
143 | 105 | } _ZN5doris10AIFunctionINS_13FunctionEmbedEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 137 | 11 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 138 | 11 | DORIS_CHECK(context != nullptr); | 139 | 11 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 140 | 11 | DORIS_CHECK(query_ctx != nullptr); | 141 | | | 142 | 11 | return query_ctx->query_options().ai_context_window_size; | 143 | 11 | } |
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 137 | 47 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 138 | 47 | DORIS_CHECK(context != nullptr); | 139 | 47 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 140 | 47 | DORIS_CHECK(query_ctx != nullptr); | 141 | | | 142 | 47 | return query_ctx->query_options().ai_context_window_size; | 143 | 47 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE26get_ai_context_window_sizeEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_19FunctionAISentimentEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 137 | 2 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 138 | 2 | DORIS_CHECK(context != nullptr); | 139 | 2 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 140 | 2 | DORIS_CHECK(query_ctx != nullptr); | 141 | | | 142 | 2 | return query_ctx->query_options().ai_context_window_size; | 143 | 2 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 137 | 19 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 138 | 19 | DORIS_CHECK(context != nullptr); | 139 | 19 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 140 | 19 | DORIS_CHECK(query_ctx != nullptr); | 141 | | | 142 | 19 | return query_ctx->query_options().ai_context_window_size; | 143 | 19 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 137 | 2 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 138 | 2 | DORIS_CHECK(context != nullptr); | 139 | 2 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 140 | 2 | DORIS_CHECK(query_ctx != nullptr); | 141 | | | 142 | 2 | return query_ctx->query_options().ai_context_window_size; | 143 | 2 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE26get_ai_context_window_sizeEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 137 | 2 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 138 | 2 | DORIS_CHECK(context != nullptr); | 139 | 2 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 140 | 2 | DORIS_CHECK(query_ctx != nullptr); | 141 | | | 142 | 2 | return query_ctx->query_options().ai_context_window_size; | 143 | 2 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE26get_ai_context_window_sizeEPNS_15FunctionContextE _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE26get_ai_context_window_sizeEPNS_15FunctionContextE Line | Count | Source | 137 | 22 | static int64_t get_ai_context_window_size(FunctionContext* context) { | 138 | 22 | DORIS_CHECK(context != nullptr); | 139 | 22 | QueryContext* query_ctx = context->state()->get_query_ctx(); | 140 | 22 | DORIS_CHECK(query_ctx != nullptr); | 141 | | | 142 | 22 | return query_ctx->query_options().ai_context_window_size; | 143 | 22 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE26get_ai_context_window_sizeEPNS_15FunctionContextE |
144 | | |
145 | 25 | MutableColumnPtr create_result_column() const { return ColumnString::create(); }Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20create_result_columnEv _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20create_result_columnEv Line | Count | Source | 145 | 2 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20create_result_columnEv Line | Count | Source | 145 | 19 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20create_result_columnEv Line | Count | Source | 145 | 2 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20create_result_columnEv _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20create_result_columnEv Line | Count | Source | 145 | 2 | MutableColumnPtr create_result_column() const { return ColumnString::create(); } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20create_result_columnEv Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20create_result_columnEv |
146 | | |
147 | | // Provider-reusable hook for AI functions(string) -> string. |
148 | | Status append_batch_results(const std::vector<std::string>& batch_results, |
149 | 30 | IColumn& col_result) const { |
150 | 30 | auto& string_col = assert_cast<ColumnString&>(col_result); |
151 | 35 | for (const auto& batch_result : batch_results) { |
152 | 35 | string_col.insert_data(batch_result.data(), batch_result.size()); |
153 | 35 | } |
154 | 30 | return Status::OK(); |
155 | 30 | } Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 149 | 2 | IColumn& col_result) const { | 150 | 2 | auto& string_col = assert_cast<ColumnString&>(col_result); | 151 | 4 | for (const auto& batch_result : batch_results) { | 152 | 4 | string_col.insert_data(batch_result.data(), batch_result.size()); | 153 | 4 | } | 154 | 2 | return Status::OK(); | 155 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 149 | 24 | IColumn& col_result) const { | 150 | 24 | auto& string_col = assert_cast<ColumnString&>(col_result); | 151 | 24 | for (const auto& batch_result : batch_results) { | 152 | 24 | string_col.insert_data(batch_result.data(), batch_result.size()); | 153 | 24 | } | 154 | 24 | return Status::OK(); | 155 | 24 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 149 | 2 | IColumn& col_result) const { | 150 | 2 | auto& string_col = assert_cast<ColumnString&>(col_result); | 151 | 2 | for (const auto& batch_result : batch_results) { | 152 | 2 | string_col.insert_data(batch_result.data(), batch_result.size()); | 153 | 2 | } | 154 | 2 | return Status::OK(); | 155 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Line | Count | Source | 149 | 2 | IColumn& col_result) const { | 150 | 2 | auto& string_col = assert_cast<ColumnString&>(col_result); | 151 | 5 | for (const auto& batch_result : batch_results) { | 152 | 5 | string_col.insert_data(batch_result.data(), batch_result.size()); | 153 | 5 | } | 154 | 2 | return Status::OK(); | 155 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE |
156 | | |
157 | 112 | static void normalize_endpoint(AIResource& config) { |
158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append |
159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` |
160 | | // for other AI scalar functions. |
161 | | // 2. `:embedContent` -> `:batchEmbedContents` |
162 | 112 | if (iequal(config.provider_type, "GEMINI")) { |
163 | 4 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { |
164 | 1 | static constexpr std::string_view legacy_suffix = ":embedContent"; |
165 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), |
166 | 1 | legacy_suffix.size(), ":batchEmbedContents"); |
167 | 1 | return; |
168 | 1 | } |
169 | | |
170 | 3 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { |
171 | 1 | return; |
172 | 1 | } |
173 | | |
174 | 2 | std::string model_name = config.model_name; |
175 | 2 | if (!model_name.starts_with("models/")) { |
176 | 2 | model_name = "models/" + model_name; |
177 | 2 | } |
178 | | |
179 | 2 | config.endpoint += "/"; |
180 | 2 | config.endpoint += model_name; |
181 | 2 | config.endpoint += |
182 | 2 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; |
183 | 2 | return; |
184 | 3 | } |
185 | | |
186 | | // The endpoint `v1/completions` does not support `system_prompt`. |
187 | | // To ensure a clear structure and stable AI results. |
188 | | // Convert from `v1/completions` to `v1/chat/completions` |
189 | 108 | if (config.endpoint.ends_with("v1/completions")) { |
190 | 1 | static constexpr std::string_view legacy_suffix = "v1/completions"; |
191 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), |
192 | 1 | legacy_suffix.size(), "v1/chat/completions"); |
193 | 1 | } |
194 | 108 | } _ZN5doris10AIFunctionINS_13FunctionEmbedEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 157 | 17 | static void normalize_endpoint(AIResource& config) { | 158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 160 | | // for other AI scalar functions. | 161 | | // 2. `:embedContent` -> `:batchEmbedContents` | 162 | 17 | if (iequal(config.provider_type, "GEMINI")) { | 163 | 2 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 164 | 1 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 165 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 166 | 1 | legacy_suffix.size(), ":batchEmbedContents"); | 167 | 1 | return; | 168 | 1 | } | 169 | | | 170 | 1 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 171 | 0 | return; | 172 | 0 | } | 173 | | | 174 | 1 | std::string model_name = config.model_name; | 175 | 1 | if (!model_name.starts_with("models/")) { | 176 | 1 | model_name = "models/" + model_name; | 177 | 1 | } | 178 | | | 179 | 1 | config.endpoint += "/"; | 180 | 1 | config.endpoint += model_name; | 181 | 1 | config.endpoint += | 182 | 1 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 183 | 1 | return; | 184 | 1 | } | 185 | | | 186 | | // The endpoint `v1/completions` does not support `system_prompt`. | 187 | | // To ensure a clear structure and stable AI results. | 188 | | // Convert from `v1/completions` to `v1/chat/completions` | 189 | 15 | if (config.endpoint.ends_with("v1/completions")) { | 190 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 191 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 192 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 193 | 0 | } | 194 | 15 | } |
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 157 | 47 | static void normalize_endpoint(AIResource& config) { | 158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 160 | | // for other AI scalar functions. | 161 | | // 2. `:embedContent` -> `:batchEmbedContents` | 162 | 47 | if (iequal(config.provider_type, "GEMINI")) { | 163 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 164 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 165 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 166 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 167 | 0 | return; | 168 | 0 | } | 169 | | | 170 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 171 | 0 | return; | 172 | 0 | } | 173 | | | 174 | 0 | std::string model_name = config.model_name; | 175 | 0 | if (!model_name.starts_with("models/")) { | 176 | 0 | model_name = "models/" + model_name; | 177 | 0 | } | 178 | |
| 179 | 0 | config.endpoint += "/"; | 180 | 0 | config.endpoint += model_name; | 181 | 0 | config.endpoint += | 182 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 183 | 0 | return; | 184 | 0 | } | 185 | | | 186 | | // The endpoint `v1/completions` does not support `system_prompt`. | 187 | | // To ensure a clear structure and stable AI results. | 188 | | // Convert from `v1/completions` to `v1/chat/completions` | 189 | 47 | if (config.endpoint.ends_with("v1/completions")) { | 190 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 191 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 192 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 193 | 0 | } | 194 | 47 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE18normalize_endpointERNS_10AIResourceE _ZN5doris10AIFunctionINS_19FunctionAISentimentEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 157 | 7 | static void normalize_endpoint(AIResource& config) { | 158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 160 | | // for other AI scalar functions. | 161 | | // 2. `:embedContent` -> `:batchEmbedContents` | 162 | 7 | if (iequal(config.provider_type, "GEMINI")) { | 163 | 2 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 164 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 165 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 166 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 167 | 0 | return; | 168 | 0 | } | 169 | | | 170 | 2 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 171 | 1 | return; | 172 | 1 | } | 173 | | | 174 | 1 | std::string model_name = config.model_name; | 175 | 1 | if (!model_name.starts_with("models/")) { | 176 | 1 | model_name = "models/" + model_name; | 177 | 1 | } | 178 | | | 179 | 1 | config.endpoint += "/"; | 180 | 1 | config.endpoint += model_name; | 181 | 1 | config.endpoint += | 182 | 1 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 183 | 1 | return; | 184 | 2 | } | 185 | | | 186 | | // The endpoint `v1/completions` does not support `system_prompt`. | 187 | | // To ensure a clear structure and stable AI results. | 188 | | // Convert from `v1/completions` to `v1/chat/completions` | 189 | 5 | if (config.endpoint.ends_with("v1/completions")) { | 190 | 1 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 191 | 1 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 192 | 1 | legacy_suffix.size(), "v1/chat/completions"); | 193 | 1 | } | 194 | 5 | } |
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 157 | 14 | static void normalize_endpoint(AIResource& config) { | 158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 160 | | // for other AI scalar functions. | 161 | | // 2. `:embedContent` -> `:batchEmbedContents` | 162 | 14 | if (iequal(config.provider_type, "GEMINI")) { | 163 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 164 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 165 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 166 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 167 | 0 | return; | 168 | 0 | } | 169 | | | 170 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 171 | 0 | return; | 172 | 0 | } | 173 | | | 174 | 0 | std::string model_name = config.model_name; | 175 | 0 | if (!model_name.starts_with("models/")) { | 176 | 0 | model_name = "models/" + model_name; | 177 | 0 | } | 178 | |
| 179 | 0 | config.endpoint += "/"; | 180 | 0 | config.endpoint += model_name; | 181 | 0 | config.endpoint += | 182 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 183 | 0 | return; | 184 | 0 | } | 185 | | | 186 | | // The endpoint `v1/completions` does not support `system_prompt`. | 187 | | // To ensure a clear structure and stable AI results. | 188 | | // Convert from `v1/completions` to `v1/chat/completions` | 189 | 14 | if (config.endpoint.ends_with("v1/completions")) { | 190 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 191 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 192 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 193 | 0 | } | 194 | 14 | } |
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 157 | 2 | static void normalize_endpoint(AIResource& config) { | 158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 160 | | // for other AI scalar functions. | 161 | | // 2. `:embedContent` -> `:batchEmbedContents` | 162 | 2 | if (iequal(config.provider_type, "GEMINI")) { | 163 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 164 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 165 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 166 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 167 | 0 | return; | 168 | 0 | } | 169 | | | 170 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 171 | 0 | return; | 172 | 0 | } | 173 | | | 174 | 0 | std::string model_name = config.model_name; | 175 | 0 | if (!model_name.starts_with("models/")) { | 176 | 0 | model_name = "models/" + model_name; | 177 | 0 | } | 178 | |
| 179 | 0 | config.endpoint += "/"; | 180 | 0 | config.endpoint += model_name; | 181 | 0 | config.endpoint += | 182 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 183 | 0 | return; | 184 | 0 | } | 185 | | | 186 | | // The endpoint `v1/completions` does not support `system_prompt`. | 187 | | // To ensure a clear structure and stable AI results. | 188 | | // Convert from `v1/completions` to `v1/chat/completions` | 189 | 2 | if (config.endpoint.ends_with("v1/completions")) { | 190 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 191 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 192 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 193 | 0 | } | 194 | 2 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE18normalize_endpointERNS_10AIResourceE _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 157 | 3 | static void normalize_endpoint(AIResource& config) { | 158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 160 | | // for other AI scalar functions. | 161 | | // 2. `:embedContent` -> `:batchEmbedContents` | 162 | 3 | if (iequal(config.provider_type, "GEMINI")) { | 163 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 164 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 165 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 166 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 167 | 0 | return; | 168 | 0 | } | 169 | | | 170 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 171 | 0 | return; | 172 | 0 | } | 173 | | | 174 | 0 | std::string model_name = config.model_name; | 175 | 0 | if (!model_name.starts_with("models/")) { | 176 | 0 | model_name = "models/" + model_name; | 177 | 0 | } | 178 | |
| 179 | 0 | config.endpoint += "/"; | 180 | 0 | config.endpoint += model_name; | 181 | 0 | config.endpoint += | 182 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 183 | 0 | return; | 184 | 0 | } | 185 | | | 186 | | // The endpoint `v1/completions` does not support `system_prompt`. | 187 | | // To ensure a clear structure and stable AI results. | 188 | | // Convert from `v1/completions` to `v1/chat/completions` | 189 | 3 | if (config.endpoint.ends_with("v1/completions")) { | 190 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 191 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 192 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 193 | 0 | } | 194 | 3 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE18normalize_endpointERNS_10AIResourceE _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE18normalize_endpointERNS_10AIResourceE Line | Count | Source | 157 | 22 | static void normalize_endpoint(AIResource& config) { | 158 | | // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append | 159 | | // `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent` | 160 | | // for other AI scalar functions. | 161 | | // 2. `:embedContent` -> `:batchEmbedContents` | 162 | 22 | if (iequal(config.provider_type, "GEMINI")) { | 163 | 0 | if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) { | 164 | 0 | static constexpr std::string_view legacy_suffix = ":embedContent"; | 165 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 166 | 0 | legacy_suffix.size(), ":batchEmbedContents"); | 167 | 0 | return; | 168 | 0 | } | 169 | | | 170 | 0 | if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) { | 171 | 0 | return; | 172 | 0 | } | 173 | | | 174 | 0 | std::string model_name = config.model_name; | 175 | 0 | if (!model_name.starts_with("models/")) { | 176 | 0 | model_name = "models/" + model_name; | 177 | 0 | } | 178 | |
| 179 | 0 | config.endpoint += "/"; | 180 | 0 | config.endpoint += model_name; | 181 | 0 | config.endpoint += | 182 | 0 | iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent"; | 183 | 0 | return; | 184 | 0 | } | 185 | | | 186 | | // The endpoint `v1/completions` does not support `system_prompt`. | 187 | | // To ensure a clear structure and stable AI results. | 188 | | // Convert from `v1/completions` to `v1/chat/completions` | 189 | 22 | if (config.endpoint.ends_with("v1/completions")) { | 190 | 0 | static constexpr std::string_view legacy_suffix = "v1/completions"; | 191 | 0 | config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(), | 192 | 0 | legacy_suffix.size(), "v1/chat/completions"); | 193 | 0 | } | 194 | 22 | } |
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE18normalize_endpointERNS_10AIResourceE |
195 | | |
196 | | Status send_request_to_llm(const std::string& request_body, std::string& response, |
197 | | const AIResource& config, std::shared_ptr<AIAdapter>& adapter, |
198 | 63 | FunctionContext* context) const { |
199 | | // Retain the cache across batches/Blocks. |
200 | 63 | auto* executor = static_cast<AIRequestExecutor*>( |
201 | 63 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); |
202 | 63 | if (executor == nullptr) { |
203 | 25 | auto state = std::make_shared<AIRequestExecutor>(); |
204 | 25 | executor = state.get(); |
205 | 25 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, |
206 | 25 | std::move(state)); |
207 | 25 | } |
208 | 63 | return executor->execute(request_body, response, config, *adapter, |
209 | 63 | context->state()->get_query_ctx()); |
210 | 63 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Line | Count | Source | 198 | 31 | FunctionContext* context) const { | 199 | | // Retain the cache across batches/Blocks. | 200 | 31 | auto* executor = static_cast<AIRequestExecutor*>( | 201 | 31 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 202 | 31 | if (executor == nullptr) { | 203 | 6 | auto state = std::make_shared<AIRequestExecutor>(); | 204 | 6 | executor = state.get(); | 205 | 6 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 206 | 6 | std::move(state)); | 207 | 6 | } | 208 | 31 | return executor->execute(request_body, response, config, *adapter, | 209 | 31 | context->state()->get_query_ctx()); | 210 | 31 | } |
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 | 198 | 3 | FunctionContext* context) const { | 199 | | // Retain the cache across batches/Blocks. | 200 | 3 | auto* executor = static_cast<AIRequestExecutor*>( | 201 | 3 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 202 | 3 | if (executor == nullptr) { | 203 | 3 | auto state = std::make_shared<AIRequestExecutor>(); | 204 | 3 | executor = state.get(); | 205 | 3 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 206 | 3 | std::move(state)); | 207 | 3 | } | 208 | 3 | return executor->execute(request_body, response, config, *adapter, | 209 | 3 | context->state()->get_query_ctx()); | 210 | 3 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE Line | Count | Source | 198 | 29 | FunctionContext* context) const { | 199 | | // Retain the cache across batches/Blocks. | 200 | 29 | auto* executor = static_cast<AIRequestExecutor*>( | 201 | 29 | context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL)); | 202 | 29 | if (executor == nullptr) { | 203 | 16 | auto state = std::make_shared<AIRequestExecutor>(); | 204 | 16 | executor = state.get(); | 205 | 16 | context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL, | 206 | 16 | std::move(state)); | 207 | 16 | } | 208 | 29 | return executor->execute(request_body, response, config, *adapter, | 209 | 29 | context->state()->get_query_ctx()); | 210 | 29 | } |
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 |
211 | | |
212 | | // Provider-reusable helper for string-returning functions. |
213 | | // Estimates one batch entry size using the raw prompt length plus the fixed JSON wrapper cost. |
214 | 124 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { |
215 | 124 | static constexpr size_t json_wrapper_size = 20; |
216 | 124 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; |
217 | 124 | } _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 214 | 64 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 215 | 64 | static constexpr size_t json_wrapper_size = 20; | 216 | 64 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 217 | 64 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 214 | 4 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 215 | 4 | static constexpr size_t json_wrapper_size = 20; | 216 | 4 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 217 | 4 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 214 | 24 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 215 | 24 | static constexpr size_t json_wrapper_size = 20; | 216 | 24 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 217 | 24 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 214 | 2 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 215 | 2 | static constexpr size_t json_wrapper_size = 20; | 216 | 2 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 217 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 214 | 5 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 215 | 5 | static constexpr size_t json_wrapper_size = 20; | 216 | 5 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 217 | 5 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 214 | 25 | size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const { | 215 | 25 | static constexpr size_t json_wrapper_size = 20; | 216 | 25 | return prompt.size() + std::to_string(idx).size() + json_wrapper_size; | 217 | 25 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE |
218 | | |
219 | | // Provider-reusable helper for string-returning functions. |
220 | | // Executes one batch request and parses the provider result into one string per input row. |
221 | | Status execute_batch_request(const std::vector<std::string>& batch_prompts, |
222 | | std::vector<std::string>& results, const AIResource& config, |
223 | | std::shared_ptr<AIAdapter>& adapter, |
224 | 14 | FunctionContext* context) const { |
225 | | #ifdef BE_TEST |
226 | | const char* test_result = std::getenv("AI_TEST_RESULT"); |
227 | | if (test_result != nullptr) { |
228 | | std::vector<std::string> parsed_test_response; |
229 | | RETURN_IF_ERROR( |
230 | | adapter->parse_response(std::string(test_result), parsed_test_response)); |
231 | | if (parsed_test_response.empty()) { |
232 | | return Status::InternalError("AI returned empty result"); |
233 | | } |
234 | | if (parsed_test_response.size() != batch_prompts.size()) { |
235 | | return Status::RuntimeError( |
236 | | "Failed to parse {} batch result, expected {} items but got {}", get_name(), |
237 | | batch_prompts.size(), parsed_test_response.size()); |
238 | | } |
239 | | results = std::move(parsed_test_response); |
240 | | return Status::OK(); |
241 | | } |
242 | | if (config.provider_type == "MOCK") { |
243 | | results.clear(); |
244 | | results.reserve(batch_prompts.size()); |
245 | | for (const auto& prompt : batch_prompts) { |
246 | | results.emplace_back("this is a mock response. " + prompt); |
247 | | } |
248 | | return Status::OK(); |
249 | | } |
250 | | #endif |
251 | | |
252 | 14 | std::string batch_prompt; |
253 | 14 | RETURN_IF_ERROR(build_batch_prompt(batch_prompts, batch_prompt)); |
254 | | |
255 | 14 | std::vector<std::string> inputs = {batch_prompt}; |
256 | 14 | std::vector<std::string> parsed_response; |
257 | | |
258 | 14 | std::string request_body; |
259 | | // Disabling provider format constraints keeps batching and the output protocol intact. |
260 | 14 | RETURN_IF_ERROR(adapter->build_request_payload( |
261 | 14 | inputs, batch_system_prompt(adapter->supports_structured_batch()), request_body, |
262 | 14 | config.enable_structured_output && adapter->supports_structured_batch())); |
263 | | |
264 | 14 | std::string response; |
265 | 14 | RETURN_IF_ERROR(send_request_to_llm(request_body, response, config, adapter, context)); |
266 | 14 | RETURN_IF_ERROR(adapter->parse_batch_response(response, parsed_response)); |
267 | 14 | if (parsed_response.empty()) { |
268 | 0 | return Status::InternalError("AI returned empty result"); |
269 | 0 | } |
270 | 14 | if (parsed_response.size() != batch_prompts.size()) { |
271 | 0 | LOG(WARNING) << "AI batch result size mismatch, function=" << get_name() |
272 | 0 | << ", provider=" << config.provider_type << ", model=" << config.model_name |
273 | 0 | << ", expected_rows=" << batch_prompts.size() |
274 | 0 | << ", actual_rows=" << parsed_response.size() |
275 | 0 | << ", response_body=" << response; |
276 | 0 | return Status::RuntimeError( |
277 | 0 | "Failed to parse {} batch result, expected {} items but got {}", get_name(), |
278 | 0 | batch_prompts.size(), parsed_response.size()); |
279 | 0 | } |
280 | 14 | results = std::move(parsed_response); |
281 | 14 | return Status::OK(); |
282 | 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 | 224 | 14 | FunctionContext* context) const { | 225 | | #ifdef BE_TEST | 226 | | const char* test_result = std::getenv("AI_TEST_RESULT"); | 227 | | if (test_result != nullptr) { | 228 | | std::vector<std::string> parsed_test_response; | 229 | | RETURN_IF_ERROR( | 230 | | adapter->parse_response(std::string(test_result), parsed_test_response)); | 231 | | if (parsed_test_response.empty()) { | 232 | | return Status::InternalError("AI returned empty result"); | 233 | | } | 234 | | if (parsed_test_response.size() != batch_prompts.size()) { | 235 | | return Status::RuntimeError( | 236 | | "Failed to parse {} batch result, expected {} items but got {}", get_name(), | 237 | | batch_prompts.size(), parsed_test_response.size()); | 238 | | } | 239 | | results = std::move(parsed_test_response); | 240 | | return Status::OK(); | 241 | | } | 242 | | if (config.provider_type == "MOCK") { | 243 | | results.clear(); | 244 | | results.reserve(batch_prompts.size()); | 245 | | for (const auto& prompt : batch_prompts) { | 246 | | results.emplace_back("this is a mock response. " + prompt); | 247 | | } | 248 | | return Status::OK(); | 249 | | } | 250 | | #endif | 251 | | | 252 | 14 | std::string batch_prompt; | 253 | 14 | RETURN_IF_ERROR(build_batch_prompt(batch_prompts, batch_prompt)); | 254 | | | 255 | 14 | std::vector<std::string> inputs = {batch_prompt}; | 256 | 14 | std::vector<std::string> parsed_response; | 257 | | | 258 | 14 | std::string request_body; | 259 | | // Disabling provider format constraints keeps batching and the output protocol intact. | 260 | 14 | RETURN_IF_ERROR(adapter->build_request_payload( | 261 | 14 | inputs, batch_system_prompt(adapter->supports_structured_batch()), request_body, | 262 | 14 | config.enable_structured_output && adapter->supports_structured_batch())); | 263 | | | 264 | 14 | std::string response; | 265 | 14 | RETURN_IF_ERROR(send_request_to_llm(request_body, response, config, adapter, context)); | 266 | 14 | RETURN_IF_ERROR(adapter->parse_batch_response(response, parsed_response)); | 267 | 14 | if (parsed_response.empty()) { | 268 | 0 | return Status::InternalError("AI returned empty result"); | 269 | 0 | } | 270 | 14 | if (parsed_response.size() != batch_prompts.size()) { | 271 | 0 | LOG(WARNING) << "AI batch result size mismatch, function=" << get_name() | 272 | 0 | << ", provider=" << config.provider_type << ", model=" << config.model_name | 273 | 0 | << ", expected_rows=" << batch_prompts.size() | 274 | 0 | << ", actual_rows=" << parsed_response.size() | 275 | 0 | << ", response_body=" << response; | 276 | 0 | return Status::RuntimeError( | 277 | 0 | "Failed to parse {} batch result, expected {} items but got {}", get_name(), | 278 | 0 | batch_prompts.size(), parsed_response.size()); | 279 | 0 | } | 280 | 14 | results = std::move(parsed_response); | 281 | 14 | return Status::OK(); | 282 | 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 |
283 | | |
284 | | // Provider-reusable helper for string-returning functions. |
285 | | // Runs the common batch execution flow; derived classes only need to define how one batch of |
286 | | // string results is inserted into the final output column. |
287 | | Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
288 | | uint32_t result, size_t input_rows_count, const AIResource& config, |
289 | 95 | std::shared_ptr<AIAdapter>& adapter) const { |
290 | 95 | Columns prompt_columns; |
291 | 95 | prompt_columns.reserve(arguments.size() - 1); |
292 | 95 | ColumnUInt8::MutablePtr result_null_map; |
293 | 214 | for (size_t i = 1; i < arguments.size(); ++i) { |
294 | 119 | const auto& argument = block.get_by_position(arguments[i]); |
295 | 119 | if (argument.type->is_nullable()) { |
296 | 14 | const auto& [column, is_const] = unpack_if_const(argument.column); |
297 | 14 | const auto& nullable = |
298 | 14 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); |
299 | 14 | if (!result_null_map) { |
300 | 13 | result_null_map = ColumnUInt8::create(input_rows_count, 0); |
301 | 13 | } |
302 | 14 | VectorizedUtils::update_null_map(result_null_map->get_data(), |
303 | 14 | nullable.get_null_map_data(), is_const); |
304 | 14 | } |
305 | 119 | prompt_columns.emplace_back( |
306 | 119 | argument.unnest_nullable(argument.type->is_nullable() |
307 | 119 | ? argument.get_nullable_column_info() |
308 | 119 | : NullableColumnInfo {}, |
309 | 119 | false) |
310 | 119 | .column); |
311 | 119 | } |
312 | | |
313 | 95 | if (result_null_map && |
314 | 95 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { |
315 | 1 | block.get_by_position(result).column = |
316 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, |
317 | 1 | Field()); |
318 | 1 | return Status::OK(); |
319 | 1 | } |
320 | | |
321 | 94 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); |
322 | 94 | std::vector<std::string> batch_prompts; |
323 | 94 | size_t current_batch_size = 2; // [] |
324 | 94 | const size_t max_batch_prompt_size = |
325 | 94 | static_cast<size_t>(get_ai_context_window_size(context)); |
326 | 94 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; |
327 | | |
328 | 232 | for (size_t i = 0; i < input_rows_count; ++i) { |
329 | 138 | if (null_map && (*null_map)[i]) { |
330 | 14 | continue; |
331 | 14 | } |
332 | | |
333 | 124 | std::string prompt; |
334 | 124 | RETURN_IF_ERROR( |
335 | 124 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); |
336 | | |
337 | 124 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); |
338 | 124 | if (entry_size > max_batch_prompt_size) { |
339 | 14 | if (!batch_prompts.empty()) { |
340 | 1 | std::vector<std::string> batch_results; |
341 | 1 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, |
342 | 1 | config, adapter, context)); |
343 | 1 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( |
344 | 1 | batch_results, *col_result)); |
345 | 1 | batch_prompts.clear(); |
346 | 1 | current_batch_size = 2; |
347 | 1 | } |
348 | | |
349 | 14 | std::vector<std::string> single_prompts; |
350 | 14 | single_prompts.emplace_back(std::move(prompt)); |
351 | 14 | std::vector<std::string> single_results; |
352 | 14 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, |
353 | 14 | adapter, context)); |
354 | 14 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( |
355 | 14 | single_results, *col_result)); |
356 | 14 | continue; |
357 | 14 | } |
358 | | |
359 | 110 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); |
360 | 110 | if (!batch_prompts.empty() && |
361 | 110 | current_batch_size + additional_size > max_batch_prompt_size) { |
362 | 2 | std::vector<std::string> batch_results; |
363 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, |
364 | 2 | adapter, context)); |
365 | 2 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( |
366 | 2 | batch_results, *col_result)); |
367 | 2 | batch_prompts.clear(); |
368 | 2 | current_batch_size = 2; |
369 | 2 | additional_size = entry_size; |
370 | 2 | } |
371 | | |
372 | 110 | batch_prompts.emplace_back(std::move(prompt)); |
373 | 110 | current_batch_size += additional_size; |
374 | 110 | } |
375 | | |
376 | 94 | if (!batch_prompts.empty()) { |
377 | 86 | std::vector<std::string> batch_results; |
378 | 86 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, |
379 | 86 | adapter, context)); |
380 | 80 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results(batch_results, |
381 | 80 | *col_result)); |
382 | 80 | } |
383 | | |
384 | 61 | if (!result_null_map) { |
385 | 49 | block.replace_by_position(result, std::move(col_result)); |
386 | 49 | return Status::OK(); |
387 | 49 | } |
388 | | |
389 | 12 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { |
390 | 3 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), |
391 | 3 | std::move(result_null_map))); |
392 | 3 | return Status::OK(); |
393 | 3 | } |
394 | | |
395 | 9 | auto nested_result = col_result->clone_empty(); |
396 | 9 | size_t result_row = 0; |
397 | 31 | for (UInt8 is_null : result_null_map->get_data()) { |
398 | 31 | if (is_null) { |
399 | 14 | nested_result->insert_default(); |
400 | 17 | } else { |
401 | 17 | nested_result->insert_from(*col_result, result_row++); |
402 | 17 | } |
403 | 31 | } |
404 | | |
405 | 9 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), |
406 | 9 | std::move(result_null_map))); |
407 | 9 | return Status::OK(); |
408 | 12 | } _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 289 | 47 | std::shared_ptr<AIAdapter>& adapter) const { | 290 | 47 | Columns prompt_columns; | 291 | 47 | prompt_columns.reserve(arguments.size() - 1); | 292 | 47 | ColumnUInt8::MutablePtr result_null_map; | 293 | 94 | for (size_t i = 1; i < arguments.size(); ++i) { | 294 | 47 | const auto& argument = block.get_by_position(arguments[i]); | 295 | 47 | if (argument.type->is_nullable()) { | 296 | 1 | const auto& [column, is_const] = unpack_if_const(argument.column); | 297 | 1 | const auto& nullable = | 298 | 1 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 299 | 1 | if (!result_null_map) { | 300 | 1 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 301 | 1 | } | 302 | 1 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 303 | 1 | nullable.get_null_map_data(), is_const); | 304 | 1 | } | 305 | 47 | prompt_columns.emplace_back( | 306 | 47 | argument.unnest_nullable(argument.type->is_nullable() | 307 | 47 | ? argument.get_nullable_column_info() | 308 | 47 | : NullableColumnInfo {}, | 309 | 47 | false) | 310 | 47 | .column); | 311 | 47 | } | 312 | | | 313 | 47 | if (result_null_map && | 314 | 47 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 315 | 0 | block.get_by_position(result).column = | 316 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 317 | 0 | Field()); | 318 | 0 | return Status::OK(); | 319 | 0 | } | 320 | | | 321 | 47 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 322 | 47 | std::vector<std::string> batch_prompts; | 323 | 47 | size_t current_batch_size = 2; // [] | 324 | 47 | const size_t max_batch_prompt_size = | 325 | 47 | static_cast<size_t>(get_ai_context_window_size(context)); | 326 | 47 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 327 | | | 328 | 113 | for (size_t i = 0; i < input_rows_count; ++i) { | 329 | 66 | if (null_map && (*null_map)[i]) { | 330 | 2 | continue; | 331 | 2 | } | 332 | | | 333 | 64 | std::string prompt; | 334 | 64 | RETURN_IF_ERROR( | 335 | 64 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 336 | | | 337 | 64 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 338 | 64 | if (entry_size > max_batch_prompt_size) { | 339 | 4 | if (!batch_prompts.empty()) { | 340 | 1 | std::vector<std::string> batch_results; | 341 | 1 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 342 | 1 | config, adapter, context)); | 343 | 1 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 344 | 1 | batch_results, *col_result)); | 345 | 1 | batch_prompts.clear(); | 346 | 1 | current_batch_size = 2; | 347 | 1 | } | 348 | | | 349 | 4 | std::vector<std::string> single_prompts; | 350 | 4 | single_prompts.emplace_back(std::move(prompt)); | 351 | 4 | std::vector<std::string> single_results; | 352 | 4 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 353 | 4 | adapter, context)); | 354 | 4 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 355 | 4 | single_results, *col_result)); | 356 | 4 | continue; | 357 | 4 | } | 358 | | | 359 | 60 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 360 | 60 | if (!batch_prompts.empty() && | 361 | 60 | current_batch_size + additional_size > max_batch_prompt_size) { | 362 | 2 | std::vector<std::string> batch_results; | 363 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 364 | 2 | adapter, context)); | 365 | 2 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 366 | 2 | batch_results, *col_result)); | 367 | 2 | batch_prompts.clear(); | 368 | 2 | current_batch_size = 2; | 369 | 2 | additional_size = entry_size; | 370 | 2 | } | 371 | | | 372 | 60 | batch_prompts.emplace_back(std::move(prompt)); | 373 | 60 | current_batch_size += additional_size; | 374 | 60 | } | 375 | | | 376 | 47 | if (!batch_prompts.empty()) { | 377 | 44 | std::vector<std::string> batch_results; | 378 | 44 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 379 | 44 | adapter, context)); | 380 | 38 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results(batch_results, | 381 | 38 | *col_result)); | 382 | 38 | } | 383 | | | 384 | 20 | if (!result_null_map) { | 385 | 19 | block.replace_by_position(result, std::move(col_result)); | 386 | 19 | return Status::OK(); | 387 | 19 | } | 388 | | | 389 | 1 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 390 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 391 | 0 | std::move(result_null_map))); | 392 | 0 | return Status::OK(); | 393 | 0 | } | 394 | | | 395 | 1 | auto nested_result = col_result->clone_empty(); | 396 | 1 | size_t result_row = 0; | 397 | 4 | for (UInt8 is_null : result_null_map->get_data()) { | 398 | 4 | if (is_null) { | 399 | 2 | nested_result->insert_default(); | 400 | 2 | } else { | 401 | 2 | nested_result->insert_from(*col_result, result_row++); | 402 | 2 | } | 403 | 4 | } | 404 | | | 405 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 406 | 1 | std::move(result_null_map))); | 407 | 1 | return Status::OK(); | 408 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 289 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 290 | 2 | Columns prompt_columns; | 291 | 2 | prompt_columns.reserve(arguments.size() - 1); | 292 | 2 | ColumnUInt8::MutablePtr result_null_map; | 293 | 4 | for (size_t i = 1; i < arguments.size(); ++i) { | 294 | 2 | const auto& argument = block.get_by_position(arguments[i]); | 295 | 2 | if (argument.type->is_nullable()) { | 296 | 0 | const auto& [column, is_const] = unpack_if_const(argument.column); | 297 | 0 | const auto& nullable = | 298 | 0 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 299 | 0 | if (!result_null_map) { | 300 | 0 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 301 | 0 | } | 302 | 0 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 303 | 0 | nullable.get_null_map_data(), is_const); | 304 | 0 | } | 305 | 2 | prompt_columns.emplace_back( | 306 | 2 | argument.unnest_nullable(argument.type->is_nullable() | 307 | 2 | ? argument.get_nullable_column_info() | 308 | 2 | : NullableColumnInfo {}, | 309 | 2 | false) | 310 | 2 | .column); | 311 | 2 | } | 312 | | | 313 | 2 | if (result_null_map && | 314 | 2 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 315 | 0 | block.get_by_position(result).column = | 316 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 317 | 0 | Field()); | 318 | 0 | return Status::OK(); | 319 | 0 | } | 320 | | | 321 | 2 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 322 | 2 | std::vector<std::string> batch_prompts; | 323 | 2 | size_t current_batch_size = 2; // [] | 324 | 2 | const size_t max_batch_prompt_size = | 325 | 2 | static_cast<size_t>(get_ai_context_window_size(context)); | 326 | 2 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 327 | | | 328 | 6 | for (size_t i = 0; i < input_rows_count; ++i) { | 329 | 4 | if (null_map && (*null_map)[i]) { | 330 | 0 | continue; | 331 | 0 | } | 332 | | | 333 | 4 | std::string prompt; | 334 | 4 | RETURN_IF_ERROR( | 335 | 4 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 336 | | | 337 | 4 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 338 | 4 | if (entry_size > max_batch_prompt_size) { | 339 | 0 | if (!batch_prompts.empty()) { | 340 | 0 | std::vector<std::string> batch_results; | 341 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 342 | 0 | config, adapter, context)); | 343 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 344 | 0 | batch_results, *col_result)); | 345 | 0 | batch_prompts.clear(); | 346 | 0 | current_batch_size = 2; | 347 | 0 | } | 348 | | | 349 | 0 | std::vector<std::string> single_prompts; | 350 | 0 | single_prompts.emplace_back(std::move(prompt)); | 351 | 0 | std::vector<std::string> single_results; | 352 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 353 | 0 | adapter, context)); | 354 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 355 | 0 | single_results, *col_result)); | 356 | 0 | continue; | 357 | 0 | } | 358 | | | 359 | 4 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 360 | 4 | if (!batch_prompts.empty() && | 361 | 4 | current_batch_size + additional_size > max_batch_prompt_size) { | 362 | 0 | std::vector<std::string> batch_results; | 363 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 364 | 0 | adapter, context)); | 365 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 366 | 0 | batch_results, *col_result)); | 367 | 0 | batch_prompts.clear(); | 368 | 0 | current_batch_size = 2; | 369 | 0 | additional_size = entry_size; | 370 | 0 | } | 371 | | | 372 | 4 | batch_prompts.emplace_back(std::move(prompt)); | 373 | 4 | current_batch_size += additional_size; | 374 | 4 | } | 375 | | | 376 | 2 | if (!batch_prompts.empty()) { | 377 | 2 | std::vector<std::string> batch_results; | 378 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 379 | 2 | adapter, context)); | 380 | 2 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results(batch_results, | 381 | 2 | *col_result)); | 382 | 2 | } | 383 | | | 384 | 2 | if (!result_null_map) { | 385 | 2 | block.replace_by_position(result, std::move(col_result)); | 386 | 2 | return Status::OK(); | 387 | 2 | } | 388 | | | 389 | 0 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 390 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 391 | 0 | std::move(result_null_map))); | 392 | 0 | return Status::OK(); | 393 | 0 | } | 394 | | | 395 | 0 | auto nested_result = col_result->clone_empty(); | 396 | 0 | size_t result_row = 0; | 397 | 0 | for (UInt8 is_null : result_null_map->get_data()) { | 398 | 0 | if (is_null) { | 399 | 0 | nested_result->insert_default(); | 400 | 0 | } else { | 401 | 0 | nested_result->insert_from(*col_result, result_row++); | 402 | 0 | } | 403 | 0 | } | 404 | |
| 405 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 406 | 0 | std::move(result_null_map))); | 407 | 0 | return Status::OK(); | 408 | 0 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 289 | 19 | std::shared_ptr<AIAdapter>& adapter) const { | 290 | 19 | Columns prompt_columns; | 291 | 19 | prompt_columns.reserve(arguments.size() - 1); | 292 | 19 | ColumnUInt8::MutablePtr result_null_map; | 293 | 38 | for (size_t i = 1; i < arguments.size(); ++i) { | 294 | 19 | const auto& argument = block.get_by_position(arguments[i]); | 295 | 19 | if (argument.type->is_nullable()) { | 296 | 7 | const auto& [column, is_const] = unpack_if_const(argument.column); | 297 | 7 | const auto& nullable = | 298 | 7 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 299 | 7 | if (!result_null_map) { | 300 | 7 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 301 | 7 | } | 302 | 7 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 303 | 7 | nullable.get_null_map_data(), is_const); | 304 | 7 | } | 305 | 19 | prompt_columns.emplace_back( | 306 | 19 | argument.unnest_nullable(argument.type->is_nullable() | 307 | 19 | ? argument.get_nullable_column_info() | 308 | 19 | : NullableColumnInfo {}, | 309 | 19 | false) | 310 | 19 | .column); | 311 | 19 | } | 312 | | | 313 | 19 | if (result_null_map && | 314 | 19 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 315 | 0 | block.get_by_position(result).column = | 316 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 317 | 0 | Field()); | 318 | 0 | return Status::OK(); | 319 | 0 | } | 320 | | | 321 | 19 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 322 | 19 | std::vector<std::string> batch_prompts; | 323 | 19 | size_t current_batch_size = 2; // [] | 324 | 19 | const size_t max_batch_prompt_size = | 325 | 19 | static_cast<size_t>(get_ai_context_window_size(context)); | 326 | 19 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 327 | | | 328 | 48 | for (size_t i = 0; i < input_rows_count; ++i) { | 329 | 29 | if (null_map && (*null_map)[i]) { | 330 | 5 | continue; | 331 | 5 | } | 332 | | | 333 | 24 | std::string prompt; | 334 | 24 | RETURN_IF_ERROR( | 335 | 24 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 336 | | | 337 | 24 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 338 | 24 | if (entry_size > max_batch_prompt_size) { | 339 | 10 | if (!batch_prompts.empty()) { | 340 | 0 | std::vector<std::string> batch_results; | 341 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 342 | 0 | config, adapter, context)); | 343 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 344 | 0 | batch_results, *col_result)); | 345 | 0 | batch_prompts.clear(); | 346 | 0 | current_batch_size = 2; | 347 | 0 | } | 348 | | | 349 | 10 | std::vector<std::string> single_prompts; | 350 | 10 | single_prompts.emplace_back(std::move(prompt)); | 351 | 10 | std::vector<std::string> single_results; | 352 | 10 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 353 | 10 | adapter, context)); | 354 | 10 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 355 | 10 | single_results, *col_result)); | 356 | 10 | continue; | 357 | 10 | } | 358 | | | 359 | 14 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 360 | 14 | if (!batch_prompts.empty() && | 361 | 14 | current_batch_size + additional_size > max_batch_prompt_size) { | 362 | 0 | std::vector<std::string> batch_results; | 363 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 364 | 0 | adapter, context)); | 365 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 366 | 0 | batch_results, *col_result)); | 367 | 0 | batch_prompts.clear(); | 368 | 0 | current_batch_size = 2; | 369 | 0 | additional_size = entry_size; | 370 | 0 | } | 371 | | | 372 | 14 | batch_prompts.emplace_back(std::move(prompt)); | 373 | 14 | current_batch_size += additional_size; | 374 | 14 | } | 375 | | | 376 | 19 | if (!batch_prompts.empty()) { | 377 | 14 | std::vector<std::string> batch_results; | 378 | 14 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 379 | 14 | adapter, context)); | 380 | 14 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results(batch_results, | 381 | 14 | *col_result)); | 382 | 14 | } | 383 | | | 384 | 19 | if (!result_null_map) { | 385 | 12 | block.replace_by_position(result, std::move(col_result)); | 386 | 12 | return Status::OK(); | 387 | 12 | } | 388 | | | 389 | 7 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 390 | 2 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 391 | 2 | std::move(result_null_map))); | 392 | 2 | return Status::OK(); | 393 | 2 | } | 394 | | | 395 | 5 | auto nested_result = col_result->clone_empty(); | 396 | 5 | size_t result_row = 0; | 397 | 15 | for (UInt8 is_null : result_null_map->get_data()) { | 398 | 15 | if (is_null) { | 399 | 5 | nested_result->insert_default(); | 400 | 10 | } else { | 401 | 10 | nested_result->insert_from(*col_result, result_row++); | 402 | 10 | } | 403 | 15 | } | 404 | | | 405 | 5 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 406 | 5 | std::move(result_null_map))); | 407 | 5 | return Status::OK(); | 408 | 7 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 289 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 290 | 2 | Columns prompt_columns; | 291 | 2 | prompt_columns.reserve(arguments.size() - 1); | 292 | 2 | ColumnUInt8::MutablePtr result_null_map; | 293 | 6 | for (size_t i = 1; i < arguments.size(); ++i) { | 294 | 4 | const auto& argument = block.get_by_position(arguments[i]); | 295 | 4 | if (argument.type->is_nullable()) { | 296 | 1 | const auto& [column, is_const] = unpack_if_const(argument.column); | 297 | 1 | const auto& nullable = | 298 | 1 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 299 | 1 | if (!result_null_map) { | 300 | 1 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 301 | 1 | } | 302 | 1 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 303 | 1 | nullable.get_null_map_data(), is_const); | 304 | 1 | } | 305 | 4 | prompt_columns.emplace_back( | 306 | 4 | argument.unnest_nullable(argument.type->is_nullable() | 307 | 4 | ? argument.get_nullable_column_info() | 308 | 4 | : NullableColumnInfo {}, | 309 | 4 | false) | 310 | 4 | .column); | 311 | 4 | } | 312 | | | 313 | 2 | if (result_null_map && | 314 | 2 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 315 | 0 | block.get_by_position(result).column = | 316 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 317 | 0 | Field()); | 318 | 0 | return Status::OK(); | 319 | 0 | } | 320 | | | 321 | 2 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 322 | 2 | std::vector<std::string> batch_prompts; | 323 | 2 | size_t current_batch_size = 2; // [] | 324 | 2 | const size_t max_batch_prompt_size = | 325 | 2 | static_cast<size_t>(get_ai_context_window_size(context)); | 326 | 2 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 327 | | | 328 | 6 | for (size_t i = 0; i < input_rows_count; ++i) { | 329 | 4 | if (null_map && (*null_map)[i]) { | 330 | 2 | continue; | 331 | 2 | } | 332 | | | 333 | 2 | std::string prompt; | 334 | 2 | RETURN_IF_ERROR( | 335 | 2 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 336 | | | 337 | 2 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 338 | 2 | if (entry_size > max_batch_prompt_size) { | 339 | 0 | if (!batch_prompts.empty()) { | 340 | 0 | std::vector<std::string> batch_results; | 341 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 342 | 0 | config, adapter, context)); | 343 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 344 | 0 | batch_results, *col_result)); | 345 | 0 | batch_prompts.clear(); | 346 | 0 | current_batch_size = 2; | 347 | 0 | } | 348 | | | 349 | 0 | std::vector<std::string> single_prompts; | 350 | 0 | single_prompts.emplace_back(std::move(prompt)); | 351 | 0 | std::vector<std::string> single_results; | 352 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 353 | 0 | adapter, context)); | 354 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 355 | 0 | single_results, *col_result)); | 356 | 0 | continue; | 357 | 0 | } | 358 | | | 359 | 2 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 360 | 2 | if (!batch_prompts.empty() && | 361 | 2 | current_batch_size + additional_size > max_batch_prompt_size) { | 362 | 0 | std::vector<std::string> batch_results; | 363 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 364 | 0 | adapter, context)); | 365 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 366 | 0 | batch_results, *col_result)); | 367 | 0 | batch_prompts.clear(); | 368 | 0 | current_batch_size = 2; | 369 | 0 | additional_size = entry_size; | 370 | 0 | } | 371 | | | 372 | 2 | batch_prompts.emplace_back(std::move(prompt)); | 373 | 2 | current_batch_size += additional_size; | 374 | 2 | } | 375 | | | 376 | 2 | if (!batch_prompts.empty()) { | 377 | 2 | std::vector<std::string> batch_results; | 378 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 379 | 2 | adapter, context)); | 380 | 2 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results(batch_results, | 381 | 2 | *col_result)); | 382 | 2 | } | 383 | | | 384 | 2 | if (!result_null_map) { | 385 | 1 | block.replace_by_position(result, std::move(col_result)); | 386 | 1 | return Status::OK(); | 387 | 1 | } | 388 | | | 389 | 1 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 390 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 391 | 0 | std::move(result_null_map))); | 392 | 0 | return Status::OK(); | 393 | 0 | } | 394 | | | 395 | 1 | auto nested_result = col_result->clone_empty(); | 396 | 1 | size_t result_row = 0; | 397 | 3 | for (UInt8 is_null : result_null_map->get_data()) { | 398 | 3 | if (is_null) { | 399 | 2 | nested_result->insert_default(); | 400 | 2 | } else { | 401 | 1 | nested_result->insert_from(*col_result, result_row++); | 402 | 1 | } | 403 | 3 | } | 404 | | | 405 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 406 | 1 | std::move(result_null_map))); | 407 | 1 | return Status::OK(); | 408 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 289 | 3 | std::shared_ptr<AIAdapter>& adapter) const { | 290 | 3 | Columns prompt_columns; | 291 | 3 | prompt_columns.reserve(arguments.size() - 1); | 292 | 3 | ColumnUInt8::MutablePtr result_null_map; | 293 | 6 | for (size_t i = 1; i < arguments.size(); ++i) { | 294 | 3 | const auto& argument = block.get_by_position(arguments[i]); | 295 | 3 | if (argument.type->is_nullable()) { | 296 | 3 | const auto& [column, is_const] = unpack_if_const(argument.column); | 297 | 3 | const auto& nullable = | 298 | 3 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 299 | 3 | if (!result_null_map) { | 300 | 3 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 301 | 3 | } | 302 | 3 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 303 | 3 | nullable.get_null_map_data(), is_const); | 304 | 3 | } | 305 | 3 | prompt_columns.emplace_back( | 306 | 3 | argument.unnest_nullable(argument.type->is_nullable() | 307 | 3 | ? argument.get_nullable_column_info() | 308 | 3 | : NullableColumnInfo {}, | 309 | 3 | false) | 310 | 3 | .column); | 311 | 3 | } | 312 | | | 313 | 3 | if (result_null_map && | 314 | 3 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 315 | 1 | block.get_by_position(result).column = | 316 | 1 | block.get_by_position(result).type->create_column_const(input_rows_count, | 317 | 1 | Field()); | 318 | 1 | return Status::OK(); | 319 | 1 | } | 320 | | | 321 | 2 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 322 | 2 | std::vector<std::string> batch_prompts; | 323 | 2 | size_t current_batch_size = 2; // [] | 324 | 2 | const size_t max_batch_prompt_size = | 325 | 2 | static_cast<size_t>(get_ai_context_window_size(context)); | 326 | 2 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 327 | | | 328 | 10 | for (size_t i = 0; i < input_rows_count; ++i) { | 329 | 8 | if (null_map && (*null_map)[i]) { | 330 | 3 | continue; | 331 | 3 | } | 332 | | | 333 | 5 | std::string prompt; | 334 | 5 | RETURN_IF_ERROR( | 335 | 5 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 336 | | | 337 | 5 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 338 | 5 | if (entry_size > max_batch_prompt_size) { | 339 | 0 | if (!batch_prompts.empty()) { | 340 | 0 | std::vector<std::string> batch_results; | 341 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 342 | 0 | config, adapter, context)); | 343 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 344 | 0 | batch_results, *col_result)); | 345 | 0 | batch_prompts.clear(); | 346 | 0 | current_batch_size = 2; | 347 | 0 | } | 348 | | | 349 | 0 | std::vector<std::string> single_prompts; | 350 | 0 | single_prompts.emplace_back(std::move(prompt)); | 351 | 0 | std::vector<std::string> single_results; | 352 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 353 | 0 | adapter, context)); | 354 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 355 | 0 | single_results, *col_result)); | 356 | 0 | continue; | 357 | 0 | } | 358 | | | 359 | 5 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 360 | 5 | if (!batch_prompts.empty() && | 361 | 5 | current_batch_size + additional_size > max_batch_prompt_size) { | 362 | 0 | std::vector<std::string> batch_results; | 363 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 364 | 0 | adapter, context)); | 365 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 366 | 0 | batch_results, *col_result)); | 367 | 0 | batch_prompts.clear(); | 368 | 0 | current_batch_size = 2; | 369 | 0 | additional_size = entry_size; | 370 | 0 | } | 371 | | | 372 | 5 | batch_prompts.emplace_back(std::move(prompt)); | 373 | 5 | current_batch_size += additional_size; | 374 | 5 | } | 375 | | | 376 | 2 | if (!batch_prompts.empty()) { | 377 | 2 | std::vector<std::string> batch_results; | 378 | 2 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 379 | 2 | adapter, context)); | 380 | 2 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results(batch_results, | 381 | 2 | *col_result)); | 382 | 2 | } | 383 | | | 384 | 2 | if (!result_null_map) { | 385 | 0 | block.replace_by_position(result, std::move(col_result)); | 386 | 0 | return Status::OK(); | 387 | 0 | } | 388 | | | 389 | 2 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 390 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 391 | 1 | std::move(result_null_map))); | 392 | 1 | return Status::OK(); | 393 | 1 | } | 394 | | | 395 | 1 | auto nested_result = col_result->clone_empty(); | 396 | 1 | size_t result_row = 0; | 397 | 5 | for (UInt8 is_null : result_null_map->get_data()) { | 398 | 5 | if (is_null) { | 399 | 3 | nested_result->insert_default(); | 400 | 3 | } else { | 401 | 2 | nested_result->insert_from(*col_result, result_row++); | 402 | 2 | } | 403 | 5 | } | 404 | | | 405 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 406 | 1 | std::move(result_null_map))); | 407 | 1 | return Status::OK(); | 408 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 289 | 22 | std::shared_ptr<AIAdapter>& adapter) const { | 290 | 22 | Columns prompt_columns; | 291 | 22 | prompt_columns.reserve(arguments.size() - 1); | 292 | 22 | ColumnUInt8::MutablePtr result_null_map; | 293 | 66 | for (size_t i = 1; i < arguments.size(); ++i) { | 294 | 44 | const auto& argument = block.get_by_position(arguments[i]); | 295 | 44 | if (argument.type->is_nullable()) { | 296 | 2 | const auto& [column, is_const] = unpack_if_const(argument.column); | 297 | 2 | const auto& nullable = | 298 | 2 | assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column); | 299 | 2 | if (!result_null_map) { | 300 | 1 | result_null_map = ColumnUInt8::create(input_rows_count, 0); | 301 | 1 | } | 302 | 2 | VectorizedUtils::update_null_map(result_null_map->get_data(), | 303 | 2 | nullable.get_null_map_data(), is_const); | 304 | 2 | } | 305 | 44 | prompt_columns.emplace_back( | 306 | 44 | argument.unnest_nullable(argument.type->is_nullable() | 307 | 44 | ? argument.get_nullable_column_info() | 308 | 44 | : NullableColumnInfo {}, | 309 | 44 | false) | 310 | 44 | .column); | 311 | 44 | } | 312 | | | 313 | 22 | if (result_null_map && | 314 | 22 | !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) { | 315 | 0 | block.get_by_position(result).column = | 316 | 0 | block.get_by_position(result).type->create_column_const(input_rows_count, | 317 | 0 | Field()); | 318 | 0 | return Status::OK(); | 319 | 0 | } | 320 | | | 321 | 22 | auto col_result = assert_cast<const Derived&>(*this).create_result_column(); | 322 | 22 | std::vector<std::string> batch_prompts; | 323 | 22 | size_t current_batch_size = 2; // [] | 324 | 22 | const size_t max_batch_prompt_size = | 325 | 22 | static_cast<size_t>(get_ai_context_window_size(context)); | 326 | 22 | const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr; | 327 | | | 328 | 49 | for (size_t i = 0; i < input_rows_count; ++i) { | 329 | 27 | if (null_map && (*null_map)[i]) { | 330 | 2 | continue; | 331 | 2 | } | 332 | | | 333 | 25 | std::string prompt; | 334 | 25 | RETURN_IF_ERROR( | 335 | 25 | assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt)); | 336 | | | 337 | 25 | size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt); | 338 | 25 | if (entry_size > max_batch_prompt_size) { | 339 | 0 | if (!batch_prompts.empty()) { | 340 | 0 | std::vector<std::string> batch_results; | 341 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, | 342 | 0 | config, adapter, context)); | 343 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 344 | 0 | batch_results, *col_result)); | 345 | 0 | batch_prompts.clear(); | 346 | 0 | current_batch_size = 2; | 347 | 0 | } | 348 | | | 349 | 0 | std::vector<std::string> single_prompts; | 350 | 0 | single_prompts.emplace_back(std::move(prompt)); | 351 | 0 | std::vector<std::string> single_results; | 352 | 0 | RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config, | 353 | 0 | adapter, context)); | 354 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 355 | 0 | single_results, *col_result)); | 356 | 0 | continue; | 357 | 0 | } | 358 | | | 359 | 25 | size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1); | 360 | 25 | if (!batch_prompts.empty() && | 361 | 25 | current_batch_size + additional_size > max_batch_prompt_size) { | 362 | 0 | std::vector<std::string> batch_results; | 363 | 0 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 364 | 0 | adapter, context)); | 365 | 0 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results( | 366 | 0 | batch_results, *col_result)); | 367 | 0 | batch_prompts.clear(); | 368 | 0 | current_batch_size = 2; | 369 | 0 | additional_size = entry_size; | 370 | 0 | } | 371 | | | 372 | 25 | batch_prompts.emplace_back(std::move(prompt)); | 373 | 25 | current_batch_size += additional_size; | 374 | 25 | } | 375 | | | 376 | 22 | if (!batch_prompts.empty()) { | 377 | 22 | std::vector<std::string> batch_results; | 378 | 22 | RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config, | 379 | 22 | adapter, context)); | 380 | 22 | RETURN_IF_ERROR(assert_cast<const Derived&>(*this).append_batch_results(batch_results, | 381 | 22 | *col_result)); | 382 | 22 | } | 383 | | | 384 | 16 | if (!result_null_map) { | 385 | 15 | block.replace_by_position(result, std::move(col_result)); | 386 | 15 | return Status::OK(); | 387 | 15 | } | 388 | | | 389 | 1 | if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) { | 390 | 0 | block.replace_by_position(result, ColumnNullable::create(std::move(col_result), | 391 | 0 | std::move(result_null_map))); | 392 | 0 | return Status::OK(); | 393 | 0 | } | 394 | | | 395 | 1 | auto nested_result = col_result->clone_empty(); | 396 | 1 | size_t result_row = 0; | 397 | 4 | for (UInt8 is_null : result_null_map->get_data()) { | 398 | 4 | if (is_null) { | 399 | 2 | nested_result->insert_default(); | 400 | 2 | } else { | 401 | 2 | nested_result->insert_from(*col_result, result_row++); | 402 | 2 | } | 403 | 4 | } | 404 | | | 405 | 1 | block.replace_by_position(result, ColumnNullable::create(std::move(nested_result), | 406 | 1 | std::move(result_null_map))); | 407 | 1 | return Status::OK(); | 408 | 1 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE |
409 | | |
410 | | private: |
411 | | // The ai resource must be literal |
412 | | Status _init_from_resource(FunctionContext* context, const Block& block, |
413 | | const ColumnNumbers& arguments, AIResource& config, |
414 | 105 | std::shared_ptr<AIAdapter>& adapter) const { |
415 | 105 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); |
416 | 105 | StringRef resource_name_ref = resource_column.column->get_data_at(0); |
417 | 105 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); |
418 | | |
419 | 105 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = |
420 | 105 | context->state()->get_query_ctx()->get_ai_resources(); |
421 | 105 | DORIS_CHECK(ai_resources); |
422 | 105 | auto it = ai_resources->find(resource_name); |
423 | 105 | DORIS_CHECK(it != ai_resources->end()); |
424 | 105 | PrimitiveType input_type = INVALID_TYPE; |
425 | 105 | if (arguments.size() > 1) { |
426 | 104 | input_type = |
427 | 104 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); |
428 | 104 | } |
429 | 105 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); |
430 | | |
431 | 105 | normalize_endpoint(config); |
432 | | |
433 | 105 | adapter = AIAdapterFactory::create_adapter(config.provider_type); |
434 | 105 | DORIS_CHECK(adapter); |
435 | | |
436 | 105 | adapter->init(config); |
437 | 105 | return Status::OK(); |
438 | 105 | } _ZNK5doris10AIFunctionINS_13FunctionEmbedEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 414 | 15 | std::shared_ptr<AIAdapter>& adapter) const { | 415 | 15 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 416 | 15 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 417 | 15 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 418 | | | 419 | 15 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 420 | 15 | context->state()->get_query_ctx()->get_ai_resources(); | 421 | 15 | DORIS_CHECK(ai_resources); | 422 | 15 | auto it = ai_resources->find(resource_name); | 423 | 15 | DORIS_CHECK(it != ai_resources->end()); | 424 | 15 | PrimitiveType input_type = INVALID_TYPE; | 425 | 15 | if (arguments.size() > 1) { | 426 | 14 | input_type = | 427 | 14 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 428 | 14 | } | 429 | 15 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 430 | | | 431 | 15 | normalize_endpoint(config); | 432 | | | 433 | 15 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 434 | 15 | DORIS_CHECK(adapter); | 435 | | | 436 | 15 | adapter->init(config); | 437 | 15 | return Status::OK(); | 438 | 15 | } |
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 414 | 47 | std::shared_ptr<AIAdapter>& adapter) const { | 415 | 47 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 416 | 47 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 417 | 47 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 418 | | | 419 | 47 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 420 | 47 | context->state()->get_query_ctx()->get_ai_resources(); | 421 | 47 | DORIS_CHECK(ai_resources); | 422 | 47 | auto it = ai_resources->find(resource_name); | 423 | 47 | DORIS_CHECK(it != ai_resources->end()); | 424 | 47 | PrimitiveType input_type = INVALID_TYPE; | 425 | 47 | if (arguments.size() > 1) { | 426 | 47 | input_type = | 427 | 47 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 428 | 47 | } | 429 | 47 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 430 | | | 431 | 47 | normalize_endpoint(config); | 432 | | | 433 | 47 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 434 | 47 | DORIS_CHECK(adapter); | 435 | | | 436 | 47 | adapter->init(config); | 437 | 47 | return Status::OK(); | 438 | 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 | 414 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 415 | 2 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 416 | 2 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 417 | 2 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 418 | | | 419 | 2 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 420 | 2 | context->state()->get_query_ctx()->get_ai_resources(); | 421 | 2 | DORIS_CHECK(ai_resources); | 422 | 2 | auto it = ai_resources->find(resource_name); | 423 | 2 | DORIS_CHECK(it != ai_resources->end()); | 424 | 2 | PrimitiveType input_type = INVALID_TYPE; | 425 | 2 | if (arguments.size() > 1) { | 426 | 2 | input_type = | 427 | 2 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 428 | 2 | } | 429 | 2 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 430 | | | 431 | 2 | normalize_endpoint(config); | 432 | | | 433 | 2 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 434 | 2 | DORIS_CHECK(adapter); | 435 | | | 436 | 2 | adapter->init(config); | 437 | 2 | return Status::OK(); | 438 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 414 | 14 | std::shared_ptr<AIAdapter>& adapter) const { | 415 | 14 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 416 | 14 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 417 | 14 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 418 | | | 419 | 14 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 420 | 14 | context->state()->get_query_ctx()->get_ai_resources(); | 421 | 14 | DORIS_CHECK(ai_resources); | 422 | 14 | auto it = ai_resources->find(resource_name); | 423 | 14 | DORIS_CHECK(it != ai_resources->end()); | 424 | 14 | PrimitiveType input_type = INVALID_TYPE; | 425 | 14 | if (arguments.size() > 1) { | 426 | 14 | input_type = | 427 | 14 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 428 | 14 | } | 429 | 14 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 430 | | | 431 | 14 | normalize_endpoint(config); | 432 | | | 433 | 14 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 434 | 14 | DORIS_CHECK(adapter); | 435 | | | 436 | 14 | adapter->init(config); | 437 | 14 | return Status::OK(); | 438 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE Line | Count | Source | 414 | 2 | std::shared_ptr<AIAdapter>& adapter) const { | 415 | 2 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 416 | 2 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 417 | 2 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 418 | | | 419 | 2 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 420 | 2 | context->state()->get_query_ctx()->get_ai_resources(); | 421 | 2 | DORIS_CHECK(ai_resources); | 422 | 2 | auto it = ai_resources->find(resource_name); | 423 | 2 | DORIS_CHECK(it != ai_resources->end()); | 424 | 2 | PrimitiveType input_type = INVALID_TYPE; | 425 | 2 | if (arguments.size() > 1) { | 426 | 2 | input_type = | 427 | 2 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 428 | 2 | } | 429 | 2 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 430 | | | 431 | 2 | normalize_endpoint(config); | 432 | | | 433 | 2 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 434 | 2 | DORIS_CHECK(adapter); | 435 | | | 436 | 2 | adapter->init(config); | 437 | 2 | return Status::OK(); | 438 | 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 | 414 | 3 | std::shared_ptr<AIAdapter>& adapter) const { | 415 | 3 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 416 | 3 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 417 | 3 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 418 | | | 419 | 3 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 420 | 3 | context->state()->get_query_ctx()->get_ai_resources(); | 421 | 3 | DORIS_CHECK(ai_resources); | 422 | 3 | auto it = ai_resources->find(resource_name); | 423 | 3 | DORIS_CHECK(it != ai_resources->end()); | 424 | 3 | PrimitiveType input_type = INVALID_TYPE; | 425 | 3 | if (arguments.size() > 1) { | 426 | 3 | input_type = | 427 | 3 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 428 | 3 | } | 429 | 3 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 430 | | | 431 | 3 | normalize_endpoint(config); | 432 | | | 433 | 3 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 434 | 3 | DORIS_CHECK(adapter); | 435 | | | 436 | 3 | adapter->init(config); | 437 | 3 | return Status::OK(); | 438 | 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 | 414 | 22 | std::shared_ptr<AIAdapter>& adapter) const { | 415 | 22 | const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]); | 416 | 22 | StringRef resource_name_ref = resource_column.column->get_data_at(0); | 417 | 22 | std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size); | 418 | | | 419 | 22 | const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources = | 420 | 22 | context->state()->get_query_ctx()->get_ai_resources(); | 421 | 22 | DORIS_CHECK(ai_resources); | 422 | 22 | auto it = ai_resources->find(resource_name); | 423 | 22 | DORIS_CHECK(it != ai_resources->end()); | 424 | 22 | PrimitiveType input_type = INVALID_TYPE; | 425 | 22 | if (arguments.size() > 1) { | 426 | 22 | input_type = | 427 | 22 | remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type(); | 428 | 22 | } | 429 | 22 | config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type); | 430 | | | 431 | 22 | normalize_endpoint(config); | 432 | | | 433 | 22 | adapter = AIAdapterFactory::create_adapter(config.provider_type); | 434 | 22 | DORIS_CHECK(adapter); | 435 | | | 436 | 22 | adapter->init(config); | 437 | 22 | return Status::OK(); | 438 | 22 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE |
439 | | |
440 | 90 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { |
441 | 90 | return AIResource(resource); |
442 | 90 | } _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 440 | 47 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 441 | 47 | return AIResource(resource); | 442 | 47 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 440 | 2 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 441 | 2 | return AIResource(resource); | 442 | 2 | } |
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 440 | 14 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 441 | 14 | return AIResource(resource); | 442 | 14 | } |
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 440 | 2 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 441 | 2 | return AIResource(resource); | 442 | 2 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 440 | 3 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 441 | 3 | return AIResource(resource); | 442 | 3 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE Line | Count | Source | 440 | 22 | AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const { | 441 | 22 | return AIResource(resource); | 442 | 22 | } |
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE |
443 | | |
444 | | // Serializes one text batch into the shared JSON-array prompt format consumed by LLM |
445 | | // providers for batch string functions. |
446 | | Status build_batch_prompt(const std::vector<std::string>& batch_prompts, |
447 | 24 | std::string& prompt) const { |
448 | 24 | rapidjson::StringBuffer buffer; |
449 | 24 | rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); |
450 | | |
451 | 24 | writer.StartArray(); |
452 | 48 | for (size_t i = 0; i < batch_prompts.size(); ++i) { |
453 | 24 | writer.StartObject(); |
454 | 24 | writer.Key("idx"); |
455 | 24 | writer.Uint64(i); |
456 | 24 | writer.Key("input"); |
457 | 24 | writer.String(batch_prompts[i].data(), |
458 | 24 | static_cast<rapidjson::SizeType>(batch_prompts[i].size())); |
459 | 24 | writer.EndObject(); |
460 | 24 | } |
461 | 24 | writer.EndArray(); |
462 | | |
463 | 24 | prompt = buffer.GetString(); |
464 | 24 | return Status::OK(); |
465 | 24 | } 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 | 447 | 24 | std::string& prompt) const { | 448 | 24 | rapidjson::StringBuffer buffer; | 449 | 24 | rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); | 450 | | | 451 | 24 | writer.StartArray(); | 452 | 48 | for (size_t i = 0; i < batch_prompts.size(); ++i) { | 453 | 24 | writer.StartObject(); | 454 | 24 | writer.Key("idx"); | 455 | 24 | writer.Uint64(i); | 456 | 24 | writer.Key("input"); | 457 | 24 | writer.String(batch_prompts[i].data(), | 458 | 24 | static_cast<rapidjson::SizeType>(batch_prompts[i].size())); | 459 | 24 | writer.EndObject(); | 460 | 24 | } | 461 | 24 | writer.EndArray(); | 462 | | | 463 | 24 | prompt = buffer.GetString(); | 464 | 24 | return Status::OK(); | 465 | 24 | } |
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_ |
466 | | }; |
467 | | |
468 | | } // namespace doris |