-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b665b0a
commit 901a7cd
Showing
5 changed files
with
59 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
APP_ENV=local | ||
APP_DEBUG=true | ||
APP_URL= | ||
APP_PORT=3000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
.vscode | ||
.env | ||
.env.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,34 +135,14 @@ Install dependencies. | |
npm ci | ||
``` | ||
|
||
Copy `.env.example` to `.env`. | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
Set the environment variables as follows: | ||
|
||
```env | ||
APP_ENV=local | ||
APP_DEBUG=true | ||
APP_PORT=3000 | ||
# optional | ||
# VERCEL_GIT_REPO_SLUG=gpt-ai-assistant | ||
# VERCEL_ACCESS_TOKEN=<your_vercel_access_token> | ||
# VERCEL_DEPLOY_HOOK_URL=<your_vercel_deploy_hook_url> | ||
### Tests | ||
|
||
# optional | ||
# OPENAI_API_KEY=<your_openai_api_key> | ||
Copy `.env.example` to `.env.test`. | ||
|
||
# optional | ||
# LINE_CHANNEL_ACCESS_TOKEN=<your_line_channel_access_token> | ||
# LINE_CHANNEL_SECRET=<your_line_channel_secret> | ||
```bash | ||
cp .env.example .env.test | ||
``` | ||
|
||
### Tests | ||
|
||
Run the tests. | ||
|
||
```bash | ||
|
@@ -172,34 +152,44 @@ npm run test | |
Check the results. | ||
|
||
```bash | ||
> gpt-ai-assistant@1.0.0 test | ||
> gpt-ai-assistant@0.0.0 test | ||
> jest | ||
|
||
console.info | ||
=== 000000 === | ||
|
||
AI: 嗨!我可以怎麼幫助你? | ||
Human: 嗨? | ||
AI: OK | ||
|
||
at Assistant.info [as debug] (assistant/assistant.js:55:28) | ||
|
||
PASS assistant/index.test.js | ||
✓ assistant works (1689 ms) | ||
AI: OK! | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: 2.579 s, estimated 4 s | ||
Ran all test suites. | ||
Time: 1 s | ||
``` | ||
|
||
### Using Proxy Server | ||
|
||
Copy `.env.example` to `.env`. | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
Set the environment variables as follows: | ||
|
||
```env | ||
APP_ENV=production | ||
APP_DEBUG=true | ||
APP_PORT=3000 | ||
VERCEL_GIT_REPO_SLUG=gpt-ai-assistant | ||
VERCEL_ACCESS_TOKEN=<your_vercel_access_token> | ||
VERCEL_DEPLOY_HOOK_URL=<your_vercel_deploy_hook_url> | ||
OPENAI_API_KEY=<your_openai_api_key> | ||
LINE_CHANNEL_ACCESS_TOKEN=<your_line_channel_access_token> | ||
LINE_CHANNEL_SECRET=<your_line_channel_secret> | ||
``` | ||
|
||
Start a local server. | ||
|
@@ -214,7 +204,7 @@ Start a proxy server. | |
ngrok http 3000 | ||
``` | ||
|
||
Go back to the website, modify the "Webhook URL" to e.g. "<https://0000-0000-0000.jp.ngrok.io>" and click the "Update" button. | ||
Go back to the [LINE](https://developers.line.biz/) website, modify the "Webhook URL" to e.g. "<https://0000-0000-0000.jp.ngrok.io/webhook>" and click the "Update" button. | ||
|
||
Send a message from the LINE mobile app. | ||
|
||
|
@@ -231,50 +221,6 @@ Human: 嗨? | |
AI: 很高興見到你!有什麼可以為你服務的嗎? | ||
``` | ||
|
||
### Using Local Server | ||
|
||
Start a local server. | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
Send a dummy request to the local server. | ||
|
||
```bash | ||
curl --request POST \ | ||
--url http://localhost:3000/webhook \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"events": [ | ||
{ | ||
"type": "message", | ||
"source": { | ||
"type": "user", | ||
"userId": "000000" | ||
}, | ||
"message": { | ||
"type": "text", | ||
"text": "我是誰" | ||
} | ||
} | ||
] | ||
}' | ||
``` | ||
|
||
Check the results. | ||
|
||
```bash | ||
> [email protected] dev | ||
> node api/index.js | ||
|
||
=== 000000 === | ||
|
||
AI: 嗨!我可以怎麼幫助你? | ||
Human: 我是誰? | ||
AI: OK | ||
``` | ||
|
||
## Changelog | ||
|
||
Detailed changes for each release are documented in the [release notes](https://github.com/memochou1993/gpt-ai-assistant/releases). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,35 +169,15 @@ cd gpt-ai-assistant | |
npm ci | ||
``` | ||
|
||
建立 `.env` 檔。 | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
設置環境變數如下: | ||
|
||
```env | ||
APP_ENV=local | ||
APP_DEBUG=true | ||
APP_PORT=3000 | ||
# optional | ||
# VERCEL_GIT_REPO_SLUG=gpt-ai-assistant | ||
# VERCEL_ACCESS_TOKEN=<your_vercel_access_token> | ||
# VERCEL_DEPLOY_HOOK_URL=<your_vercel_deploy_hook_url> | ||
### 測試 | ||
|
||
# optional | ||
# OPENAI_API_KEY=<your_openai_api_key> | ||
建立 `.env.test` 檔。 | ||
|
||
# optional | ||
# LINE_CHANNEL_ACCESS_TOKEN=<your_line_channel_access_token> | ||
# LINE_CHANNEL_SECRET=<your_line_channel_secret> | ||
```bash | ||
cp .env.example .env.test | ||
``` | ||
|
||
### 測試 | ||
|
||
在終端機使用以下指令,運行測試,向 OpenAI 伺服器發送請求。 | ||
在終端機使用以下指令,運行測試。 | ||
|
||
```bash | ||
npm run test | ||
|
@@ -206,34 +186,44 @@ npm run test | |
查看結果。 | ||
|
||
```bash | ||
> gpt-ai-assistant@1.0.0 test | ||
> gpt-ai-assistant@0.0.0 test | ||
> jest | ||
|
||
console.info | ||
=== 000000 === | ||
|
||
AI: 嗨!我可以怎麼幫助你? | ||
Human: 嗨? | ||
AI: | ||
|
||
at Assistant.info [as debug] (assistant/assistant.js:55:28) | ||
|
||
PASS assistant/index.test.js | ||
✓ assistant works (1689 ms) | ||
AI: OK! | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: 2.579 s, estimated 4 s | ||
Ran all test suites. | ||
Time: 1 s | ||
``` | ||
|
||
### 反向代理 | ||
### 使用代理伺服器 | ||
|
||
建立 `.env` 檔。 | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
修改環境變數如下: | ||
設置環境變數如下: | ||
|
||
```env | ||
APP_ENV=production | ||
APP_DEBUG=true | ||
APP_PORT=3000 | ||
VERCEL_GIT_REPO_SLUG=gpt-ai-assistant | ||
VERCEL_ACCESS_TOKEN=<your_vercel_access_token> | ||
VERCEL_DEPLOY_HOOK_URL=<your_vercel_deploy_hook_url> | ||
OPENAI_API_KEY=<your_openai_api_key> | ||
LINE_CHANNEL_ACCESS_TOKEN=<your_line_channel_access_token> | ||
LINE_CHANNEL_SECRET=<your_line_channel_secret> | ||
``` | ||
|
||
在終端機使用以下指令,啟動一個本地伺服器。 | ||
|
@@ -248,7 +238,7 @@ npm run dev | |
ngrok http 3000 | ||
``` | ||
|
||
回到 Line 平台,修改「Webhook URL」,例如「<https://0000-0000-0000.jp.ngrok.io>」,點選「Update」按鈕。 | ||
回到 [LINE](https://developers.line.biz/) 平台,修改「Webhook URL」,例如「<https://0000-0000-0000.jp.ngrok.io/webhook>」,點選「Update」按鈕。 | ||
|
||
使用 LINE 手機應用程式發送訊息。 | ||
|
||
|
@@ -265,50 +255,6 @@ Human: 嗨? | |
AI: 很高興見到你!有什麼可以為你服務的嗎? | ||
``` | ||
|
||
### 模擬請求 | ||
|
||
在終端機使用以下指令,啟動一個本地伺服器。 | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
在另一個終端機使用以下指令,模擬 LINE 伺服器向本地伺服器發送請求,再由本地伺服器向 OpenAI 伺服器發送請求。 | ||
|
||
```bash | ||
curl --request POST \ | ||
--url http://localhost:3000/webhook \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"events": [ | ||
{ | ||
"type": "message", | ||
"source": { | ||
"type": "user", | ||
"userId": "000000" | ||
}, | ||
"message": { | ||
"type": "text", | ||
"text": "我是誰" | ||
} | ||
} | ||
] | ||
}' | ||
``` | ||
|
||
查看結果。 | ||
|
||
```bash | ||
> [email protected] dev | ||
> node api/index.js | ||
|
||
=== 000000 === | ||
|
||
AI: 嗨!我可以怎麼幫助你? | ||
Human: 我是誰? | ||
AI: | ||
``` | ||
|
||
## 更新日誌 | ||
|
||
請到「[Releases](https://github.com/memochou1993/gpt-ai-assistant/releases)」頁面查看發布通知。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters