Skip to content

Commit

Permalink
Add deploy command
Browse files Browse the repository at this point in the history
  • Loading branch information
memochou1993 committed Dec 16, 2022
1 parent 9c9ffab commit c48d388
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ GPT AI Assistant 是基於 OpenAI API 與 LINE Messaging API 實作的範例應
`ai <text>` | 詢問 AI 問題
`ai --auto-reply off` | 關閉 AI 自動回覆,須設置 `VERCEL_ACCESS_TOKEN` 環境變數
`ai --auto-reply on` | 開啟 AI 自動回覆,須設置 `VERCEL_ACCESS_TOKEN` 環境變數
`deploy` | 部署應用程式,須設置 `VERCEL_WEBHOOK_URL` 環境變數

## 環境變數

Expand All @@ -74,6 +75,7 @@ GPT AI Assistant 是基於 OpenAI API 與 LINE Messaging API 實作的範例應
--- | --- | ---
`APP_DEBUG` | `false` | 決定是否印出訊息,可設置為 `true``false`
`VERCEL_ACCESS_TOKEN` | `null` | Vercel 的 [access token](/demo/vercel-access-token.png)
`VERCEL_WEBHOOK_URL` | `null` | Vercel 的 [Webhook URL](/demo/vercel-webhook-url.png)
`OPENAI_API_KEY` | `null` | OpenAI 的 [API key](/demo/openai-api-key.png)
`OPENAI_COMPLETION_INIT_LANG` | `zh` | 決定初始語言,可設置為 `zh``en`
`OPENAI_COMPLETION_MODEL` | `text-davinci-003` | 參見 [model](https://beta.openai.com/docs/api-reference/completions/create#completions/create-model) 說明
Expand Down
1 change: 0 additions & 1 deletion assistant/assistant.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import config from '../config/index.js';
import {
EVENT_TYPE_MESSAGE,
MESSAGE_TYPE_TEXT,
Expand Down
5 changes: 5 additions & 0 deletions assistant/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
COMMAND_AI,
COMMAND_AI_AUTO_REPLY_OFF,
COMMAND_AI_AUTO_REPLY_ON,
COMMAND_DEPLOY,
COMMAND_VERSION,
} from '../constants/command/index.js';

Expand Down Expand Up @@ -34,6 +35,10 @@ class Event {
return this.input === COMMAND_VERSION;
}

get isCommandDeploy() {
return this.input === COMMAND_DEPLOY;
}

get isCommandAI() {
return this.input.startsWith(COMMAND_AI);
}
Expand Down
1 change: 1 addition & 0 deletions constants/command/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const COMMAND_VERSION = 'version';
export const COMMAND_DEPLOY = 'deploy';
export const COMMAND_AI = 'ai';
export const COMMAND_AI_AUTO_REPLY_OFF = 'ai --auto-reply off';
export const COMMAND_AI_AUTO_REPLY_ON = 'ai --auto-reply on';
Binary file added demo/vercel-webhook-url.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion services/line/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ instance.interceptors.request.use((c) => {
return c;
});

export const replyMessages = ({
const replyMessages = ({
replyToken,
messages,
}) => instance.post('/v2/bot/message/reply', {
replyToken,
messages,
});

export {
replyMessages,
};
6 changes: 5 additions & 1 deletion services/openai/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ instance.interceptors.request.use((c) => {
return c;
});

export const createCompletion = ({
const createCompletion = ({
model = config.OPENAI_COMPLETION_MODEL,
prompt,
temperature = config.OPENAI_COMPLETION_TEMPERATURE,
Expand All @@ -39,3 +39,7 @@ export const createCompletion = ({
presence_penalty: presencePenalty,
stop,
});

export {
createCompletion,
};
15 changes: 10 additions & 5 deletions services/vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ instance.interceptors.request.use((c) => {
return c;
});

export const fetchEnvironments = () => instance.get(`/v9/projects/${config.VERCEL_GIT_REPO_SLUG}/env`);
const fetchEnvironments = () => instance.get(`/v9/projects/${config.VERCEL_GIT_REPO_SLUG}/env`);

export const createEnvironment = ({
const createEnvironment = ({
key,
value,
type = 'encrypted',
Expand All @@ -28,7 +28,7 @@ export const createEnvironment = ({
target,
});

export const updateEnvironment = ({
const updateEnvironment = ({
id,
value,
type = 'encrypted',
Expand All @@ -39,6 +39,11 @@ export const updateEnvironment = ({
target,
});

export const deploy = () => instance.post(config.VERCEL_WEBHOOK_URL);
const deploy = () => axios.post(config.VERCEL_WEBHOOK_URL);

export default null;
export {
fetchEnvironments,
createEnvironment,
updateEnvironment,
deploy,
};
6 changes: 5 additions & 1 deletion tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import {
MESSAGE_TYPE_TEXT,
} from '../services/line/index.js';

export const createEvents = (messages) => messages.map((message) => ({
const createEvents = (messages) => messages.map((message) => ({
replyToken: '',
type: EVENT_TYPE_MESSAGE,
source: { type: 'user', userId: '000000' },
message: { type: MESSAGE_TYPE_TEXT, text: message },
}));

export {
createEvents,
};

export default null;

0 comments on commit c48d388

Please sign in to comment.