Skip to content

Commit

Permalink
update changlog
Browse files Browse the repository at this point in the history
  • Loading branch information
liverpool8056 committed Apr 18, 2024
1 parent 0446f9f commit 1865a5c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 53 deletions.
5 changes: 4 additions & 1 deletion changelog/unreleased/migration_of_ai_proxy_plugin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
message: |
**AI-proxy**: A configuration validation is added to prevent from enabling `log_statistics` upon providers not supporting statistics. Accordingly, the default of `log_statistics` is changed from `true` to `false`, and a database migration is added as well for disabling `log_statistics` if it has bee enabling upon unsupported providers.
**AI-proxy**: A configuration validation is added to prevent from enabling `log_statistics` upon
providers not supporting statistics. Accordingly, the default of `log_statistics` is changed from
`true` to `false`, and a database migration is added as well for disabling `log_statistics` if it
has already been enabled upon unsupported providers.
type: bugfix
6 changes: 2 additions & 4 deletions kong/plugins/ai-proxy/migrations/001_360_to_370.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local operations = require "kong.db.migrations.operations.200_to_210"
local ops = require("kong.db.migrations.operations.200_to_210.lua")

local function update_logging_statistic(config)
if config.logging.log_statistics and config.route_type == "llm/v1/completions"
Expand All @@ -8,12 +8,10 @@ local function update_logging_statistic(config)
end
end


return {
postgres = {
up = "",
teardown = function(connector)
operations.postgres.teardown:fixup_plugin_config(connector, "ai-proxy", update_logging_statistic)
ops.postgres.teardown:fixup_plugin_config(connector, "ai-proxy", update_logging_statistic)
end
}
}
103 changes: 55 additions & 48 deletions spec/05-migration/plugins/ai-proxy/migrations/001_360_to_370_spec.lua
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
local uh = require "spec.upgrade_helpers"
local helpers = require "spec.helpers"
local pgmoon_json = require("pgmoon.json")
local uuid = require "resty.jit-uuid"

for _, strategy in helpers.each_strategy() do
local strategy = "postgres"

local function render(template, keys)
return (template:gsub("$%(([A-Z_]+)%)", keys))
end

if uh.database_type() == strategy then
describe("ai-proxy plugin migration", function()
local db, ai_proxy_plugin
uh.setup(function()
_, db = helpers.get_db_utils(strategy, {"plugins"}, { "ai-proxy" })
local plugin, err, err_t = db.plugins:insert {
name = "ai-proxy",
config = {
route_type = "llm/v1/completions",
auth = {
header_name = "x-api-key",
header_value = "anthropic-key",
},
model = {
name = "claude-2.1",
provider = "anthropic",
options = {
max_tokens = 256,
temperature = 1.0,
upstream_url = "http://example.com/llm/v1/completions/good",
anthropic_version = "2023-06-01",
},
},
logging = {
log_statistics = true, -- anthropic does not support statistics
},
local plugin_name = "ai-proxy"
local plugin_config = {
route_type = "llm/v1/completions",
auth = {
header_name = "x-api-key",
header_value = "anthropic-key",
},
model = {
name = "claude-2.1",
provider = "anthropic",
options = {
max_tokens = 256,
temperature = 1.0,
upstream_url = "http://example.com/llm/v1/completions/good",
anthropic_version = "2023-06-01",
},
}
assert.is_nil(err)
assert.is_nil(err_t)
assert.is_not_nil(plugin)
ai_proxy_plugin = plugin
end)
},
logging = {
log_statistics = true, -- anthropic does not support statistics
},
}

uh.new_after_up("has updated ai-proxy plugin configuration", function ()
-- local cache_key = db.plugins:cache_key("ai-proxy")
local plugin, err = db.plugins:select({ id = ai_proxy_plugin.id })
uh.setup(function()
local _, db = helpers.get_db_utils(strategy, { "plugins" })
local id = uuid.generate_v4()
local sql = render([[
INSERT INTO plugins (id, name, config, enabled) VALUES
('$(ID)', '$(PLUGIN_NAME)', $(CONFIG)::jsonb, TRUE);
COMMIT;
]], {
ID = id,
PLUGIN_NAME = plugin_name,
CONFIG = pgmoon_json.encode_json(plugin_config),
})

local res, err = db.connector:query(sql)
assert.is_nil(err)
assert.is_not_nil(plugin)
-- assert.equal(1, #rows)
assert.is_not_nil(res)
end)

assert.equal("ai-proxy", plugin.name)
local expected_config = {
logging = {
log_statistics = false
},
route_type = "llm/v1/completions",
model = {
provider = "anthropic"
}
}
uh.new_after_finish("has updated ai-proxy plugin configuration", function ()
for plugin, err in helpers.db.connector:iterate("SELECT id, name, config FROM plugins") do
if err then
return nil, err
end

assert.partial_match(expected_config, plugin.config)
if plugin.name == 'ai-proxy' then
assert.falsy(plugin.config.logging.log_statistics)
end
end
end)
end)
end
end

0 comments on commit 1865a5c

Please sign in to comment.