Skip to content
adatum
  • Home
  •  About adatum
  •  Learn Azure Bicep
  •  SCOM Web API
Automation

Using Azure OpenAI ChatGPT for incidents

  • 24/04/202307/01/2025
  • by Martin Ehrnst

The Challenge of Long Chat Threads During Incidents

Everyone is an AI expert these days. After OpenAI released ChatGPT it’s almost impossible to work in tech without being presented with good (and bad) examples of what this service can do for you. Of course, I am also interested in seeing what these services can help with, but until very recently I didn’t have any good use cases that would provide the company I work for and me any value. Of course, GitHub copilot help our developers when it comes to programming, and it helps me from time to time with the same. Maybe even more, as I have no idea what I am doing in most cases.

I used Azure OpenAI and the GPT3.5 turbo language model, which is what the public ChatGPT uses. The reason for using Azure OpenAI is to make sure we can use and train the model with our company-specific data. Currently, the service is open on request only.

Anyway, let’s dive into the actual problem at hand. As an incident responder, you know how important it is to keep track of what happened during an incident. When the incident is over, you need to have a clear summary of what happened to help you identify what went wrong and how you can prevent similar incidents in the future. But what if you have hundreds or even thousands of chat messages to go through? That’s where Azure OpenAI and ChatGPT come in.

Using PowerShell and Slack API to Retrieve Chat Threads from Slack

In Vipps Slack is our primary communication tool during incidents. After each incident, we need to go through the chat threads to understand what happened. We used to do this manually, but it was time-consuming and error-prone. That’s why we decided to automate the process using Azure OpenAI and ChatGPT.

First, I used PowerShell and Slack API to retrieve the individual messages from Slack threads. I then passed the chat threads to Azure OpenAI’s GPT-3 model, which generated a summary of the incident based on the chat messages.

Setting up a Slack App to use Slack API

