-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(*): change ai analytics #12583
Conversation
|
By using the AI request and response transformers you will get following logs: When using same AI provider: "ai": {
"cohere": {
"instances": [
{
"meta": {
"response_model": "command",
"provider_name": "cohere",
"request_model": "command"
},
"usage": {
"completion_tokens": 33,
"prompt_tokens": 129,
"total_tokens": 162
}
},
{
"meta": {
"response_model": "command",
"provider_name": "cohere",
"request_model": "command"
},
"usage": {
"completion_tokens": 25,
"prompt_tokens": 412,
"total_tokens": 437
}
}
],
"request_prompt_tokens": 541,
"request_completion_tokens": 58,
"request_total_tokens": 599,
"number_of_instances": 2
}
} When using different AI providers:
EDIT: JSON formatting |
Would it be possible to also store the |
a1798fc
to
70c46ef
Compare
935038c
to
bbfe32e
Compare
bbfe32e
to
142eb5f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rebase'd and added a test - this is good to go now!
Co-authored-by: Joshua Schmid <jaiks@posteo.de>
It seems we have resolved all the points. Are we ok to push this PR? @jschmid1 |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-12583-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-12583-to-master-to-upstream
git checkout -b cherry-pick-12583-to-master-to-upstream
ancref=$(git merge-base 1b920ca144aed6669b2b1dbe5003683b4fcd18d3 9f3ab14f104e81d317aa6f2cc2d8337f5e72178a)
git cherry-pick -x $ancref..9f3ab14f104e81d317aa6f2cc2d8337f5e72178a |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-12583-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-12583-to-master-to-upstream
git checkout -b cherry-pick-12583-to-master-to-upstream
ancref=$(git merge-base 1b920ca144aed6669b2b1dbe5003683b4fcd18d3 9f3ab14f104e81d317aa6f2cc2d8337f5e72178a)
git cherry-pick -x $ancref..9f3ab14f104e81d317aa6f2cc2d8337f5e72178a |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-12583-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-12583-to-master-to-upstream
git checkout -b cherry-pick-12583-to-master-to-upstream
ancref=$(git merge-base 1b920ca144aed6669b2b1dbe5003683b4fcd18d3 9f3ab14f104e81d317aa6f2cc2d8337f5e72178a)
git cherry-pick -x $ancref..9f3ab14f104e81d317aa6f2cc2d8337f5e72178a |
@jschmid1 thanks could you please cherry pick and merge to EE? Thanks |
@jschmid1 This squashed commit is missing the component in the scope, please watch out next time :) |
This is a fixed of #12583 We need to refactor as many observability providers do not simplify ingest array. Here is a new nested format: Current model is: ```json "ai": { "mistral": { "request_total_tokens": 648, "number_of_instances": 1, "instances": [ { "meta": { "request_model": "mistral-tiny", "plugin_id": "1c783122-0223-4a03-9f1d-c71d2baab01e", "response_model": "mistral-tiny", "provider_name": "mistral" }, "usage": { "prompt_token": 392, "total_tokens": 648, "completion_token": 256 } } ], "request_prompt_tokens": 392, "request_completion_tokens": 256 }, "azure": { "request_total_tokens": 145, "number_of_instances": 1, "instances": [ { "meta": { "request_model": "gpt-35-turbo", "plugin_id": "5df193be-47a3-4f1b-8c37-37e31af0568b", "response_model": "gpt-35-turbo", "provider_name": "azure" }, "usage": { "prompt_token": 89, "total_tokens": 145, "completion_token": 56 } } ], "request_prompt_tokens": 89, "request_completion_tokens": 56 }, "cohere": { "request_total_tokens": 149, "number_of_instances": 1, "instances": [ { "meta": { "request_model": "command", "plugin_id": "30a63ab9-03c6-447a-9b25-195eb0acaeb2", "response_model": "command", "provider_name": "cohere" }, "usage": { "prompt_token": 78, "total_tokens": 149, "completion_token": 71 } } ], "request_prompt_tokens": 78, "request_completion_tokens": 71 } } ``` New model if using several plugins: ```json "ai": { "ai-request-transformer": { "meta": { "request_model": "gpt-35-turbo", "provider_name": "azure", "response_model": "gpt-35-turbo", "plugin_id": "5df193be-47a3-4f1b-8c37-37e31af0568b" }, "payload": {}, "usage": { "prompt_token": 89, "completion_token": 56, "total_tokens": 145 } }, "ai-response-transformer": { "meta": { "request_model": "mistral-tiny", "provider_name": "mistral", "response_model": "mistral-tiny", "plugin_id": "1c783122-0223-4a03-9f1d-c71d2baab01e" }, "payload": {}, "usage": { "prompt_token": 168, "completion_token": 180, "total_tokens": 348 } }, "ai-proxy": { "meta": { "request_model": "gpt-35-turbo", "provider_name": "azure", "response_model": "gpt-35-turbo", "plugin_id": "546c3856-24b3-469a-bd6c-f6083babd2cd" }, "payload": {}, "usage": { "prompt_token": 28, "completion_token": 14, "total_tokens": 42 } } }, ``` * fix analytics with new format * changelog * fix * fix json * fix test * fix test * fix test * fix(ai analytics): edit the format of the ai anayltics * fix(ai analytics): edit the format of the ai anayltics * fix: add testcase * fix: add testcase * fix: add testcase * fix lint * fix(ai-transformer): integration tests wrong response status --------- Co-authored-by: Jack Tysoe <jack.tysoe@konghq.com>
Summary
This will allow to add a provide layer in the analytics in case several plugins are used
Current model is:
New model if using several plugins:
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix #[issue number]
KAG-3759
KAG-4124
EDIT: format JSON snippets