Skip to content

Commit

Permalink
fix order
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineJac committed Jun 18, 2024
1 parent 8785af5 commit 2124a2b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions kong/llm/drivers/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ local log_entry_keys = {
RESPONSE_BODY = "response",

-- meta keys
PLUGIN_ID = "plugin_id",
PROVIDER_NAME = "provider_name",
REQUEST_MODEL = "request_model",
RESPONSE_MODEL = "response_model",
PROVIDER_NAME = "provider_name",
PLUGIN_ID = "plugin_id",

-- usage keys
PROCESSING_TIME = "processing_time",
PROMPT_TOKENS = "prompt_tokens",
COMPLETION_TOKENS = "completion_tokens",
TOTAL_TOKENS = "total_tokens",
Expand Down Expand Up @@ -481,7 +480,12 @@ function _M.post_request(conf, response_object)

-- create a new analytics structure for this plugin
local request_analytics_plugin = {
[log_entry_keys.META_CONTAINER] = {},
[log_entry_keys.META_CONTAINER] = {
[log_entry_keys.PLUGIN_ID] = "",
[log_entry_keys.PROVIDER_NAME] = "",
[log_entry_keys.REQUEST_MODEL] = "",
[log_entry_keys.RESPONSE_MODEL] = "",
},
[log_entry_keys.USAGE_CONTAINER] = {
[log_entry_keys.PROMPT_TOKENS] = 0,
[log_entry_keys.COMPLETION_TOKENS] = 0,
Expand All @@ -497,10 +501,10 @@ function _M.post_request(conf, response_object)
}

-- Set the model, response, and provider names in the current try context
request_analytics_plugin[log_entry_keys.META_CONTAINER][log_entry_keys.PLUGIN_ID] = conf.__plugin_id
request_analytics_plugin[log_entry_keys.META_CONTAINER][log_entry_keys.PROVIDER_NAME] = provider_name
request_analytics_plugin[log_entry_keys.META_CONTAINER][log_entry_keys.REQUEST_MODEL] = kong.ctx.plugin.llm_model_requested or conf.model.name
request_analytics_plugin[log_entry_keys.META_CONTAINER][log_entry_keys.RESPONSE_MODEL] = response_object.model or conf.model.name
request_analytics_plugin[log_entry_keys.META_CONTAINER][log_entry_keys.PROVIDER_NAME] = provider_name
request_analytics_plugin[log_entry_keys.META_CONTAINER][log_entry_keys.PLUGIN_ID] = conf.__plugin_id

-- set extra per-provider meta
if kong.ctx.plugin.ai_extra_meta and type(kong.ctx.plugin.ai_extra_meta) == "table" then
Expand Down Expand Up @@ -542,15 +546,15 @@ function _M.post_request(conf, response_object)
kong.ctx.shared.analytics = request_analytics

if conf.logging and conf.logging.log_statistics then
-- Log analytics data
kong.log.set_serialize_value(fmt("ai.%s.%s", plugin_name, log_entry_keys.USAGE_CONTAINER),
request_analytics_plugin[log_entry_keys.USAGE_CONTAINER])

-- Log meta
-- Log meta data
kong.log.set_serialize_value(fmt("ai.%s.%s", plugin_name, log_entry_keys.META_CONTAINER),
request_analytics_plugin[log_entry_keys.META_CONTAINER])

-- Log cache
-- Log usage data
kong.log.set_serialize_value(fmt("ai.%s.%s", plugin_name, log_entry_keys.USAGE_CONTAINER),
request_analytics_plugin[log_entry_keys.USAGE_CONTAINER])

-- Log cache data
kong.log.set_serialize_value(fmt("ai.%s.%s", plugin_name, log_entry_keys.CACHE_CONTAINER),
request_analytics_plugin[log_entry_keys.CACHE_CONTAINER])
end
Expand Down

0 comments on commit 2124a2b

Please sign in to comment.