Skip to content

Commit

Permalink
g4f version update
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy_lin.林均祥 committed May 14, 2024
1 parent 8dee2fc commit da2f5cf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 0 additions & 1 deletion .github/workflows/translate-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ jobs:
uses: ./
with:
token: ${{ secrets.Action_Bot }} # Your token
g4f_provider: g4f.Provider.DeepAi # You can change this provider
langs: "en,zh-TW,zh-CN,French,Arabic" # You can define any langs
2 changes: 0 additions & 2 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@
uses: Lin-jun-xiang/action-translate-readme@v2 # Based on the tag
with:
token: ${{ secrets.Action_Bot }} # Based on step2 name
g4f_provider: g4f.Provider.DeepAi # You can change this provider
langs: "en,zh-TW,zh-CN,French,Arabic" # You can define any langs
```

`.yml`中有三個參數要特別注意:

* `token`: 根據步驟2,在repos中建立的token
* `g4f_provider`: gpt 的提供者,更多請參考[連結](https://github.com/xtekky/gpt4free/tree/main#gpt-35--gpt-4)
* `langs`: 想要產生的語言版本,務必用`,`分隔不同語言,例如:
* `"en"`: 僅翻譯英文版
* `"en,zh-TW"`: 翻譯英文、繁體中文
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ runs:
shell: bash
run: |
pip install PyExecJS
pip install nest_asyncio
pip install -U g4f
pip install --upgrade tenacity
- name: Translate README
shell: bash
working-directory: .
run: |
export PROVIDER=${{ inputs.g4f_provider }}
export LANGS=${{ inputs.langs }}
python $GITHUB_ACTION_PATH/translation.py
Expand Down
19 changes: 6 additions & 13 deletions translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@
import subprocess

import g4f
from g4f.client import AsyncClient
from tenacity import retry, stop_after_attempt

g4f.debug.logging = True

LAGNS = os.environ.get('LANGS').split(',')

PROVIDER_MAPPING = {
f'g4f.Provider.{provider}': getattr(g4f.Provider, provider)
for provider in g4f.Provider.__all__
}
try:
PROVIDER = PROVIDER_MAPPING[os.environ.get('PROVIDER')]
except:
PROVIDER = None


def run_shell_command(command: str) -> tuple:
result = subprocess.run(
Expand All @@ -33,14 +25,15 @@ def run_shell_command(command: str) -> tuple:

@retry(stop=stop_after_attempt(15))
async def chat_completion(query: str) -> str:
response = await g4f.ChatCompletion.create_async(
model=g4f.models.gpt_35_long,
client = AsyncClient()

response = await client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": query}],
provider=PROVIDER
)
if response == '' or response is None:
raise Exception
return response
return response.choices[0].message.content


async def translate_content(content: str, output_lang: str) -> str:
Expand Down

0 comments on commit da2f5cf

Please sign in to comment.