Skip to content

Commit 9df5667

Browse files
authored
Merge pull request #248 from azooKey/codex/update-google-form-action-for-feedback-filtering
feat: filter Google Form notes with GitHub Models
2 parents a07ef72 + 35ff473 commit 9df5667

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

.github/workflows/google_form.yaml

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,76 @@ on:
99
permissions:
1010
issues: write
1111
contents: read
12+
models: read
1213

1314
jobs:
1415
create-issue:
1516
runs-on: ubuntu-latest
1617
steps:
1718
- name: Open issue with form response
1819
uses: actions/github-script@v7
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1922
with:
2023
script: |
2124
const payload = context.payload.client_payload;
25+
const content = payload.content;
2226
// Extract the word after "単語を入力してください:" if present
23-
const wordMatch = payload.content.match(/^単語を入力してください:\s*(.+)$/m);
27+
const wordMatch = content.match(/^単語を入力してください:\s*(.+)$/m);
2428
const word = wordMatch ? wordMatch[1].trim() : null;
2529
30+
// Extract supplementary info
31+
const supplementMatch = content.match(/^この単語について補足すべき情報があれば記載してください:\s*(.*)$/m);
32+
const supplement = supplementMatch ? supplementMatch[1].trim() : '';
33+
34+
let filteredContent = content;
35+
if (supplement) {
36+
try {
37+
const res = await fetch('https://models.github.ai/inference/chat/completions', {
38+
method: 'POST',
39+
headers: {
40+
'Content-Type': 'application/json',
41+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
42+
},
43+
body: JSON.stringify({
44+
model: 'openai/gpt-4o',
45+
messages: [
46+
{
47+
role: 'system',
48+
content: 'You check whether the user text is toxic. If toxic, rewrite it into Japanese cat-speak. Respond in JSON.'
49+
},
50+
{ role: 'user', content: supplement }
51+
],
52+
response_format: {
53+
type: 'json_schema',
54+
json_schema: {
55+
name: 'toxicity',
56+
schema: {
57+
type: 'object',
58+
properties: {
59+
toxic: { type: 'boolean' },
60+
cat: { type: 'string' }
61+
},
62+
required: ['toxic', 'cat'],
63+
additionalProperties: false
64+
}
65+
}
66+
}
67+
})
68+
});
69+
if (res.ok) {
70+
const data = await res.json();
71+
const msg = data?.choices?.[0]?.message?.content;
72+
const result = JSON.parse(msg);
73+
if (result.toxic) {
74+
filteredContent = content.replace(/^この単語について補足すべき情報があれば記載してください:\s*(.*)$/m, `この単語について補足すべき情報があれば記載してください: ${result.cat}`);
75+
}
76+
}
77+
} catch (err) {
78+
core.warning(`LLM filtering failed: ${err}`);
79+
}
80+
}
81+
2682
const titlePrefix = word
2783
? `vocabulary: add 「${word}」`
2884
: 'Form response';
@@ -32,12 +88,12 @@ jobs:
3288
'Google Formに辞書追加のリクエストがありました。対応を検討してください。',
3389
'',
3490
'```',
35-
payload.content,
91+
filteredContent,
3692
'```'
3793
].join('\n');
3894
await github.rest.issues.create({
3995
owner: context.repo.owner,
4096
repo: context.repo.repo,
4197
title,
4298
body
43-
});
99+
});

0 commit comments

Comments
 (0)