From fa52c16586774a6629993e80b46cc5f2d27a18e7 Mon Sep 17 00:00:00 2001 From: Jack Tysoe Date: Thu, 25 Jul 2024 13:45:46 +0100 Subject: [PATCH] fix bedrock lints --- kong/llm/drivers/bedrock.lua | 5 +---- kong/llm/drivers/gemini.lua | 7 ------- kong/plugins/ai-proxy/handler.lua | 1 - kong/tools/aws_stream.lua | 25 ++++++++++--------------- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/kong/llm/drivers/bedrock.lua b/kong/llm/drivers/bedrock.lua index ae981f87442d..21690fa32f54 100644 --- a/kong/llm/drivers/bedrock.lua +++ b/kong/llm/drivers/bedrock.lua @@ -6,10 +6,8 @@ local fmt = string.format local ai_shared = require("kong.llm.drivers.shared") local socket_url = require("socket.url") local string_gsub = string.gsub -local buffer = require("string.buffer") local table_insert = table.insert local string_lower = string.lower -local string_sub = string.sub local signer = require("resty.aws.request.sign") -- @@ -122,8 +120,7 @@ local function handle_stream_event(event_t, model_info, route_type) new_event = "[DONE]" - elseif event_type == "contentBlockStop" then - -- placeholder - I don't think this does anything yet + -- "contentBlockStop" is absent because it is not used for anything here end if new_event then diff --git a/kong/llm/drivers/gemini.lua b/kong/llm/drivers/gemini.lua index 107deb5fa94d..f76488dcb19c 100644 --- a/kong/llm/drivers/gemini.lua +++ b/kong/llm/drivers/gemini.lua @@ -41,13 +41,6 @@ local function is_response_content(content) and content.candidates[1].content.parts[1].text end -local function is_response_finished(content) - return content - and content.candidates - and #content.candidates > 0 - and content.candidates[1].finishReason -end - local function handle_stream_event(event_t, model_info, route_type) -- discard empty frames, it should either be a random new line, or comment if (not event_t.data) or (#event_t.data < 1) then diff --git a/kong/plugins/ai-proxy/handler.lua b/kong/plugins/ai-proxy/handler.lua index 5110c8bb951c..fccb66545f8a 100644 --- a/kong/plugins/ai-proxy/handler.lua +++ b/kong/plugins/ai-proxy/handler.lua @@ -5,7 +5,6 @@ local kong_utils = require("kong.tools.gzip") local kong_meta = require("kong.meta") local buffer = require "string.buffer" local strip = require("kong.tools.utils").strip -local to_hex = require("resty.string").to_hex -- cloud auth/sdk providers local GCP_SERVICE_ACCOUNT do diff --git a/kong/tools/aws_stream.lua b/kong/tools/aws_stream.lua index cee1c9ed4be0..719600277665 100644 --- a/kong/tools/aws_stream.lua +++ b/kong/tools/aws_stream.lua @@ -123,22 +123,20 @@ function Stream:next_message() -- this is a chicken and egg problem, because we need to -- read the message to get the length, to then re-read the -- whole message at correct offset - local msg_len, orig_len, err = self:next_int(32) + local msg_len, _, err = self:next_int(32) if err then return err end -- get the headers length - local headers_len, orig_headers_len, err = self:next_int(32) + local headers_len, _, err = self:next_int(32) + if err then + return err + end -- get the preamble checksum - local preamble_checksum, orig_preamble_checksum, err = self:next_int(32) - - -- TODO: calculate checksum - -- local result = crc32(orig_len .. origin_headers_len, preamble_checksum) - -- if not result then - -- return nil, "preamble checksum failed - message is corrupted" - -- end + -- skip it because we're not using UDP + self:next_int(32) -- pull the headers from the buf local headers = {} @@ -167,12 +165,9 @@ function Stream:next_message() local body = self:next_utf_8(msg_len - self.read_count - 4) -- last 4 bytes is a body checksum - local msg_checksum = self:next_int(32) - -- TODO CHECK FULL MESSAGE CHECKSUM - -- local result = crc32(original_full_msg, msg_checksum) - -- if not result then - -- return nil, "preamble checksum failed - message is corrupted" - -- end + -- skip it because we're not using UDP + self:next_int(32) + -- rewind the tape self.read_count = 0