From f3d71c5bdaa80c41f938ae9e6d7df0f050ee5ccc Mon Sep 17 00:00:00 2001 From: Jack Tysoe Date: Wed, 5 Jun 2024 19:34:49 +0100 Subject: [PATCH] fix(ai-proxy): correct model check precedence --- kong/plugins/ai-proxy/handler.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kong/plugins/ai-proxy/handler.lua b/kong/plugins/ai-proxy/handler.lua index 7e65dafc3245..cbe0727983ae 100644 --- a/kong/plugins/ai-proxy/handler.lua +++ b/kong/plugins/ai-proxy/handler.lua @@ -343,13 +343,6 @@ function _M:access(conf) return bad_request(err) end - -- check that the user isn't trying to override the plugin conf model in the request body - if request_table and request_table.model and type(request_table.model) == "string" then - if request_table.model ~= conf_m.model.name then - return bad_request("cannot use own model - must be: " .. conf_m.model.name) - end - end - -- copy from the user request if present if (not multipart) and (not conf_m.model.name) and (request_table.model) then conf_m.model.name = request_table.model @@ -357,6 +350,13 @@ function _M:access(conf) conf_m.model.name = "NOT_SPECIFIED" end + -- check that the user isn't trying to override the plugin conf model in the request body + if request_table and request_table.model and type(request_table.model) == "string" then + if request_table.model ~= conf_m.model.name then + return bad_request("cannot use own model - must be: " .. conf_m.model.name) + end + end + -- model is stashed in the copied plugin conf, for consistency in transformation functions if not conf_m.model.name then return bad_request("model parameter not found in request, nor in gateway configuration")