Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions .github/workflows/google_form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,76 @@ on:
permissions:
issues: write
contents: read
models: read

jobs:
create-issue:
runs-on: ubuntu-latest
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';
Expand All @@ -32,12 +88,12 @@ jobs:
'Google Formに辞書追加のリクエストがありました。対応を検討してください。',
'',
'```',
payload.content,
filteredContent,
'```'
].join('\n');
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body
});
});