-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(plugins): ai-proxy-plugin #12323
Conversation
a074d1c
to
d9b303e
Compare
2fc22cd
to
3b1216c
Compare
@fffonion Anything else for me to do here? |
c634c5c
to
7d6b50a
Compare
4b3f822
to
949a161
Compare
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.
This is great! 🚀
None of my comments are real blockers to merge this PR, just some suggestions.
kong/llm/drivers/cohere.lua
Outdated
|
||
if type(body) == "table" then | ||
body_string, err = cjson.encode(body) | ||
if err then return nil, nil, "failed to parse body to json: " .. err end |
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.
if err then return nil, nil, "failed to parse body to json: " .. err end | |
if err then | |
return nil, nil, "failed to parse body to json: " .. err | |
end |
|
||
local _M = {} | ||
|
||
local auth_schema = { |
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.
The schemas could go to their own file to keep this file cleaner.
77b23dd
to
f5be8e6
Compare
f83b2e9
to
a25535c
Compare
Successfully created cherry-pick PR for |
Summary
This commit transforms and proxies requests to a number of AI / LLM providers and models.
It adds a plugin that takes requests in one of a few defined and standardised formats, translates them to the configured target format, and then transforms the response back into a standard format.
The request/response formats are based on OpenAI, and conform to the JSON schema in the fixtures
There is a sample API specification to describe the suported formats also
The plugin controls:
config.model.options.upstream_url
)kong.log
entries, which will then output via any configured logging platform e.g. file-log, kafka-log...The reasoning for trying to flatten all provider formats, is that it allows standardised manipulation of the data before and after transmission.
It currently supports
v1/chat
andv1/completion
style requests for all available providers. Each provider implementation class is in its own module underkong.plugins.ai-proxy.drivers
.You can also set mode
preserve
to pass through, and the plugin will perform a best-effort to conform to the chosenconfig.model.provider
, based on the configured header patterns and values. This may need re-thinking, please provide input on this.This implementation only supports REST-based full text responses, but streaming support could be added based upon adoption, as with Kong >3.0 we can now process WebSocket frames.
Ideal documentation (docs.konghq.com) is being finalised internally, will be ready soon.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.md