Skip to content

Commit

Permalink
fix(*): fix conflicts of null-able checker on upstream_url and auth
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Aug 2, 2024
1 parent 973747a commit 0058c8e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kong/ai/embeddings/drivers/mistralai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ end
-- @return the API response containing the embeddings
-- @return nothing. throws an error if any
function Driver:generate(prompt)
if not self.auth or not self.auth.token then
-- allow auth to skip for custom upstream_url
if not self.upstream_url and (not self.auth or not self.auth.token) then
return nil, "Authorization is not defined for the mistralai driver"
end

Expand Down
3 changes: 2 additions & 1 deletion kong/ai/embeddings/drivers/openai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ end
-- @return the API response containing the embeddings
-- @return nothing. throws an error if any
function Driver:generate(prompt)
if not self.auth or not self.auth.token then
-- allow auth to skip for custom upstream_url
if not self.upstream_url and (not self.auth or not self.auth.token) then
return nil, "Authorization is not defined for the openai driver"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe(PLUGIN_NAME .. ": (schema)", function()

assert.is_falsy(ok)
assert.not_nil(err)
assert.same({ config = { embeddings = { ["@entity"] = {"failed conditional validation given value of field 'driver'"}, upstream_url = "value must be null"}, rules = {allow_prompts = { [1] = "length must be at most 500" }}}}, err)
assert.same({ config = { rules = {allow_prompts = { [1] = "length must be at most 500" }}}}, err)
end)

it("won't allow too many array items", function()
Expand Down

0 comments on commit 0058c8e

Please sign in to comment.