This commit is contained in:
parent
94c43069c8
commit
a2258f374b
2
.github/workflows/翻译更新日志.yml
vendored
2
.github/workflows/翻译更新日志.yml
vendored
@ -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文件
|
||||
|
20
翻译更新日志.py
20
翻译更新日志.py
@ -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("翻译成功")
|
||||
|
||||
# 获取当前中国时间
|
||||
|
Loading…
Reference in New Issue
Block a user