Re: [PR] refactor(ai): ai-proxy and ai-proxy-multi [apisix]
shreemaan-abhishek commented on code in PR #12030:
URL: https://github.com/apache/apisix/pull/12030#discussion_r190194
##
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(1, 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 line guarantees safety:
https://github.com/apache/apisix/pull/12030/files#diff-6df73662ffc3d9815275bcf80c1ed0cebc86ce2dea275087cd299c6dea3b465aR73
--
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]
Re: [PR] refactor(ai): ai-proxy and ai-proxy-multi [apisix]
shreemaan-abhishek merged PR #12030: URL: https://github.com/apache/apisix/pull/12030 -- 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]
Re: [PR] refactor(ai): ai-proxy and ai-proxy-multi [apisix]
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(1, 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
[PR] refactor(ai): ai-proxy and ai-proxy-multi [apisix]
shreemaan-abhishek opened a new pull request, #12030: URL: https://github.com/apache/apisix/pull/12030 ### Description Fixes # (issue) ### Checklist - [ ] I have explained the need for this PR and the problem it solves - [ ] I have explained the changes or the new features added to this PR - [ ] I have added tests corresponding to this change - [ ] I have updated the documentation to reflect this change - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first) -- 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]
