Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-jun-xiang committed Sep 25, 2023
1 parent 22a1361 commit 43a9523
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 46 deletions.
47 changes: 5 additions & 42 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,20 @@

[英文版](README.md) | [中文版README.md](README.zh-TW.md)

# What's changed for action-translate-readme?

隨著 ChatGPT 的橫空出世,作者想到本專案的翻譯任務可以交給 GPT 實現,透過開源專案 [`gpt4free`](https://github.com/xtekky/gpt4free),我們得以實現免費的 GPT API,希望可以提升本專案的翻譯能力!

* 版本一的翻譯方式: 透過 Linux 第三方套件實現的 (`translation.sh`)
* 翻譯效果: 差,與 google 翻譯效果差不多
* 翻譯速度: 慢
* 穩定性: 高,可以確保每次都能正確翻譯

* 版本二的翻譯方式: 透過 GPT 進行翻譯任務 (`translation.py`)
* 翻譯效果: 好
* 翻譯速度: 時快時慢
* 穩定性: 低

由於 `gpt4free` 是透過逆向工程來實現免費調用 api,因此調用過程可能會碰到異常問題。作者在調用 api 函式時添加上 `retry` 技術 (發生異常,會重新執行) 來避免翻譯失敗,相對地,翻譯速度就會隨著 retry 次數增加。

> **注意**,在 `gpt4free` 中有[不同的 Provider](https://github.com/xtekky/gpt4free#models),這些 Provider 就是提供調用 api 的來源,如果無法正常使用本專案自動翻譯工具,通常問題來自於當前使用的 Provider 已經 **Inactive**
>
> 因此在各位的 `translate-readme.yml` 檔案中,可以自行設定該[參數](.github\workflows\translate-readme.yml) (預設為`g4f.Provider.DeepAi`)。
>
> 此外,由於是**生成式AI**的技術,並不能確保每次翻譯正確,如果翻譯效果不好,可以多重複幾次。

# Introduction

* 我們都知道寫文檔很費時間,但是現在有一個解決方案可以讓你節省一半的時間. 這就是我們的`action-translate-readme`

* 有了這個工具,你可以自動翻譯`README.md`文件,不僅可以翻譯,還可以翻譯**內聯代碼、表情、代碼塊、HTML標籤和鏈接等各種元素**

* 其運行原理是通過`Github Actions`實現自動化,只需要推送更新的README文件,翻譯後的README(zh或en)文件即可自動更新

* 持續集成(CI)

* **通過 Github Action 自動翻譯 README 的語言**

* 更新`README.md`並推送,這個動作會自動更新`README.zh-TW.md`
(更新 `README.zh-TW.md` 自動更新 `README.md`)

* 寫文檔的時間節省一半.

# Features
* 我們都知道寫README文檔很費時間,但是現在有一個解決方案可以讓你節省一半的時間. 這就是我們的`action-translate-readme`

* 未翻譯:
* 內聯代碼 (`inline_code`)
* 通過 `gpt3.5` 翻譯不同語言版本的 README

* 用於表情符號
* 透過 **Github Actions(CI/CD) 自動提交(commit、push)** 翻譯後的檔案

* 代碼塊
* 例如: **撰寫****修改**英文版README,自動生成繁體中文、簡體中文、法文...等版本 README

* HTML 標籤
備註: v1版本的翻譯器是透過 `Linux` 第三方套件實現;v2版本是透過 [`g4f`](https://github.com/xtekky/gpt4free) 免費調用 openai api 實現翻譯

* 鏈接

# How to use ?

Expand Down
4 changes: 4 additions & 0 deletions commit.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
LATEST_COMMIT_MSG=$(git show -s --format='%s')

git add -N .

dir_files=$(ls)
changed_files=$(git diff --name-only)

echo "The current files: $dir_files"
echo "You auto changed $changed_files"

if [[ $changed_files =~ "README" ]]; then
Expand Down
1 change: 0 additions & 1 deletion test.md

This file was deleted.

13 changes: 10 additions & 3 deletions translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

class AvailableProviders:
providers = [getattr(g4f.Provider, provider) for provider in g4f.Provider.__all__]
unuse_providers = [g4f.Provider.ChatBase, g4f.Provider.Yqcloud, g4f.Provider.Bing]

@classmethod
def _test_provider(cls, provider: g4f.Provider) -> str:
try:
if provider in cls.unuse_providers:
return
g4f.ChatCompletion.create(
model='gpt-3.5-turbo',
messages=[{"role": "user", "content": 'Hello world'}],
Expand All @@ -25,7 +28,7 @@ def _test_provider(cls, provider: g4f.Provider) -> str:
return

@classmethod
def show(cls, threads_num: int = 4) -> list:
def show(cls, threads_num: int = 8) -> list:
"""Test all the providers then find out which are available"""
with ThreadPool(threads_num) as pool:
available_providers = pool.map(
Expand Down Expand Up @@ -100,13 +103,14 @@ def main():
if "README" not in file:
print('no README changed.')
return
print(f'{file} changed.')

with open(file, "r", encoding="utf-8") as f:
content = f.read()

for output_lang in LAGNS:
def multi_exec(output_lang: str):
if output_lang in file:
continue
return
translated_content = translate_content(content, output_lang)
output_file = f'README.{output_lang}.md'
output_file = output_file.replace('.en', '')
Expand All @@ -115,6 +119,9 @@ def main():
f.write(translated_content)
print(f"Translated content written to {output_file}")

with ThreadPool(8) as pool:
pool.map(multi_exec, LAGNS)


if __name__ == "__main__":
main()

0 comments on commit 43a9523

Please sign in to comment.