Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/takedown bot #138

Merged
merged 25 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0a029a8
feat: init nodejs project with eslint
nonumpa Nov 18, 2024
8756115
feat: implement getSpamList that sent reply to GenAI then return spam…
nonumpa Nov 18, 2024
7bb138a
feat: createPullRequest via GitHub App
nonumpa Nov 18, 2024
e39648d
feat: get reply from rumors-api
nonumpa Nov 18, 2024
ecc58ff
feat: takedown spam reply
nonumpa Nov 18, 2024
d949cd6
feat: update prompt, input date format and rename env variables
nonumpa Dec 9, 2024
e916533
feat: get known users from pr titles
nonumpa Dec 9, 2024
7247697
feat: run takedown on github action
nonumpa Dec 9, 2024
7ede7df
feat: use langfuse to trace llm response
nonumpa Dec 9, 2024
e7ab33f
chore: rename createPR to githubPR
nonumpa Dec 11, 2024
7895364
feat: update takedown command
nonumpa Dec 11, 2024
be36c5c
fix: filtered out blocked user, fix query syntax error
nonumpa Dec 11, 2024
c41eb80
fix: Failed to add secret: Secret names must not start with GITHUB_.
nonumpa Dec 11, 2024
a295bc9
fix: github action environment variables null issue
nonumpa Dec 11, 2024
4510919
chore: rename action job title
nonumpa Dec 11, 2024
f904c05
chore: add REVIEW_REPLY_BEFORE to .env.sample
nonumpa Dec 11, 2024
7776d2a
feat(getSpamList): enhance response quality by replacing systemInstru…
nonumpa Dec 18, 2024
1322e18
fix(langfuse): lost one generation data, no need to await `trace.gen…
nonumpa Dec 18, 2024
521097c
fix(main): make sure we catch all error
nonumpa Dec 18, 2024
072187e
chore: update the github app tutorial link
nonumpa Dec 18, 2024
cb98402
chore: remove unused field
nonumpa Dec 16, 2024
960ae30
chore: rename function to processSpamRepliesFromDate to better reflec…
nonumpa Dec 18, 2024
b6941fd
perf(cd): adjusted cron expression to try to reduce high load
nonumpa Dec 18, 2024
0a6c467
perf(getPRs): use search api instead of pulls.list
nonumpa Dec 18, 2024
db3191b
perf(main): filter out duplicate texts
nonumpa Dec 18, 2024
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
25 changes: 25 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://ai.google.dev/gemini-api/docs/api-key
GEMINI_API_KEY=

# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation#using-the-octokitjs-sdk-to-authenticate-as-an-app-installation
# See the step1 in the above link
GITHUBAPP_ID=
# See the step2 in the link, and make sure to convert to base64: `base64 -i your_private_key_file > key.base64`
GITHUBAPP_PRIVATE_KEY_BASE64=
# Step3 in the link
GITHUBAPP_INSTALLATION_ID=

# To generate takedown document(reply url) for moderators to review
COFACTS_URL=https://dev.cofacts.tw

# Query article replies from Cofacts API
COFACTS_API_URL=https://dev-api.cofacts.tw/graphql

# Specifies the time range to query replies from `REVIEW_REPLY_BEFORE`
REVIEW_REPLY_BEFORE={ "seconds":0, "minutes":0, "hours":23, "days":46 }

# Optional: use langfuse for tracing the llm response
LANGFUSE_SECRET_KEY=
LANGFUSE_PUBLIC_KEY=
LANGFUSE_BASEURL=
ENV=development
26 changes: 26 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
parser: '@babel/eslint-parser',
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'prettier',
],
env: { node: true, es6: true, jest: true },
plugins: ['prettier', 'import'],
rules: {
'prettier/prettier': [
'error',
{
trailingComma: 'es5',
singleQuote: true,
},
],
},
settings: {
'import/resolver': {
'babel-module': {},
typescript: {},
},
},
};
33 changes: 33 additions & 0 deletions .github/workflows/takedown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Spam Detection

on:
schedule:
- cron: '4-59/10 * * * *' # run every ten minutes, starting at 4 minutes past the hour
workflow_dispatch: # allow manual trigger

jobs:
scanning-spam:
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- run: npm i

- name: Detect and create takedown PR
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
GITHUBAPP_PRIVATE_KEY_BASE64: ${{ secrets.GITHUBAPP_PRIVATE_KEY_BASE64 }}
GITHUBAPP_ID: ${{ secrets.GITHUBAPP_ID }}
GITHUBAPP_INSTALLATION_ID: ${{ secrets.GITHUBAPP_INSTALLATION_ID }}
COFACTS_URL: ${{ vars.COFACTS_URL }}
COFACTS_API_URL: ${{ vars.COFACTS_API_URL }}
REVIEW_REPLY_BEFORE: ${{ vars.REVIEW_REPLY_BEFORE }}
LANGFUSE_BASEURL: ${{ vars.LANGFUSE_BASEURL }}
LANGFUSE_PUBLIC_KEY: ${{ secrets.LANGFUSE_PUBLIC_KEY }}
LANGFUSE_SECRET_KEY: ${{ secrets.LANGFUSE_SECRET_KEY }}
ENV: ${{ github.environment }}
run: npm run takedown
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"presets": [
["@babel/env", {
"targets": {
"node": "current"
}
}]
],
"plugins": [
["module-resolver", {
"root": ["./src", "./test"],
"extensions": [".js", ".ts"]
}]
]
}
Loading
Loading