From 142eb5f67b221dca277fb1dd0ab448f8e695d3ca Mon Sep 17 00:00:00 2001 From: Jack Tysoe Date: Sun, 14 Apr 2024 21:19:59 +0100 Subject: [PATCH] fix(rebase): solve conflicts with #12792 --- kong/llm/drivers/shared.lua | 14 +------------- kong/plugins/ai-proxy/handler.lua | 5 ++++- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/kong/llm/drivers/shared.lua b/kong/llm/drivers/shared.lua index 5162081eecd4..663498385187 100644 --- a/kong/llm/drivers/shared.lua +++ b/kong/llm/drivers/shared.lua @@ -293,12 +293,6 @@ function _M.post_request(conf, response_object) body_string = response_object.response or "ERROR__NOT_SET" end - local provider_length = conf.model.provider and #conf.model.provider or 0 - - if conf.logging and conf.logging.log_payloads then - kong.log.set_serialize_value(conf.model.provider[provider_length].log_entry_keys.RESPONSE_BODY, body_string) - end - -- analytics and logging if conf.logging and conf.logging.log_statistics then -- check if we already have analytics in this context @@ -335,12 +329,6 @@ function _M.post_request(conf, response_object) -- Get the current try count local try_count = request_analytics_provider.number_of_instances - -- Decode the response string - local response_object, err = cjson.decode(response_string) - if err then - return nil, "failed to decode response from JSON" - end - -- Set the model, response, and provider names in the current try context current_try[log_entry_keys.META_CONTAINER][log_entry_keys.REQUEST_MODEL] = conf.model.name current_try[log_entry_keys.META_CONTAINER][log_entry_keys.RESPONSE_MODEL] = response_object.model or conf.model.name @@ -365,7 +353,7 @@ function _M.post_request(conf, response_object) -- Log response body if logging payloads is enabled if conf.logging and conf.logging.log_payloads then - current_try[log_entry_keys.RESPONSE_BODY] = response_string + current_try[log_entry_keys.RESPONSE_BODY] = body_string end -- Store the split key data in instances diff --git a/kong/plugins/ai-proxy/handler.lua b/kong/plugins/ai-proxy/handler.lua index aef6883cacc2..d3b9dce498c1 100644 --- a/kong/plugins/ai-proxy/handler.lua +++ b/kong/plugins/ai-proxy/handler.lua @@ -141,7 +141,10 @@ function _M:body_filter(conf) end -- call with replacement body, or original body if nothing changed - ai_shared.post_request(conf, original_request) + local _, err = ai_shared.post_request(conf, original_request) + if err then + kong.log.warn("analytics phase failed for request, ", err) + end end kong.ctx.plugin.body_called = true