Skip to content

Commit 5ab536d

Browse files
committed
add PROMPT var
1 parent 84022a6 commit 5ab536d

File tree

8 files changed

+36
-16
lines changed

8 files changed

+36
-16
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ LANGUAGE=
1717
MODEL=
1818
temperature=
1919
top_p=
20-
TARGET_LABEL=
20+
TARGET_LABEL=
21+
PROMPT=Bellow is a code diff, please help me do a code review

README.ja.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Translation Versions: [ENGLISH](./README.md) | [中文简体](./README.zh-CN.md)
66

77
## Usage
88

9-
❗️⚠️ コストを考慮してBOTはテスト目的でのみ使用され、現在AWS Lambdaに展開されて速度制限を受けています。そのため、不安定な状況は完全に正常です。アプリケーションを直接展開することをお勧めします。
9+
❗️⚠️ コストを考慮して BOT はテスト目的でのみ使用され、現在 AWS Lambda に展開されて速度制限を受けています。そのため、不安定な状況は完全に正常です。アプリケーションを直接展開することをお勧めします。
1010

1111
## Install
1212

@@ -17,12 +17,12 @@ Install: [apps/cr-gpt](https://github.com/apps/cr-gpt);
1717
1. リポジトリのホームページに移動します
1818
2. `settings` をクリックします
1919
3. `secrets and variables` メニューの下の `actions` をクリックします
20-
4. `New repository variable` をクリックしてOpenAI の APIキーの登録を行います。変数名は `OPENAI_API_KEY` にしてください。変数の値にはOpenAIのAPIキーを入力します。 (OpenAIのホームページからAPIキーを取得できます。)
20+
4. `New repository variable` をクリックして OpenAI の API キーの登録を行います。変数名は `OPENAI_API_KEY` にしてください。変数の値には OpenAI の API キーを入力します。 (OpenAI のホームページから API キーを取得できます。)
2121
<img width="1465" alt="image" src="https://user-images.githubusercontent.com/13167934/218533628-3974b70f-c423-44b0-b096-d1ec2ace85ea.png">
2222

2323
### Start using
2424

25-
1. このbotは新しいプルリクエストが作成されたときに自動的にコードレビューを行います。レビュー結果はプルリクエストのタイムラインやファイル変更部分に表示されます。
25+
1. この bot は新しいプルリクエストが作成されたときに自動的にコードレビューを行います。レビュー結果はプルリクエストのタイムラインやファイル変更部分に表示されます。
2626
2. `git push` によりプルリクエストの更新が行われたときにも自動的にコードレビューを行います。
2727

2828
example:
@@ -63,6 +63,7 @@ jobs:
6363
# Optional
6464
LANGUAGE: Chinese
6565
MODEL:
66+
PROMPT:
6667
top_p: 1
6768
temperature: 1
6869
```
@@ -71,7 +72,7 @@ jobs:
7172
7273
1. このリポジトリをクローンします
7374
2. `.env.example` を `.env` にリネームし、必要な環境変数を設定します
74-
3. 以下のコマンドを順番に実行することで依存関係をインストールし、botを起動します
75+
3. 以下のコマンドを順番に実行することで依存関係をインストールし、bot を起動します
7576

7677
```sh
7778
npm i

README.ko.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Translation Versions: [ENGLISH](./README.md) | [中文简体](./README.zh-CN.md)
77
## 사용법
88

99
❗️⚠️비용을 고려하여 BOT은 테스트 목적으로만 사용되며, 현재 AWS Lambda에 배포되어 속도 제한을 받고 있습니다. 따라서 불안정한 상황은 완전히 정상적입니다. 응용 프로그램을 직접 배포하는 것이 좋습니다.
10+
1011
### 설치
1112

1213
설치: [apps/cr-gpt](https://github.com/apps/cr-gpt);
@@ -58,7 +59,9 @@ jobs:
5859
env:
5960
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6061
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
62+
# optional
6163
LANGUAGE: Korean
64+
PROMPT:
6265
```
6366
6467
## Self-hosting

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Translation Versions: [ENGLISH](./README.md) | [中文简体](./README.zh-CN.md)
66

77
## Bot Usage
88

9-
❗️⚠️ `Due to cost considerations, BOT is only used for testing purposes and is currently deployed on AWS Lambda with ratelimit restrictions. Therefore, unstable situations are completely normal. It is recommended to deploy an app by yourself.`
9+
❗️⚠️ `Due to cost considerations, BOT is only used for testing purposes and is currently deployed on AWS Lambda with ratelimit restrictions. Therefore, unstable situations are completely normal. It is recommended to deploy an app by yourself.`
1010

1111
### Install
1212

@@ -62,6 +62,7 @@ jobs:
6262
LANGUAGE: Chinese
6363
OPENAI_API_ENDPOINT: https://api.openai.com/v1
6464
MODEL:
65+
PROMPT:
6566
top_p: 1
6667
temperature: 1
6768
```

README.zh-CN.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## 用法
88

9-
❗️⚠️ 鉴于成本考虑,BOT仅用于测试目的,并目前在AWS Lambda上部署并受到速率限制。因此,不稳定的情况是完全正常的。建议自己部署应用程序。
9+
❗️⚠️ 鉴于成本考虑,BOT 仅用于测试目的,并目前在 AWS Lambda 上部署并受到速率限制。因此,不稳定的情况是完全正常的。建议自己部署应用程序。
1010

1111
### 安装
1212

@@ -17,12 +17,12 @@
1717
1. 转到你要集成此机器人的仓库首页
1818
2. 点击`settings`
1919
3. 点击`actions`在下面`secrets and variables`
20-
4. 切换到`Variables`选项,创建一个新变量`OPENAI_API_KEY`值为你的open api 的key<img width="1465" alt="image" src="https://user-images.githubusercontent.com/13167934/218533628-3974b70f-c423-44b0-b096-d1ec2ace85ea.png">
20+
4. 切换到`Variables`选项,创建一个新变量`OPENAI_API_KEY`值为你的 open api 的 key<img width="1465" alt="image" src="https://user-images.githubusercontent.com/13167934/218533628-3974b70f-c423-44b0-b096-d1ec2ace85ea.png">
2121

2222
### 开始使用
2323

2424
1. 当你创建一个新的 Pull request 时,机器人会自动进行代码审查,审查信息将显示在 pr timeline / file changes 部分。
25-
2.`git push`更新PR之后,cr bot 将重新审查更改的文件
25+
2.`git push`更新 PR 之后,cr bot 将重新审查更改的文件
2626

2727
例子:
2828

@@ -58,14 +58,16 @@ jobs:
5858
env:
5959
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6060
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
61+
# optional
6162
LANGUAGE: Chinese
63+
PROMPT:
6264
```
6365
6466
## 自托管
6567
6668
1. 克隆代码
6769
2. 复制`.env.example`到`.env`, 并填写环境变量
68-
3. 安装deps并运行
70+
3. 安装 deps 并运行
6971

7072
```sh
7173
npm i
@@ -111,4 +113,3 @@ docker run -e APP_ID=<app-id> -e PRIVATE_KEY=<pem-value> cr-bot
111113
## License
112114

113115
[ISC](LICENSE)© 2023 anc95
114-

README.zh-TW.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
1. 轉到你要集成此機器人的倉庫首頁
1616
2. 點擊`settings`
1717
3. 點擊`actions`在下面`secrets and variables`
18-
4. 切換到`Variables`選項,創建一個新變量`OPENAI_API_KEY`值為你的open api 的key<img width="1465" alt="image" src="https://user-images.githubusercontent.com/13167934/218533628-3974b70f-c423-44b0-b096-d1ec2ace85ea.png">
18+
4. 切換到`Variables`選項,創建一個新變量`OPENAI_API_KEY`值為你的 open api 的 key<img width="1465" alt="image" src="https://user-images.githubusercontent.com/13167934/218533628-3974b70f-c423-44b0-b096-d1ec2ace85ea.png">
1919

2020
### 開始使用
2121

2222
1. 當你創建一個新的 Pull request 時,機器人會自動進行代碼審查,審查信息將顯示在 pr timeline / file changes 部分。
23-
2.`git push`更新PR之後,cr bot 將重新審查更改的文件
23+
2.`git push`更新 PR 之後,cr bot 將重新審查更改的文件
2424

2525
例子:
2626

@@ -56,13 +56,15 @@ jobs:
5656
env:
5757
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5858
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
59+
# optional
60+
PROMPT:
5961
```
6062
6163
## 自托管
6264
6365
1. 克隆代碼
6466
2. 復製`.env.example`到`.env`, 並填寫環境變量
65-
3. 安裝deps並運行
67+
3. 安裝 deps 並運行
6668

6769
```sh
6870
npm i

action/index.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148165,18 +148165,21 @@ const robot = (app) => {
148165148165
const repo = context.repo();
148166148166
const chat = await loadChat(context);
148167148167
if (!chat) {
148168+
console.log('Chat initialized fialed');
148168148169
return 'no chat';
148169148170
}
148170148171
const pull_request = context.payload.pull_request;
148171148172
if (pull_request.state === 'closed' ||
148172148173
pull_request.locked ||
148173148174
pull_request.draft) {
148175+
console.log('invalid event paylod');
148174148176
return 'invalid event paylod';
148175148177
}
148176148178
const target_label = process.env.TARGET_LABEL;
148177148179
if (target_label &&
148178148180
(!pull_request.labels?.length ||
148179148181
pull_request.labels.every((label) => label.name !== target_label))) {
148182+
console.log('no target label attached');
148180148183
return 'no target label attached';
148181148184
}
148182148185
const data = await context.octokit.repos.compareCommits({
@@ -148197,6 +148200,7 @@ const robot = (app) => {
148197148200
changedFiles = changedFiles?.filter((file) => filesNames.includes(file.filename));
148198148201
}
148199148202
if (!changedFiles?.length) {
148203+
console.log('no target label attached');
148200148204
return 'no change';
148201148205
}
148202148206
console.time('gpt cost');
@@ -148207,6 +148211,7 @@ const robot = (app) => {
148207148211
continue;
148208148212
}
148209148213
if (!patch || patch.length > MAX_PATCH_COUNT) {
148214+
console.log(`${file.filename} skipped caused by its diff is too large`);
148210148215
continue;
148211148216
}
148212148217
const res = await chat?.codeReview(patch);
@@ -148256,7 +148261,9 @@ class Chat {
148256148261
const answerLanguage = process.env.LANGUAGE
148257148262
? `Answer me in ${process.env.LANGUAGE},`
148258148263
: '';
148259-
return `Bellow is the code patch, please help me do a brief code review,${answerLanguage} if any bug risk and improvement suggestion are welcome
148264+
const prompt = process.env.PROMPT ||
148265+
'Bellow is the code patch, please help me do a brief code review, if any bug risk and improvement suggestion are welcome';
148266+
return `${prompt}, ${answerLanguage}:
148260148267
${patch}
148261148268
`;
148262148269
};

src/chat.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export class Chat {
1919
? `Answer me in ${process.env.LANGUAGE},`
2020
: '';
2121

22-
return `Bellow is the code patch, please help me do a brief code review,${answerLanguage} if any bug risk and improvement suggestion are welcome
22+
const prompt =
23+
process.env.PROMPT ||
24+
'Bellow is the code patch, please help me do a brief code review, if any bug risk and improvement suggestion are welcome';
25+
26+
return `${prompt}, ${answerLanguage}:
2327
${patch}
2428
`;
2529
};

0 commit comments

Comments
 (0)