Skip to content

Add an AI triage assistant #21

Add an AI triage assistant

Add an AI triage assistant #21

name: "Triage: Apply Labels"
on:
pull_request:
types: [reopened, synchronize, opened]
# issues:
# types: [opened, edited]
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number to triage'
required: true
type: number
permissions:
contents: read
issues: read
models: read
jobs:
triage-issue:
name: Apply Labels
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get Issue Data
id: issue-data
uses: actions/github-script@v7
with:
script: |
const issue_number =
github.event_name === 'workflow_dispatch' ? context.payload.inputs.issue_number :
github.event_name === 'issues' ? github.event.issue.number :
'29634';
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number
});
const data = {
title: issue.data.title,
body: issue.data.body,
number: issue.data.number
};
const fs = require('fs');
fs.writeFileSync('issue.json', JSON.stringify(data, null, 2));
return data;
- name: Create Prompt
id: create-prompt
shell: pwsh
run: |
$issue = Get-Content -Raw "issue.json" | ConvertFrom-Json
$number = $issue.number
$title = $issue.title
$body = $issue.body
Set-Content -Path "prompt.md" -Value @"
A new issue has arrived, please triage and apply the appropriate labels.
The issue is as follows:
The issue number is:
#$number
The title is:
$title
The body is:
$body
"@
- name: Load System Prompt
id: load-system-prompt
shell: pwsh
run: |
$lines = Get-Content ".github/prompts/apply-label.prompt-template.md"
$outputContent = ""
foreach ($line in $lines) {
if ($line -match "^EXEC:\s*(.+)$") {
$command = $matches[1]
Write-Host "Executing command: $command"
try {
$result = Invoke-Expression $command
Write-Host "Command output: $result"
$outputContent += "$result`n"
} catch {
Write-Error "ERROR executing: $command`n$_"
exit 1
}
} else {
$outputContent += "$line`n"
}
}
$outputContent | Set-Content -Path ".github/prompts/apply-label.prompt.md"
"system_prompt=$($outputContent | ConvertTo-Json)" >> $env:GITHUB_OUTPUT
- name: Log Prompts
run: |
echo "::group::System Prompt"
cat .github/prompts/apply-label.prompt.md
echo "::endgroup::"
echo "::group::User Prompt"
cat prompt.md
echo "::endgroup::"
- name: Run AI Inference
id: inference
uses: actions/ai-inference@main
with:
prompt-file: "prompt.md"
system-prompt: ${{ steps.load-system-prompt.outputs.system_prompt }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Log AI Analysis
shell: pwsh
run: |
cat "${{ steps.inference.outputs.response-file }}"