|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from openai import OpenAI
client = OpenAI(
base_url = 'https://api.chre.tech/v1',
api_key = "sk-loHrzSP2KEPOWUVFE5YjIxFZ2xv" # 设置你的 API 密钥
)
def srtFileGPTTran(questionfile, srtZhFileNameAndPath):
questionfile = "translate to Chinese:\n" + open(questionfile, "r", encoding="utf-8").read()
print(questionfile)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": questionfile}
]
)
reply = response.choices[0].message.content
with open(srtZhFileNameAndPath, "w", encoding="utf-8") as file:
file.write(reply)
# return reply
srtEnFileNameMergeAndPath = '1.srt'
srtZhFileNameAndPath = '1zh11.srt'
srtFileGPTTran(srtEnFileNameMergeAndPath, srtZhFileNameAndPath)
1zh11.srt 的结果是:
Sure, here is the translation in Chinese:
1
00:00:00,084 --> 00:00:00,880
我很乐意来收拾。
2
00:00:01,154 --> 00:00:02,480
哦,你真好。
怎么让chatgpt 不说”Sure, here is the translation in Chinese:“ 这种话,只输出结果呢?
|
|