1028.py
All checks were successful
test / job_1 (push) Successful in 1m12s

This commit is contained in:
298977887 2024-10-28 21:12:08 +08:00
parent 94c43069c8
commit a2258f374b
2 changed files with 14 additions and 8 deletions

View File

@ -46,7 +46,7 @@ jobs:
# 安装 Python 依赖,使用清华大学镜像源
- name: 📥 安装 Python 依赖
run: |
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests deep-translator
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
# 翻译更新日志
- name: 📦 运行翻译更新输出更新日志txt文件

View File

@ -1,7 +1,7 @@
import requests
from datetime import datetime, timezone, timedelta
from deep_translator import GoogleTranslator
import logging
import json
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@ -46,14 +46,20 @@ else:
all_commits_text += commit_message + "\n" # 将每个提交信息添加到字符串中
logging.info(f"找到匹配的提交日期: {commit_date},提交信息: {commit_message}")
# 创建一个 Translator 对象
translator = GoogleTranslator(source='en', target='zh-CN')
logging.info("创建 GoogleTranslator 对象")
# 使用 llama3.1 模型翻译
logging.info("开始调用 llama3.1 模型进行翻译")
translation_api_url = "https://ollama.aoun.ltd/api/generate"
headers = {"Content-Type": "application/json"}
payload = {
"model": "llama3.1",
"prompt": f"请翻译这个内容:{all_commits_text}",
"stream": False
}
try:
# 翻译合并后的提交信息文本
logging.info("开始翻译提交信息文本")
translated_text = translator.translate(all_commits_text)
response = requests.post(translation_api_url, headers=headers, data=json.dumps(payload))
response.raise_for_status()
translated_text = response.json().get("response", "翻译失败")
logging.info("翻译成功")
# 获取当前中国时间