Skip to content

Commit

Permalink
feat: update github action to automatically translate changes into ch…
Browse files Browse the repository at this point in the history
…inese
  • Loading branch information
fang2hou committed Apr 10, 2023
1 parent 6e656a4 commit 1ba78cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
npm install discord.js
echo "ℹ️ Installing ts-node..."
npm install ts-node
echo "ℹ️ Installing openai..."
npm install openai
- name: ⚒️ Cross Build All Binaries
run: make cross-build-all
Expand Down
29 changes: 29 additions & 0 deletions scripts/discord_release_notification.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {readFile} from 'fs';
import {APIEmbedField, EmbedAuthorOptions, EmbedBuilder, RestOrArray, WebhookClient} from 'discord.js';

const {Configuration, OpenAIApi} = require("openai");

const REPOSITORY: string = process.env.GITHUB_REPOSITORY || '';
const TAG: string = process.env.GITHUB_REF_NAME || '';
const GITHUB_URL: string = process.env.GITHUB_SERVER_URL || '';
const DISCORD_WEBHOOK_URL: string = process.env.DISCORD_WEBHOOK_URL || '';
const OPENAI_API_KEY: string = process.env.OPENAI_API_KEY || '';

if (REPOSITORY.length === 0) {
console.error('GITHUB_REPOSITORY is not set');
Expand Down Expand Up @@ -74,6 +76,33 @@ readFile('./changes.md', 'utf8', (err: NodeJS.ErrnoException | null, data: strin
}
});


if (OPENAI_API_KEY.length !== 0) {
const openai = new OpenAIApi(new Configuration({
apiKey: OPENAI_API_KEY,
}));

openai.createChatCompletion({
model: "gpt-3.5-turbo-0301",
messages: [
{
role: "user",
content: "You are a translator for translating the software changelog to chinese," +
"your answer should not include anything outside the list." +
"Do not translate the word 'token' and ':.*:', just keep it as it is."
},
{
role: "user",
content: releaseNote
},
],
}).then((response: any) => {
releaseNote = response.data.choices[0].message;
}).catch((err: any) => {
console.error(err);
});
}

fields.push(
{name: '**变更列表**', value: releaseNote, inline: false},
{name: '\u200B', value: '\u200B', inline: false}
Expand Down

0 comments on commit 1ba78cc

Please sign in to comment.