Skip to content

Commit bd39dba

Browse files
committed
Make individual prompts configurable
1 parent c08bd1c commit bd39dba

9 files changed

Lines changed: 177 additions & 69 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Example workflow demonstrating configurable built-in prompts
2+
name: 'AI Spam Guard with Custom Configuration'
3+
on:
4+
issues:
5+
types: [opened]
6+
issue_comment:
7+
types: [created]
8+
pull_request_review_comment:
9+
types: [created]
10+
11+
jobs:
12+
# Basic usage with all prompts enabled (default behavior)
13+
full-protection:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
issues: write
17+
pull-requests: write
18+
models: read
19+
contents: read
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Run AI Spam Guard with All Prompts
23+
uses: github/ai-spam-guard
24+
with:
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
spam-label: 'spam'
27+
ai-label: 'ai-generated'
28+
minimize-detected-comments: true
29+
30+
# Selective prompt configuration example
31+
custom-protection:
32+
runs-on: ubuntu-latest
33+
permissions:
34+
issues: write
35+
pull-requests: write
36+
models: read
37+
contents: read
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Run AI Spam Guard with Selective Prompts
41+
uses: github/ai-spam-guard
42+
with:
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
spam-label: 'potential-spam'
45+
ai-label: 'ai-generated'
46+
minimize-detected-comments: false
47+
# Only enable general spam and link spam detection
48+
enable-spam-detection: true
49+
enable-link-spam-detection: true
50+
enable-ai-detection: false # Disable AI detection for this workflow
51+
52+
# Link spam only (for repositories that mainly deal with link spam)
53+
link-spam-only:
54+
runs-on: ubuntu-latest
55+
permissions:
56+
issues: write
57+
pull-requests: write
58+
models: read
59+
contents: read
60+
steps:
61+
- uses: actions/checkout@v4
62+
- name: Run AI Spam Guard - Link Spam Only
63+
uses: github/ai-spam-guard
64+
with:
65+
token: ${{ secrets.GITHUB_TOKEN }}
66+
spam-label: 'link-spam'
67+
minimize-detected-comments: true
68+
# Only enable link spam detection
69+
enable-spam-detection: false
70+
enable-link-spam-detection: true
71+
enable-ai-detection: false

README.md

Lines changed: 25 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ jobs:
3636
spam-label: 'spam'
3737
ai-label: 'ai-generated'
3838
minimize-detected-comments: true
39+
# Built-in prompt configuration (all enabled by default)
40+
enable-spam-detection: true
41+
enable-link-spam-detection: true
42+
enable-ai-detection: true
3943
# custom-prompt-path: '.github/prompts/my-custom.prompt.yml' # Optional
4044
```
4145

@@ -48,6 +52,9 @@ jobs:
4852
| `ai-label` | Label to add when AI-generated content is detected | `ai-generated` | No |
4953
| `minimize-detected-comments` | Whether to minimize comments detected as spam | `true` | No |
5054
| `custom-prompt-path` | Path to a custom YAML prompt file in your repository (relative to repo root) | (none) | No |
55+
| `enable-spam-detection` | Enable built-in spam detection prompt | `true` | No |
56+
| `enable-link-spam-detection` | Enable built-in link spam detection prompt | `true` | No |
57+
| `enable-ai-detection` | Enable built-in AI-generated content detection prompt | `true` | No |
5158

5259
### Inference
5360

@@ -60,13 +67,27 @@ into rate limiting issues you can choose to
6067

6168
## Detection Prompts
6269

63-
The action uses built-in YAML prompts located in the `prompts/` directory:
70+
The action uses built-in YAML prompts located in the `prompts/` directory. Each
71+
prompt can be individually enabled or disabled using the configuration options:
6472

6573
- **`spam-detection.prompt.yml`**: Detects promotional content, scams, and
66-
irrelevant posts
74+
irrelevant posts (controlled by `enable-spam-detection`)
6775
- **`ai-detection.prompt.yml`**: Identifies AI-generated content patterns
68-
- **`bot-detection.prompt.yml`**: Identifies automated bot behavior
76+
(controlled by `enable-ai-detection`)
6977
- **`link-spam-detection.prompt.yml`**: Focuses on suspicious links and URLs
78+
(controlled by `enable-link-spam-detection`)
79+
80+
All prompts are enabled by default. You can selectively disable them based on
81+
your repository's moderation needs:
82+
83+
```yaml
84+
- uses: github/ai-spam-guard
85+
with:
86+
token: ${{ secrets.GITHUB_TOKEN }}
87+
enable-spam-detection: true # Enable general spam detection
88+
enable-link-spam-detection: false # Disable link spam detection
89+
enable-ai-detection: true # Enable AI content detection
90+
```
7091
7192
You can iterate on or tweak these prompts via the
7293
[Models tab](https://github.com/github/ai-spam-guard/models) on this repository.
@@ -85,62 +106,7 @@ You can also provide your own custom prompt file in your repository using the
85106
custom-prompt-path: '.github/prompts/my-custom-spam-detection.prompt.yml'
86107
```
87108

