Skip to content

Commit

Permalink
edit cost name
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineJac committed Jun 17, 2024
1 parent 06bbcbe commit cd85513
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions kong/llm/drivers/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ local log_entry_keys = {
PROMPT_TOKENS = "prompt_tokens",
COMPLETION_TOKENS = "completion_tokens",
TOTAL_TOKENS = "total_tokens",
COST_REQUEST = "cost_request",
COST = "cost",

-- cache keys
VECTOR_DB = "vector_db",
Expand Down Expand Up @@ -486,7 +486,7 @@ function _M.post_request(conf, response_object)
[log_entry_keys.PROMPT_TOKENS] = 0,
[log_entry_keys.COMPLETION_TOKENS] = 0,
[log_entry_keys.TOTAL_TOKENS] = 0,
[log_entry_keys.COST_REQUEST] = 0,
[log_entry_keys.COST] = 0,
},
[log_entry_keys.CACHE_CONTAINER] = {
[log_entry_keys.VECTOR_DB] = "",
Expand Down Expand Up @@ -523,7 +523,7 @@ function _M.post_request(conf, response_object)

if response_object.usage.prompt_tokens and response_object.usage.completion_tokens
and conf.model.options.input_cost and conf.model.options.output_cost then
request_analytics_plugin[log_entry_keys.TOKENS_CONTAINER][log_entry_keys.COST_REQUEST] =
request_analytics_plugin[log_entry_keys.TOKENS_CONTAINER][log_entry_keys.COST] =
(response_object.usage.prompt_tokens * conf.model.options.input_cost
+ response_object.usage.completion_tokens * conf.model.options.output_cost) / 1000000 -- 1 million
end
Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/prometheus/exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ local function log(message, serialized)
labels_table_ai_llm_status[7] = workspace
metrics.ai_llm_requests:inc(1, labels_table_ai_llm_status)

if ai_plugin.usage.cost_request and ai_plugin.usage.cost_request > 0 then
metrics.ai_llm_cost:inc(ai_plugin.usage.cost_request, labels_table_ai_llm_status)
if ai_plugin.usage.cost and ai_plugin.usage.cost > 0 then
metrics.ai_llm_cost:inc(ai_plugin.usage.cost, labels_table_ai_llm_status)
end

labels_table_ai_llm_tokens[1] = ai_plugin.meta.provider_name
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/38-ai-proxy/02-openai_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ local _EXPECTED_CHAT_STATS = {
},
usage = {
completion_tokens = 12,
cost_request = 0.00037,
cost = 0.00037,
prompt_tokens = 25,
total_tokens = 37,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ local _EXPECTED_CHAT_STATS = {
},
usage = {
completion_tokens = 12,
cost_request = 0.00037,
cost = 0.00037,
prompt_tokens = 25,
total_tokens = 37,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ local _EXPECTED_CHAT_STATS = {
},
usage = {
completion_tokens = 12,
cost_request = 0.00037,
cost = 0.00037,
prompt_tokens = 25,
total_tokens = 37,
},
Expand Down

0 comments on commit cd85513

Please sign in to comment.