Skip to content

Commit 5cfcba9

Browse files
Copilottrwalke
andcommitted
Switch auto-answer-issues workflow from OpenAI.com to Azure OpenAI
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
1 parent c12b5fa commit 5cfcba9

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

.github/workflows/auto-answer-issues.yml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
# Only run for issues created by org members or owners (i.e., Microsoft Open Source enterprise members).
1515
# github.event.issue.author_association is set by GitHub based on the issue author's relationship
1616
# to this repository. MEMBER = org member, OWNER = repo/org owner. This prevents untrusted
17-
# external contributors from triggering the OpenAI-backed responder and consuming secrets/tokens.
17+
# external contributors from triggering the Azure OpenAI-backed responder and consuming secrets/tokens.
1818
if: |
1919
github.event.issue.author_association == 'MEMBER' ||
2020
github.event.issue.author_association == 'OWNER' ||
@@ -35,7 +35,10 @@ jobs:
3535
- name: Generate and post response
3636
env:
3737
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
38+
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
39+
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
40+
AZURE_OPENAI_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_DEPLOYMENT }}
41+
AZURE_OPENAI_API_VERSION: "2024-12-01-preview"
3942
ISSUE_NUMBER: ${{ github.event.issue.number }}
4043
ISSUE_TITLE: ${{ github.event.issue.title }}
4144
ISSUE_BODY: ${{ github.event.issue.body }}
@@ -44,12 +47,15 @@ jobs:
4447
run: |
4548
node - << 'EOF'
4649
const { Octokit } = require("@octokit/rest");
47-
const OpenAI = require("openai");
50+
const { AzureOpenAI } = require("openai");
4851
4952
async function main() {
5053
const {
5154
GITHUB_TOKEN,
52-
OPENAI_API_KEY,
55+
AZURE_OPENAI_API_KEY,
56+
AZURE_OPENAI_ENDPOINT,
57+
AZURE_OPENAI_DEPLOYMENT,
58+
AZURE_OPENAI_API_VERSION,
5359
ISSUE_NUMBER,
5460
ISSUE_TITLE,
5561
ISSUE_BODY,
@@ -60,8 +66,14 @@ jobs:
6066
if (!GITHUB_TOKEN) {
6167
throw new Error("GITHUB_TOKEN is not set.");
6268
}
63-
if (!OPENAI_API_KEY) {
64-
throw new Error("OPENAI_API_KEY is not set.");
69+
if (!AZURE_OPENAI_API_KEY) {
70+
throw new Error("AZURE_OPENAI_API_KEY is not set.");
71+
}
72+
if (!AZURE_OPENAI_ENDPOINT) {
73+
throw new Error("AZURE_OPENAI_ENDPOINT is not set.");
74+
}
75+
if (!AZURE_OPENAI_DEPLOYMENT) {
76+
throw new Error("AZURE_OPENAI_DEPLOYMENT is not set.");
6577
}
6678
if (!ISSUE_NUMBER || !REPO_OWNER || !REPO_NAME) {
6779
throw new Error("Required issue/repository environment variables are missing.");
@@ -72,7 +84,12 @@ jobs:
7284
const body = ISSUE_BODY || "";
7385
7486
const octokit = new Octokit({ auth: GITHUB_TOKEN });
75-
const openai = new OpenAI({ apiKey: OPENAI_API_KEY });
87+
const openai = new AzureOpenAI({
88+
apiKey: AZURE_OPENAI_API_KEY,
89+
endpoint: AZURE_OPENAI_ENDPOINT,
90+
deployment: AZURE_OPENAI_DEPLOYMENT,
91+
apiVersion: AZURE_OPENAI_API_VERSION
92+
});
7693
7794
const prompt = `
7895
You are a helpful GitHub assistant. An issue has been opened in the repository \`${REPO_OWNER}/${REPO_NAME}\`.
@@ -91,7 +108,7 @@ Please write a concise, friendly reply that:
91108
`;
92109
93110
const completion = await openai.chat.completions.create({
94-
model: "gpt-4.1-mini",
111+
model: AZURE_OPENAI_DEPLOYMENT,
95112
messages: [
96113
{ role: "system", content: "You are a helpful assistant for triaging GitHub issues." },
97114
{ role: "user", content: prompt }
@@ -100,7 +117,7 @@ Please write a concise, friendly reply that:
100117
101118
const reply = (completion.choices[0]?.message?.content || "").trim();
102119
if (!reply) {
103-
throw new Error("OpenAI returned an empty response.");
120+
throw new Error("Azure OpenAI returned an empty response.");
104121
}
105122
106123
await octokit.issues.createComment({

0 commit comments

Comments
 (0)