github-actions[bot] commented on code in PR #69302:
URL: https://github.com/apache/doris/pull/69302#discussion_r4317656211


##########
be/src/exprs/function/ai/ai_adapter.h:
##########
@@ -869,16 +970,64 @@ class OpenAIAdapter : public VoyageAIAdapter {
             doc.AddMember("messages", messages, allocator);
         }
 
-        rapidjson::StringBuffer buffer;
-        rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
-        doc.Accept(writer);
-        request_body = buffer.GetString();
+        if (structured_batch) {
+            // These complete format fragments are compile-time constants. 
RawValue writes
+            // them unchanged on every request; no schema construction or 
parsing is needed.
+            /* {
+              "type": "json_schema", "name": "ai_batch_result", "strict": true,
+              "schema": {
+                  "type": "object",
+                  "properties": {"results": {"type": "array", "items": 
{"type": "string"}}},
+                  "required": ["results"],
+                  "additionalProperties": false
+                }
+            } */
+            static constexpr std::string_view responses_format =
+                    
R"({"type":"json_schema","name":"ai_batch_result","strict":true,"schema":{"type":"object","properties":{"results":{"type":"array","items":{"type":"string"}}},"required":["results"],"additionalProperties":false}})";
+            /* {
+              "type": "json_schema",
+              "json_schema": {
+                "name": "ai_batch_result", "strict": true,
+                "schema": {
+                  "type": "object",
+                  "properties": {"results": {"type": "array", "items": 
{"type": "string"}}},
+                  "required": ["results"],
+                  "additionalProperties": false
+                }
+              }
+            } */
+            static constexpr std::string_view chat_format =
+                    
R"({"type":"json_schema","json_schema":{"name":"ai_batch_result","strict":true,"schema":{"type":"object","properties":{"results":{"type":"array","items":{"type":"string"}}},"required":["results"],"additionalProperties":false}}})";
+            if (_config.endpoint.ends_with("responses")) {
+                append_result_format(doc, request_body, "format", 
responses_format, "text");
+            } else if (_chat_json_schema) {
+                append_result_format(doc, request_body, "response_format", 
chat_format);

Review Comment:
   [P1] Gate Chat JSON Schema on the configured model's capability
   
   `QwenAdapter` inherits `OpenAIAdapter(true)`, so an existing QWEN resource 
using `qwen-turbo` at the compatible Chat Completions endpoint now sends 
`response_format.type=json_schema` on every scalar batch. [Alibaba's 
supported-model 
matrix](https://www.alibabacloud.com/help/en/model-studio/qwen-structured-output)
 lists Qwen-Turbo under JSON Object mode and restricts JSON Schema to newer 
model series. Since missing resource properties default to true, upgrading 
changes previously working requests into unsupported ones; users must manually 
ALTER the resource to false to recover. Select `json_object`/prompt-only 
constraints for models without schema support, or require explicit opt-in for 
the incompatible mode, while retaining the results envelope.



##########
be/src/exprs/function/ai/ai_functions.h:
##########
@@ -238,12 +255,14 @@ class AIFunction : public IFunction {
         std::vector<std::string> parsed_response;
 
         std::string request_body;
+        // Disabling provider format constraints keeps batching and the output 
protocol intact.
         RETURN_IF_ERROR(adapter->build_request_payload(
-                inputs, assert_cast<const Derived&>(*this).system_prompt, 
request_body));
+                inputs, 
batch_system_prompt(adapter->supports_structured_batch()), request_body,
+                config.enable_structured_output && 
adapter->supports_structured_batch()));
 
         std::string response;
         RETURN_IF_ERROR(send_request_to_llm(request_body, response, config, 
adapter, context));
-        RETURN_IF_ERROR(adapter->parse_response(response, parsed_response));
+        RETURN_IF_ERROR(adapter->parse_batch_response(response, 
parsed_response));

Review Comment:
   [P2] Update the existing scalar HTTP fixture to the results envelope
   
   
`AIRequestExecutorTest.ScalarReusesConnectionAcrossBatchesAndBlocksWithNulls` 
still returns `message.content = ["summary"]` 
(be/test/ai/ai_request_executor_test.cpp:289). It uses `OpenAIAdapter` and 
reaches this call through `FunctionAISummarize::execute`, so 
`parse_batch_response` now rejects the array root and the first `ASSERT_TRUE` 
at line 299 fails. Please update that fixture to return 
`{"results":["summary"]}` so the existing batch/Block connection-reuse, 
nullable-row and cleanup assertions can run under the new protocol.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to