Skip to content

feat: add ai-request-rewrite plugin#12036

Merged
LiteSun merged 43 commits into
apache:masterfrom
LiteSun:add-ai-proxy-plugin
Mar 24, 2025
Merged

feat: add ai-request-rewrite plugin#12036
LiteSun merged 43 commits into
apache:masterfrom
LiteSun:add-ai-proxy-plugin

Conversation

@LiteSun

@LiteSun LiteSun commented Mar 11, 2025

Copy link
Copy Markdown
Member

Description

The ai-request-rewrite plugin leverages predefined prompts and AI services to intelligently modify client requests, enabling AI-powered content transformation before forwarding to upstream services.

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 first)

@LiteSun LiteSun changed the title add ai-request-rewrite plugin feat: add ai-request-rewrite plugin Mar 12, 2025
@LiteSun
LiteSun requested a review from membphis March 19, 2025 11:00
membphis
membphis previously approved these changes Mar 20, 2025

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pls fix some minor issues

Comment thread apisix/plugins/ai-request-rewrite.lua Outdated
error_msg = error_msg .. ", err: " .. err
end
return HTTP_BAD_REQUEST, error_msg
core.log.error("LLM service returned error status: ", res.status, ", ", resp_body)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to remove resp_body, it is big

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to remove resp_body, it is big

Logging the response body would make it easier to identify issues. For example, a 400 error can occur for various reasons, and the returned message can help pinpoint the problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main identification here is the response code, which has nothing to do with the response body. So, recording the response body in the log will not provide any other obvious help.

In addition, the response body itself is relatively large and may contain sensitive business information, which is not suitable for recording in the error log.

moonming
moonming previously approved these changes Mar 20, 2025
@LiteSun
LiteSun dismissed stale reviews from moonming and membphis via 92e08b4 March 21, 2025 02:11
Comment thread apisix/plugins/ai-request-rewrite.lua Outdated
Comment thread apisix/plugins/ai-request-rewrite.lua Outdated
Comment thread apisix/plugins/ai-request-rewrite.lua Outdated
Comment thread t/plugin/ai-request-rewrite.t Outdated
nic-6443
nic-6443 previously approved these changes Mar 21, 2025
moonming
moonming previously approved these changes Mar 21, 2025
Comment thread apisix/plugins/ai-request-rewrite.lua Outdated
function _M.access(conf, ctx)
local client_request_body, err = core.request.get_body()
if err then
core.log.info("failed to get request body: ", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use core.log.warn

Comment thread apisix/plugins/ai-request-rewrite.lua Outdated
local client_request_body, err = core.request.get_body()
if err then
core.log.info("failed to get request body: ", err)
return HTTP_BAD_REQUEST, err

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove err

@LiteSun
LiteSun dismissed stale reviews from moonming and nic-6443 via 17e9cd8 March 21, 2025 10:08
@LiteSun
LiteSun merged commit 8179784 into apache:master Mar 24, 2025
laz-xyr pushed a commit to laz-xyr/apisix that referenced this pull request Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request plugin size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants