Skip to content

Commit 05ab1bc

Browse files
authored
Merge pull request #11 from coolbeevip/issue-10
Add custom rule support to summary prompt
2 parents f09c731 + 62bfebc commit 05ab1bc

File tree

13 files changed

+130
-50
lines changed

13 files changed

+130
-50
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/pr.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
paths:
6+
- "src/**"
7+
- "*.py"
8+
- "*.toml"
9+
- "requirements.txt"
10+
- ".github/workflows/**"
11+
pull_request:
12+
paths:
13+
- "src/**"
14+
- "*.py"
15+
- "*.toml"
16+
- "requirements.txt"
17+
- ".github/workflows/**"
18+
19+
jobs:
20+
lint:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Check Out Repo
24+
uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.11'
29+
cache: 'pip'
30+
- name: Install Dependencies
31+
run: make init
32+
- name: Run Linter
33+
run: make lint
34+
35+
test:
36+
needs: lint
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Check Out Repo
40+
uses: actions/checkout@v4
41+
- name: Set up Python
42+
uses: actions/setup-python@v5
43+
with:
44+
python-version: '3.11'
45+
cache: 'pip'
46+
- name: Install Dependencies
47+
run: make init
48+
- name: Run Tests
49+
run: make test

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ fmt:
99
@black ./src ./tests ./gitlab_bot.py
1010
@isort --profile black ./src ./tests ./gitlab_bot.py
1111

12-
coverage: lint
13-
@pytest --cov=an_copilot tests
12+
test: lint
13+
@pytest --cov=src tests
1414

1515
i18n:
1616
xgettext -d base -o src/locales/gitlab-bot.pot *.py

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ These parameters are used to connect Azure OpenAI models.
180180
181181
This parameter specifies the AI model backend to use. The default value is `openai`, but you can switch to `google` for Google models or `azure-openai` for Azure OpenAI models.
182182
183-
**`BOT_GITLAB_MERGE_REQUEST_SUMMARY_ENABLED` / `BOT_GITLAB_MERGE_REQUEST_SUMMARY_LANGUAGE`**
183+
**`BOT_GITLAB_MERGE_REQUEST_SUMMARY_ENABLED` / `BOT_GITLAB_MERGE_REQUEST_SUMMARY_LANGUAGE` / `BOT_GITLAB_MERGE_REQUEST_SUMMARY_PROMPT_RULE` **
184184
185185
The `BOT_GITLAB_MERGE_REQUEST_SUMMARY_ENABLED` parameter controls whether the system generates a summary for GitLab merge requests. By default, it is set to `true`.
186186
The `BOT_GITLAB_MERGE_REQUEST_SUMMARY_LANGUAGE` parameter specifies the language in which the generated merge request summaries will be written. By default, it is set to `English`. However, you can change it to any preferred language code if needed.
187+
The `BOT_GITLAB_MERGE_REQUEST_SUMMARY_PROMPT_RULE` The parameters specify the prompt rules for generating a merge request summary. You can change it to any preferred prompt rule as needed, for example: `1. Please summarize and condense highly\n2. Please output in English`.
187188
188189
**`BOT_GITLAB_MERGE_REQUEST_EMAIL_USERNAME_NOT_MATCH_ENABLED`**
189190

README_ZH.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ BOT_GIT_COMMIT_SUBJECT_EXAMPLES_MARKDOWN="* feat: 添加认证模块\n* fix: 解
179179

180180
该参数指定要使用的 AI 模型后端。默认值为 `openai`,但您可以切换为 `google`(用于 Google 模型)或 `azure-openai`(用于 Azure OpenAI 模型)。
181181

182-
**`BOT_GITLAB_MERGE_REQUEST_SUMMARY_ENABLED` / `BOT_GITLAB_MERGE_REQUEST_SUMMARY_LANGUAGE`**
182+
**`BOT_GITLAB_MERGE_REQUEST_SUMMARY_ENABLED` / `BOT_GITLAB_MERGE_REQUEST_SUMMARY_LANGUAGE` / `BOT_GITLAB_MERGE_REQUEST_SUMMARY_PROMPT_RULE`**
183183

184184
`BOT_GITLAB_MERGE_REQUEST_SUMMARY_ENABLED` 参数控制系统是否生成 GitLab 合并请求的摘要。默认设置为 `true`
185185
`BOT_GITLAB_MERGE_REQUEST_SUMMARY_LANGUAGE` 参数指定生成的合并请求摘要的语言。默认设置为 `English`。但您可以根据需要更改为任何首选的语言代码。
186+
`BOT_GITLAB_MERGE_REQUEST_SUMMARY_PROMPT_RULE` 参数指定生成合并请求摘要的提示规则。您可以根据需要更改为任何首选的提示规则,例如:`1. 请高度概括并总结\n2. 请使用中文输出`
186187

187188
**`BOT_GITLAB_MERGE_REQUEST_EMAIL_USERNAME_NOT_MATCH_ENABLED`**
188189

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ lint = [
3636
"isort>=5,<6",
3737
"black>=23,<24"
3838
]
39+
test = [
40+
"pytest==7.4.3",
41+
"coverage==7.2.7",
42+
"pytest-cov==4.1.0"
43+
]
3944
package = [
4045
"flit==3.9.0"
4146
]

src/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
"BOT_GITLAB_MERGE_REQUEST_SUMMARY_LANGUAGE", "English"
136136
)
137137

138+
bot_gitlab_merge_request_summary_prompt_rule = os.getenv(
139+
"BOT_GITLAB_MERGE_REQUEST_SUMMARY_PROMPT_RULE", None
140+
)
141+
138142
# gitlab merge request email username not match check
139143
bot_gitlab_merge_request_email_username_not_match_enabled = (
140144
os.getenv(

src/llm.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@
2424
azure_openai_api_key,
2525
azure_openai_api_version,
2626
azure_openai_endpoint,
27+
bot_gitlab_merge_request_summary_prompt_rule,
2728
bot_language,
2829
google_api_key,
2930
model_name,
3031
openai_api_base,
3132
openai_api_key,
3233
)
3334
from src.i18n import _
34-
from src.prompts.prompts import get_prompt_text
35+
from src.prompts.prompts import get_summary_prompt_text
3536

3637
AI = None
3738

@@ -77,8 +78,10 @@ def ai_diffs_summary(git_diff) -> str:
7778
logging.info(f"diffs_string: {diff_string}")
7879
messages = [
7980
SystemMessage(
80-
content=get_prompt_text(
81-
name="DIFFS_SUMMARY_PROMPTS_TEMPLATE", lang=bot_language
81+
content=get_summary_prompt_text(
82+
name="DIFFS_SUMMARY_PROMPTS_TEMPLATE",
83+
lang=bot_language,
84+
custom_rule=bot_gitlab_merge_request_summary_prompt_rule,
8285
)
8386
),
8487
HumanMessage(content=diff_string),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
You are an intelligent robot proficient in multiple programming languages and good at reading git-dff reports.
22

3+
## Rules
4+
5+
<RULES>
36
1. Understand and summarize the author’s intention based on the report content.
47
2. Then analyze whether there are apparent flaws based on the report content and give suggestions.
8+
</RULES>
59

610
Next, I will send you the complete content of the git-diff report. Please respond according to the rules above after receiving it.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
你是一个精通多种编程语言的智能机器人,擅长阅读 git-dff 报告。
22

3+
## 规则
4+
5+
<RULES>
36
1. 先根据报告内容理解作者意图并总结
47
2. 再根据报告内容分析是否存在明显的缺陷并给出建议
8+
</RULES>
59

610
接下来我会发给你 git-diff 报告完整内容,收到后请按照上边的规则回复。

0 commit comments

Comments
 (0)