Skip to content

Commit

Permalink
add testst p
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Aug 15, 2024
1 parent 57c7224 commit 83ec366
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kong/llm/drivers/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -848,4 +848,7 @@ function _M.calculate_cost(query_body, tokens_models, tokens_factor)
return query_cost, nil
end

-- for unit tests
_M._count_words = count_words

return _M
43 changes: 43 additions & 0 deletions spec/03-plugins/38-ai-proxy/01-unit_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,47 @@ describe(PLUGIN_NAME .. ": (unit)", function()

end)

describe("count_words", function()
local c = ai_shared._count_words

it("normal prompts", function()
assert.same(10, c(string.rep("apple ", 10)))
end)

it("multi-modal prompts", function()
assert.same(10, c({
{
type = "text",
text = string.rep("apple ", 10),
},
}))

assert.same(20, c({
{
type = "text",
text = string.rep("apple ", 10),
},
{
type = "text",
text = string.rep("banana ", 10),
},
}))

assert.same(10, c({
{
type = "not_text",
text = string.rep("apple ", 10),
},
{
type = "text",
text = string.rep("banana ", 10),
},
{
type = "text",
-- somehow malformed
},
}))
end)
end)

end)

0 comments on commit 83ec366

Please sign in to comment.