-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0446f9f
commit 1865a5c
Showing
3 changed files
with
61 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 55 additions & 48 deletions
103
spec/05-migration/plugins/ai-proxy/migrations/001_360_to_370_spec.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |