From 35ff4738847b0f6ac97e2951fb11064dc943a6cc Mon Sep 17 00:00:00 2001 From: Miwa <63481257+ensan-hcl@users.noreply.github.com> Date: Wed, 20 Aug 2025 21:55:13 +0900 Subject: [PATCH] feat: filter Google Form notes with GitHub Models --- .github/workflows/google_form.yaml | 62 ++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/.github/workflows/google_form.yaml b/.github/workflows/google_form.yaml index 5232307..a752c1a 100644 --- a/.github/workflows/google_form.yaml +++ b/.github/workflows/google_form.yaml @@ -9,6 +9,7 @@ on: permissions: issues: write contents: read + models: read jobs: create-issue: @@ -16,13 +17,68 @@ jobs: steps: - name: Open issue with form response uses: actions/github-script@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: script: | const payload = context.payload.client_payload; + const content = payload.content; // Extract the word after "単語を入力してください:" if present - const wordMatch = payload.content.match(/^単語を入力してください:\s*(.+)$/m); + const wordMatch = content.match(/^単語を入力してください:\s*(.+)$/m); const word = wordMatch ? wordMatch[1].trim() : null; + // Extract supplementary info + const supplementMatch = content.match(/^この単語について補足すべき情報があれば記載してください:\s*(.*)$/m); + const supplement = supplementMatch ? supplementMatch[1].trim() : ''; + + let filteredContent = content; + if (supplement) { + try { + const res = await fetch('https://models.github.ai/inference/chat/completions', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, + }, + body: JSON.stringify({ + model: 'openai/gpt-4o', + messages: [ + { + role: 'system', + content: 'You check whether the user text is toxic. If toxic, rewrite it into Japanese cat-speak. Respond in JSON.' + }, + { role: 'user', content: supplement } + ], + response_format: { + type: 'json_schema', + json_schema: { + name: 'toxicity', + schema: { + type: 'object', + properties: { + toxic: { type: 'boolean' }, + cat: { type: 'string' } + }, + required: ['toxic', 'cat'], + additionalProperties: false + } + } + } + }) + }); + if (res.ok) { + const data = await res.json(); + const msg = data?.choices?.[0]?.message?.content; + const result = JSON.parse(msg); + if (result.toxic) { + filteredContent = content.replace(/^この単語について補足すべき情報があれば記載してください:\s*(.*)$/m, `この単語について補足すべき情報があれば記載してください: ${result.cat}`); + } + } + } catch (err) { + core.warning(`LLM filtering failed: ${err}`); + } + } + const titlePrefix = word ? `vocabulary: add 「${word}」` : 'Form response'; @@ -32,7 +88,7 @@ jobs: 'Google Formに辞書追加のリクエストがありました。対応を検討してください。', '', '```', - payload.content, + filteredContent, '```' ].join('\n'); await github.rest.issues.create({ @@ -40,4 +96,4 @@ jobs: repo: context.repo.repo, title, body - }); \ No newline at end of file + });