88-
Custom prompt files should follow the same YAML format as the built-in prompts:
89-
90-
```yaml
91-
messages:
92-
- role: system
93-
content: |
94-
You are a content moderation system. Analyze the provided content
95-
and determine if it violates repository guidelines.
96-
97-
Consider these indicators:
98-
- Off-topic discussions
99-
- Inappropriate language
100-
- Spam or promotional content
101-
102-
Provide your analysis in the specified JSON format.
103-
- role: user
104-
content: |
105-
Analyze this content:
106-
107-
{{stdin}}
108-
model: gpt-4o
109-
responseFormat: json_schema
110-
jsonSchema: |-
111-
{
112-
"name": "spam_detection_result",
113-
"strict": true,
114-
"schema": {
115-
"type": "object",
116-
"properties": {
117-
"reasoning": {
118-
"type": "string",
119-
"description": "Detailed explanation of the analysis"
120-
},
121-
"is_spam": {
122-
"type": "boolean",
123-
"description": "Whether the content violates guidelines"
124-
}
125-
},
126-
"additionalProperties": false,
127-
"required": ["reasoning", "is_spam"]
128-
}
129-
}
130-
```
131-
132-
**Notes:**
133-
134-
- Custom prompts are treated as spam detection prompts by default (unless the
135-
filename contains "ai-detection")
136-
- Custom prompts are evaluated **before** the built-in prompts
137-
- The `{{stdin}}` placeholder will be replaced with the actual content to
138-
analyze
139-
- Custom prompts must return a JSON response with at least `reasoning` and
140-
`is_spam` fields
141-
142-
### Example Custom Prompt
143-
109+
Custom prompt files should follow the same YAML format as the built-in prompts.
144110
An example custom prompt file is included at
145111
`.github/prompts/example-custom.prompt.yml` that demonstrates the proper format
146112
and shows how to create repository-specific spam detection rules.

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ inputs:
3131
'Path to a custom YAML prompt file in your repository (relative to
3232
repository root)'
3333
required: false
34+
enable-spam-detection:
35+
description: 'Enable built-in spam detection prompt'
36+
required: false
37+
default: 'true'
38+
enable-link-spam-detection:
39+
description: 'Enable built-in link spam detection prompt'
40+
required: false
41+
default: 'true'
42+
enable-ai-detection:
43+
description: 'Enable built-in AI-generated content detection prompt'
44+
required: false
45+
default: 'true'
3446

3547
runs:
3648
using: 'node16'

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 27 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prompts/ai-detection.prompt.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ testData:
101101
multi agents haven’t been so much effective. Then I went back to a single
102102
agent creating code with baby steps. How it’s going for you?
103103
expected: 'false'
104-
- stdin: this beast with claude 4 opus just gonna eat through your bank account :)
104+
- stdin:
105+
this beast with claude 4 opus just gonna eat through your bank account :)
105106
expected: 'false'
106107
evaluators:
107108
- name: is-ai

src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ async function run(): Promise<void> {
1818
const minimizeComments = core.getBooleanInput('minimize-detected-comments')
1919
const customPromptPath = core.getInput('custom-prompt-path')
2020

21+
// Built-in prompt configuration
22+
const enableSpamDetection = core.getBooleanInput('enable-spam-detection')
23+
const enableLinkSpamDetection = core.getBooleanInput(
24+
'enable-link-spam-detection'
25+
)
26+
const enableAiDetection = core.getBooleanInput('enable-ai-detection')
27+
2128
const openai = new OpenAI({
2229
apiKey: token,
2330
baseURL: 'https://models.github.ai/inference'
@@ -44,7 +51,12 @@ async function run(): Promise<void> {
4451
openai,
4552
promptsDir,
4653
content,
47-
customPromptPath
54+
customPromptPath,
55+
{
56+
enableSpamDetection,
57+
enableLinkSpamDetection,
58+
enableAiDetection
59+
}
4860
)
4961

5062
if (!flags.spam && !flags.ai) {

src/prompt.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ interface PromptConfig {
1515
jsonSchema?: string
1616
}
1717

18+
interface BuiltInPromptConfig {
19+
enableSpamDetection: boolean
20+
enableLinkSpamDetection: boolean
21+
enableAiDetection: boolean
22+
}
23+
1824
// Response interfaces for different detection types
1925
interface SpamDetectionResult {
2026
reasoning: string
@@ -141,13 +147,30 @@ export async function evaluateContent(
141147
openai: OpenAI,
142148
promptsDir: string,
143149
content: string,
144-
customPromptPath?: string
150+
customPromptPath?: string,
151+
builtInConfig?: BuiltInPromptConfig
145152
): Promise<{ spam: boolean; ai: boolean }> {
146153
const files = await getPromptFiles(promptsDir)
147154
const flags = { spam: false, ai: false }
148155

156+
// Filter built-in prompts based on configuration
157+
const filteredFiles = files.filter((file) => {
158+
const filename = basename(file).toLowerCase()
159+
160+
if (filename.includes('ai-detection')) {
161+
return builtInConfig?.enableAiDetection !== false
162+
} else if (filename.includes('spam-detection')) {
163+
return builtInConfig?.enableSpamDetection !== false
164+
} else if (filename.includes('link-spam')) {
165+
return builtInConfig?.enableLinkSpamDetection !== false
166+
}
167+
168+
// Include unknown prompt types by default
169+
return true
170+
})
171+
149172
// Add custom prompt file if provided
150-
const allFiles = [...files]
173+
const allFiles = [...filteredFiles]
151174
if (customPromptPath && customPromptPath.trim()) {
152175
try {
153176
// Resolve custom prompt path relative to workspace root

0 commit comments

Comments
 (0)