From a87a384e5ebc62f529b026309363435d7465cb39 Mon Sep 17 00:00:00 2001 From: Potter <75838259@qq.com> Date: Sat, 23 Nov 2024 23:18:47 +0800 Subject: [PATCH 1/3] ci: add OpenAI engine support and environment variables for OpenAI API key and model --- .env.example | 5 +++++ .github/workflows/ci.yml | 2 ++ 2 files changed, 7 insertions(+) diff --git a/.env.example b/.env.example index b6de7a1..d57c047 100644 --- a/.env.example +++ b/.env.example @@ -7,3 +7,8 @@ AMAZON_SECRET_ACCESS_KEY = BAIDU_APP_ID = BAIDU_SECRET_KEY = + +DEEPL_KEY = + +OPEN_AI_API_KEY = +OPEN_AI_MODEL = diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e288953..dc7f842 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,8 @@ env: BAIDU_APP_ID: ${{ secrets.BAIDU_APP_ID }} BAIDU_SECRET_KEY: ${{ secrets.BAIDU_SECRET_KEY }} DEEPL_KEY: ${{ secrets.DEEPL_KEY }} + OPEN_AI_API_KEY: ${{ secrets.OPEN_AI_API_KEY }} + OPEN_AI_MODEL: ${{ secrets.OPEN_AI_MODEL }} jobs: build: From c0b2afe33630d4874ff43465b4a44bac5d890b75 Mon Sep 17 00:00:00 2001 From: Potter <75838259@qq.com> Date: Sat, 23 Nov 2024 23:32:11 +0800 Subject: [PATCH 2/3] test: adjust open ai test judgment --- src/engines/openai.ts | 3 --- test/translate.test.ts | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/engines/openai.ts b/src/engines/openai.ts index f8b75c7..e735df1 100644 --- a/src/engines/openai.ts +++ b/src/engines/openai.ts @@ -42,8 +42,6 @@ export function openai(options: OpenAIEngineOption): Engine { `, }; - console.log("prompt:", prompt.content); - const res = await fetch(url, { method: "POST", headers: { @@ -69,7 +67,6 @@ export function openai(options: OpenAIEngineOption): Engine { .trim() .split("\n") .map((item: string) => item.trim()); - console.log("translations:", translations); return translations; }, diff --git a/test/translate.test.ts b/test/translate.test.ts index 37cb6d7..0daf8e6 100644 --- a/test/translate.test.ts +++ b/test/translate.test.ts @@ -105,13 +105,14 @@ describe("translator", () => { model: process.env.OPEN_AI_MODEL as OpenAIModel })); + // Note: Since open ai has different translation results for the same parameters, we only test if the result is returned here. + const res1 = await translator.translate("hello", { to: "Chinese", engine: "openai" }); - expect(res1).toEqual(["你好"]); + expect(res1.length >= 1).toBe(true); const res2 = await translator.translate(["hello", "good"], { from: "en", to: "Chinese", engine: "openai" }); - expect(res2).toEqual(["你好", "好"]); + expect(res2.length >= 2).toBe(true); - // Note: Since open ai has different translation results for the same parameters, we only test if the result is returned here. const translateText = ['This function adds two numbers', '@param', ' ', '— first number', '@param', ' ', '— second number']; const res3 = await translator.translate(translateText, { from: "en", to: "Chinese", engine: "openai" }); expect(res3.length != 0).toBe(true); From 65eba796352799dd708a93016e1534ab262cc9f3 Mon Sep 17 00:00:00 2001 From: Potter <75838259@qq.com> Date: Sat, 23 Nov 2024 23:36:10 +0800 Subject: [PATCH 3/3] chore(release): v0.1.1 --- CHANGELOG.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfbd210..1203ba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ # Changelog +## v0.1.1 + +[compare changes](https://github.com/yxw007/translate/compare/v0.1.0...v0.1.1) + +### ✅ Tests + +- Adjust open ai test judgment ([c0b2afe](https://github.com/yxw007/translate/commit/c0b2afe)) + +### 🤖 CI + +- Add OpenAI engine support and environment variables for OpenAI API key and model ([a87a384](https://github.com/yxw007/translate/commit/a87a384)) + +### ❤️ Contributors + +- Potter <75838259@qq.com> + ## v0.1.0 [compare changes](https://github.com/yxw007/translate/compare/v0.0.20...v0.1.0) diff --git a/package.json b/package.json index 1c5c133..6da9e42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yxw007/translate", - "version": "0.1.0", + "version": "0.1.1", "description": "A simple library that supports multiple translation engines", "author": "Potter", "homepage": "https://github.com/yxw007/translate",