membphis commented on code in PR #12030: URL: https://github.com/apache/apisix/pull/12030#discussion_r1988862485
########## apisix/plugins/ai-proxy/base.lua: ########## @@ -15,84 +15,43 @@ -- limitations under the License. -- -local CONTENT_TYPE_JSON = "application/json" local core = require("apisix.core") +local require = require local bad_request = ngx.HTTP_BAD_REQUEST local internal_server_error = ngx.HTTP_INTERNAL_SERVER_ERROR -local schema = require("apisix.plugins.ai-proxy.schema") -local ngx_print = ngx.print -local ngx_flush = ngx.flush - -local function keepalive_or_close(conf, httpc) - if conf.set_keepalive then - httpc:set_keepalive(10000, 100) - return - end - httpc:close() -end local _M = {} -function _M.new(proxy_request_to_llm_func, get_model_name_func) - return function(conf, ctx) - local ct = core.request.header(ctx, "Content-Type") or CONTENT_TYPE_JSON - if not core.string.has_prefix(ct, CONTENT_TYPE_JSON) then - return bad_request, "unsupported content-type: " .. ct - end - - local request_table, err = core.request.get_json_request_body_table() - if not request_table then - return bad_request, err - end - - local ok, err = core.schema.check(schema.chat_request_schema, request_table) - if not ok then - return bad_request, "request format doesn't match schema: " .. err - end - - request_table.model = get_model_name_func(conf) +function _M.before_proxy(conf, ctx) + local ai_instance = ctx.picked_ai_instance + local ai_driver = require("apisix.plugins.ai-drivers." .. ai_instance.provider) Review Comment: This may failed, we need to check the return value or use pcall -- 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: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org