Skip to content

Commit

Permalink
refactor(github): refactor triage-issues-with-ai to generateObject (#…
Browse files Browse the repository at this point in the history
…69696)

## Why

It turns out we should have been using `generateObject()` instead all
along for this use case.

![CleanShot 2024-09-04 at 14 18
31@2x](https://github.com/user-attachments/assets/033d51f3-12a1-47af-8967-67e365ba2ead)
  • Loading branch information
samcx authored Sep 4, 2024
1 parent afcad43 commit 1b89d7d
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 378 deletions.

Large diffs are not rendered by default.

229 changes: 0 additions & 229 deletions .github/actions/next-repo-actions/lib/types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions .github/actions/next-repo-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/github": "6.0.0",
"@ai-sdk/openai": "^0.0.54",
"@ai-sdk/openai": "^0.0.55",
"@slack/web-api": "^7.3.4",
"ai": "^3.3.19",
"ai": "^3.3.26",
"slack-block-builder": "^2.8.0",
"zod": "^3.23.8"
},
Expand Down
38 changes: 16 additions & 22 deletions .github/actions/next-repo-actions/src/triage-issues-with-ai.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { WebClient } from '@slack/web-api'
import { info, setFailed } from '@actions/core'
import { context } from '@actions/github'
import { generateText, tool } from 'ai'
import { generateObject } from 'ai'
import { openai } from '@ai-sdk/openai'
import { z } from 'zod'
import { BlockCollection, Divider, Section } from 'slack-block-builder'

import { getLatestCanaryVersion, getLatestVersion } from '../lib/util.mjs'
import { issueSchema } from '../lib/types'

async function main() {
if (!process.env.OPENAI_API_KEY) throw new TypeError('OPENAI_API_KEY not set')
Expand All @@ -19,9 +19,6 @@ async function main() {
const channel = '#next-info'

const issue = context.payload.issue
const html_url = issue.html_url
const number = issue.number
const title = issue.title

let latestVersion: string
let latestCanaryVersion: string
Expand All @@ -42,20 +39,17 @@ async function main() {

const guidelines = await res.text()

const result = await generateText({
const {
object: { explanation, isSevere, number, title, url },
} = await generateObject({
model: openai(model),
maxToolRoundtrips: 1,
tools: {
report_to_slack: tool({
description: 'Report to Slack.',
parameters: issueSchema,
execute: async () => {
// necessary to have an execute the tool automatically,
// so just putting an info message here as a placeholder
info('Reporting to Slack...')
},
}),
},
schema: z.object({
explanation: z.string().describe('The explanation of the severity.'),
isSevere: z.boolean().describe('Whether the issue is severe.'),
number: z.number().describe('The issue number.'),
title: z.string().describe('The issue title.'),
url: z.string().describe('The issue URL.'),
}),
system:
'Your job is to determine the severity of a GitHub issue using the triage guidelines and the latest versions of Next.js. Succinctly explain why you chose the severity, without paraphrasing the triage guidelines. Report to Slack the explanation only if the severity is considered severe.',
prompt:
Expand All @@ -66,14 +60,14 @@ async function main() {
})

// the ai determined that the issue was severe enough to report on slack
if (result.roundtrips.length > 1) {
if (isSevere) {
const blocks = BlockCollection([
Section({
text: `:github2: <${html_url}|#${number}>: ${title}\n_Note: This issue was evaluated and reported on Slack with *${model}*._`,
text: `:github2: <${url}|#${number}>: ${title}\n_Note: This issue was evaluated and reported on Slack with *${model}*._`,
}),
Divider(),
Section({
text: `_${result.text}_`,
text: `_${explanation}_`,
}),
])

Expand All @@ -89,7 +83,7 @@ async function main() {

// the ai will also provide a reason why the issue was not severe enough to report on slack
info(
`result.text: ${result.text}\nhtml_url: ${html_url}\nnumber: ${number}\ntitle: ${title}`
`Explanation: ${explanation}\nhtml_url: ${url}\nnumber: ${number}\ntitle: ${title}`
)
} catch (error) {
setFailed(error)
Expand Down
Loading

0 comments on commit 1b89d7d

Please sign in to comment.