|
16 | 16 | -- |
17 | 17 | local schema_def = require("apisix.schema_def") |
18 | 18 | local ai_providers_schema = require("apisix.plugins.ai-providers.schema") |
| 19 | +local protocols = require("apisix.plugins.ai-protocols") |
| 20 | +local pairs = pairs |
19 | 21 |
|
20 | 22 | local _M = {} |
21 | 23 |
|
@@ -72,6 +74,40 @@ local model_options_schema = { |
72 | 74 | additionalProperties = true, |
73 | 75 | } |
74 | 76 |
|
| 77 | +-- Build per-target-protocol request body override schema. |
| 78 | +-- Each registered protocol gets an optional "any-shape object" entry. |
| 79 | +-- Values are applied via deep-merge after the model_options flat overwrite. |
| 80 | +local request_body_override_properties = {} |
| 81 | +for _, proto_name in pairs(protocols.names()) do |
| 82 | + request_body_override_properties[proto_name] = { |
| 83 | + type = "object", |
| 84 | + description = "Deep-merged into the outgoing request body when the " |
| 85 | + .. "target protocol is '" .. proto_name .. "'.", |
| 86 | + additionalProperties = true, |
| 87 | + } |
| 88 | +end |
| 89 | + |
| 90 | +local request_body_override_schema = { |
| 91 | + type = "object", |
| 92 | + description = "Per target-protocol request body overrides. Keys are target " |
| 93 | + .. "protocol names; values are partial request bodies that are " |
| 94 | + .. "deep-merged into the outgoing body (objects merged recursively, " |
| 95 | + .. "arrays and scalars replaced wholesale).", |
| 96 | + properties = request_body_override_properties, |
| 97 | + additionalProperties = false, |
| 98 | +} |
| 99 | + |
| 100 | +local override_schema = { |
| 101 | + type = "object", |
| 102 | + properties = { |
| 103 | + endpoint = { |
| 104 | + type = "string", |
| 105 | + description = "To be specified to override the endpoint of the AI Instance", |
| 106 | + }, |
| 107 | + request_body = request_body_override_schema, |
| 108 | + }, |
| 109 | +} |
| 110 | + |
75 | 111 | local provider_vertex_ai_schema = { |
76 | 112 | type = "object", |
77 | 113 | properties = { |
@@ -115,15 +151,7 @@ local ai_instance_schema = { |
115 | 151 | }, |
116 | 152 | auth = auth_schema, |
117 | 153 | options = model_options_schema, |
118 | | - override = { |
119 | | - type = "object", |
120 | | - properties = { |
121 | | - endpoint = { |
122 | | - type = "string", |
123 | | - description = "To be specified to override the endpoint of the AI Instance", |
124 | | - }, |
125 | | - }, |
126 | | - }, |
| 154 | + override = override_schema, |
127 | 155 | checks = { |
128 | 156 | type = "object", |
129 | 157 | properties = { |
@@ -192,15 +220,7 @@ _M.ai_proxy_schema = { |
192 | 220 | }, |
193 | 221 | keepalive_pool = {type = "integer", minimum = 1, default = 30}, |
194 | 222 | ssl_verify = {type = "boolean", default = true }, |
195 | | - override = { |
196 | | - type = "object", |
197 | | - properties = { |
198 | | - endpoint = { |
199 | | - type = "string", |
200 | | - description = "To be specified to override the endpoint of the AI Instance", |
201 | | - }, |
202 | | - }, |
203 | | - }, |
| 223 | + override = override_schema, |
204 | 224 | }, |
205 | 225 | required = {"provider", "auth"}, |
206 | 226 | encrypt_fields = {"auth.header", "auth.query", "auth.gcp.service_account_json"}, |
|
0 commit comments