Skip to content

Commit

Permalink
Added KQL to get AOAI data from Application Insights
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Apr 2, 2024
1 parent af3d5ce commit 1503f25
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions infra/modules/apim/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ resource "azurerm_api_management_api_policy" "policy" {
}

# https://github.com/aavetis/azure-openai-logger/blob/main/README.md
# KQL Query to extract OpenAI data from Application Insights
# requests
# | where operation_Name == "openai-api;rev=1 - Completions_Create" or operation_Name == "openai-api;rev=1 - ChatCompletions_Create"
# | extend Prompt = parse_json(tostring(parse_json(tostring(parse_json(tostring(customDimensions.["Request-Body"])).messages[-1].content))))
# | extend Generation = parse_json(tostring(parse_json(tostring(parse_json(tostring(customDimensions.["Response-Body"])).choices))[0].message)).content
# | extend promptTokens = parse_json(tostring(parse_json(tostring(customDimensions.["Response-Body"])).usage)).prompt_tokens
# | extend completionTokens = parse_json(tostring(parse_json(tostring(customDimensions.["Response-Body"])).usage)).completion_tokens
# | extend totalTokens = parse_json(tostring(parse_json(tostring(customDimensions.["Response-Body"])).usage)).total_tokens
# | project timestamp, Prompt, Generation, promptTokens, completionTokens, totalTokens, round(duration,2), operation_Name
resource "azurerm_api_management_diagnostic" "diagnostics" {
identifier = "applicationinsights"
resource_group_name = var.resource_group_name
Expand Down

0 comments on commit 1503f25

Please sign in to comment.