To use the Slack API to retrieve chat threads, you’ll need to set up a Slack app and obtain an API token. Here’s how you can do it:

  1. Go to the Slack API website (https://api.slack.com) and sign in with your Slack account.
  2. Click on the “Create New App” button and give your app a name and a development workspace.
  3. In the app dashboard, navigate to the “OAuth & Permissions” section and add the “channels:history” scope to your bot token scopes.
  4. Install the app in your workspace and copy the Bot User OAuth Access Token.
  5. In PowerShell, use the following code to retrieve the chat threads from Slack:
$token = "YOUR_BOT_TOKEN"
$channelId = "CHANNEL_ID"
$url = "https://slack.com/api/conversations.history?token=$token&channel=$channelId"
$response = Invoke-RestMethod -Uri $url
Output from the Azure OpenAI PowerShell script

Putting the Complete PowerShell Script together

Below is a complete PowerShell script. I have redacted some company-specific information. So feel free to use and modify where you need. It is possible that you need to filter out more things than I did. Specific users that you do not want to include, HTML content, etc.

# slack test
$slackKey = Get-AzKeyVaultsecret -VaultName "" -Name "" -AsPlainText
$azOpenAiKey = Get-AzKeyVaultsecret -VaultName "" -Name "" -AsPlainText
$slackChannelId = ""
$slackThreadId = ""
$openAiUrl = ""
$slackUrl = "https://slack.com/api/conversations.replies?channel=$slackChannelId&ts=$slackThreadId&pretty=1"
$slackHeaders= @{
"Authorization" = "Bearer $slackKey"
"content-type" = "authorization/x-www-form-urlencoded"
}
$incidentThread = Invoke-RestMethod -uri $slackUrl -Method Get -Headers $slackHeaders
$incidentMessages = ""
foreach ($message in $incidentThread.messages) {
$messageText = $message.text
$messageUser = $message.user
$messageUserUrl = "https://slack.com/api/users.info?user=$messageUser&pretty=1"
$messageUser = Invoke-RestMethod -uri $messageUserUrl -Method Get -Headers $slackHeaders
$messageUser = $messageUser.user.profile.real_name_normalized
$messageDate = (([System.DateTimeOffset]::FromUnixTimeSeconds($message.ts)).DateTime).ToString("yyyy-MM-dd HH:mm")
$messageText = $messageText.Replace("`n", "")
$messageText = $messageText.Replace("`r", "")
$messageText = $messageText.Replace(">", "")
$messageText = $messageText.Split("https://")[0]
$incidentMessages+="$messageDate|$messageUser|$messageText|`n"
}
$openAiHeaders = @{
"Content-Type" = "application/json"
"api-key" = $azOpenAiKey
"accept" = "application/json, text/plain, */*"
"accept-language" = "en"
}
$messages = $incidentMessages |Out-String
$prompt = @"
summarize the incident chat log in the following format returning a structured markdown document. Make sure to include the following fields as headings
Start time:
End time:
Observed issue:
Root cause:
Action items:
Participants:
$messages
summary:
"@
$body = @{
"prompt" = "$prompt"
"max_tokens" = 500
"temperature" = 0.3
"top_p" = 1
"frequency_penalty" = 0.2
"presence_penalty" = 0.2
"stop" = "tokens"
} | ConvertTo-Json -EscapeHandling EscapeNonAscii
$summary = Invoke-RestMethod -uri $openAiUrl -Method Post -Headers $openAiHeaders -Body $body
$summary.choices.text
view raw azopenai-slack.ps1 hosted with ❤ by GitHub

Summary and things to know

When using Azure OpenAI and ChatGPT to generate incident summaries, it’s important to keep in mind that the model is designed to analyze text-based data. If the chat messages contain images or other non-text data, the model will not be able to interpret them.

If your incident chat threads contain images or other non-text data, you may need to consider alternative ways to include that information

Another important consideration when using Azure OpenAI and ChatGPT to summarize chat threads from Slack during incidents is the token limitations of the model. The GPT-3 model has a limit of 2048 tokens per input, which means that if your chat threads are particularly long, you may need to split them into multiple inputs to generate a complete summary.

In addition, the Azure OpenAI API uses a token-based pricing model, which means that you will be charged based on the number of tokens generated by the model. If you’re generating a large number of summaries or working with particularly long chat threads, this can quickly become a significant expense.

By being mindful of these token limitations and experimenting with different summarization strategies, you can still use Azure OpenAI and ChatGPT to generate valuable incident summaries that can help you improve your incident response process.

Image from chatgpt showing i used chatgpt to write the post

Share this:

  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
Automation

Playing with cognitive services

  • 16/01/201707/01/2025
  • by Martin Ehrnst

If you know what your users do or talk about you will likely have advantages over your competitors, or if you have support desk, you want to dispatch the ticket to the correct department as quickly as possible. To gain some insights you can use different AI/Machine learning tools to help you and ‘automatically’ perform actions.

Microsoft cognitive services is a set of APIs which let you do things like text analytics. I have played around a bit and found that I could pretty easy do a sentiment test (how ‘happy’ is the author) and a key phrase analysis (what is the text about). To do an analysis I needed to send the text in English. By living in Norway I am fortunate i many ways, but one of them is that Norwegian translate very good programmatically in to English

Since Microsoft (or Google and AWS) let’s us translate text through their translation API, you can in theory run text analysis on any language. I played around a bit and i managed to send some text through translation and in the end output a sentiment analysis and the key phrases. I set up the script in Azure Functions as well and it works pretty good.
To use it you will have to sign up for two Cognitive Services accounts in Azure, One for the Text Analytics API and one for the Translator API. In your Azure function you will have to set up the two API keys as variables.

The script is available on Github and it is totally a proof of concept without any error handling other than the APIs itself. Feel free to contribute to the code. Version when writing 0.5b

 

Here is an example on a text i found on a French news site.

Donald Trump a réaffirmé, lundi, ses positions critiques vis-à-vis de l’Otan, de l’UE, et de la politique d’accueil des migrants lors d’entretiens accordés à des médias européens. Une vision toujours proche de celle de Vladimir Poutine.

Une erreur catastrophique de Merkel sur l’accueil des migrants, l’Otan obsolète, le succès du Brexit qui marque le début de la fin de l’Union européenne. Si le fond ressemble à du Vladimir Poutine, la forme, elle, est clairement signée Donald Trump.

Lundi 16 janvier, à cinq jours de son investiture, le magnat de l’immobilier n’a pas mâché ses mots pour exposer ses vues sur les sujets d’actualité les plus brûlants sur le Vieux Continent, auprès des journaux britannique Times et allemand Bild.

Translated in to English

Donald Trump has r affirm, Monday, his criticism-screws – live NATO, the EU, and the migrant policy in interviews granted to European media. A vision still close to that of Vladimir Poutine.

A catastrophic error of Merkel on the reception of migrants, NATO MP4 you, the success of the Brexit brand the d to the end of the European Union. If the background looks like from Vladimir P
utin, the form, she is clearly sign e Donald Trump.

Monday, January 16, five days of his inauguration, the real estate mogul has no m ch her words to present its views on the topics of news the most br callers on the old Continent, aupr s of B
ritish newspapers Times and German Bild.

Not the best translation, but the analisys is quite OK

Sentiment Score : 87.73 %

Key phrases : Monday, Vladimir Putin, NATO MP4, Vladimir Poutine, criticism-screws - live NATO, aupr s of British newspapers Times, real estate mogul, end, European media, reception of migrants, m ch, old 
Continent, success, e Donald Trump, European Union, br callers, migrant policy, form, interviews, days, Brexit brand, inauguration, words, catastrophic error of Merkel, topics of news, German
Bild, background, January, vision

The tests done in Norwegian is pretty much spot on, and English analysis is just as you would expect.

Share this:

  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit

Popular blog posts

  • Azure Application registrations, Enterprise Apps, and managed identities
  • Windows Admin Center with SquaredUp/SCOM
  • Microsoft killed SCOM internally
  • Creating Azure AD Application using Powershell
  • Azure token from a custom app registration

Categories

Automation Azure Azure Active Directory Azure Bicep Azure DevOps Azure Functions Azure Lighthouse Azure Logic Apps Azure Monitor Azure Policy Community Conferences CSP Monitoring DevOps GitHub Guest blogs Infrastructure As Code Kubernetes Microsoft CSP MPAuthoring OMS Operations Manager Podcast Powershell Uncategorised Windows Admin Center Windows Server

Follow Martin Ehrnst

  • X
  • LinkedIn

RSS feed RSS - Posts

RSS feed RSS - Comments

Microsoft Azure MVP

Martin Ehrnst Microsoft Azure MVP
Adatum.no use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Cookie Policy
Theme by Colorlib Powered by WordPress