-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ai-proxy): prevent shared state #13028
base: master
Are you sure you want to change the base?
Conversation
e75c662
to
83b9d80
Compare
The object initializer (new) would set properties on the parent instead of on the instance.
-- @treturn[2] nil | ||
-- @treturn[2] string An error message if instantiation failed | ||
function _M.new_driver(conf, http_opts) | ||
local self = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment to reviewers: self
was pointing to _M
in the old code. So setting self.conf
, self.http_opts
, and self.driver
would actually modify the class, and not the instance.
if not ai_driver then | ||
return internal_server_error(err) | ||
end | ||
|
||
-- if asked, introspect the request before proxying | ||
kong.log.debug("introspecting request with LLM") | ||
local new_request_body, err = llm:ai_introspect_body( | ||
local new_request_body, err = ai_driver:ai_introspect_body( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment to reviewers: The old code would call on llm
(the class) instead of on ai_driver
(the instance).
@@ -123,7 +129,7 @@ function _M:access(conf) | |||
-- if asked, introspect the request before proxying | |||
kong.log.debug("introspecting response with LLM") | |||
|
|||
local new_response_body, err = llm:ai_introspect_body( | |||
local new_response_body, err = ai_driver:ai_introspect_body( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment to reviewers: The old code would call on llm
(the class) instead of on ai_driver
(the instance).
return internal_server_error(err) | ||
kong_ctx_shared.skip_response_transformer = true | ||
kong.log.err("failed to configure request for AI service: ", err) | ||
return kong.response.exit(500) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we response with the error message?
return kong.response.exit(500) | |
return kong.response.exit(500, { error = { message = err } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is an internal server error. Targeted at the admin of the system (hence the log line), it is of no concern for the end user.
@@ -0,0 +1,3 @@ | |||
message: "**AI-Proxy**: object constructor would set data on the class instead of the instance" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not necessary to have a changelog for an internal refracting PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bugfix, so the changelog should be here imho
The object initializer (new) would set properties on class instead of on the instance. Also cleans up some code.
I have added comments on the actual bug, everything else is cosmetic/cleanup. Please review with whitespace changes disabled in the github UI.
Summary
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Internal ticket: AG-44