#1571 翻译字幕阶段出错:[兼容AI/本地模型] 处理列表或序列时索引越界:list index out of range: Traceback (most recent call last): File "videotrans\transla

240e:378* Posted at: 11 hours ago 👁13

[localllm]发送请求数据:message=[{'role': 'system', 'content': '您是一名顶级的字幕翻译引擎。'}, {'role': 'user', 'content': '# 任务:逐行翻译\n\n将 内的文本逐行翻译成 **简体中文**。\n\n**核心规则:**\n1. **行数绝对一致**:输入有几行,输出就必须有几行。即使句子被拆分,也要逐行翻译。\n2. **保留无法翻译的内容**:代码、专有名词、路径等无法翻译的行,直接原样输出。\n3. **指定格式**:所有输出必须用 标签包裹。\n\n


\n### 格式示例\n以下示例仅用于展示必须遵守的格式规则。\n请忽略示例中的具体语言,你的翻译目标是本任务开头指定的语言。\n\n#### 输入:\nThis is\na long sentence.\nconfig_path\n\n#### 输出:\nxml\n\n这是\n一个长句子。\nconfig_path\n\n\n
\n\nドアを見てください。\n先行きましょ?\nどうぞ。\n皆さんはいけない?\nそれが気持ちいいの?\nいいですよ。\n開尾は気持ちいいの?\n音楽を歌うその子さんです。\n大きな音楽を歌うのを歌う人に耐えます。\nhangar?\nお互いを歌います。\n先生、まだ誰と付き合うか決められないの?\nどうだよ、先生。本当に決めるつもりあるの?\nもしかして、このまま決めないで、3人と付き合おうって思ってる?\nそれは、いや、あの、あの、3人は帰らなくていいのか。\n今日は、みんな友達の家に泊まりに行くって言ってあるから大丈夫だよ。\nそうだよ、今日はいっぱい時間あるから大丈夫。\nどうだよ、先生と一番中レックスするんだよ。\nねえ。\nねえ。\n先生、足でされるのも好きなの?\nねえ。\nどうし?\nYouTube?\nなんか、大きくなっちゃう。\nね。\nどうしよう。\nこんなこと好きだから、いろんなとこ飲めるよ。\nえ?\nこことか。\nなないでしょ。\nさまくな。\nなめる?\nねえ、足のめられるのと、チンチンなめられるの。\nどっちが気持ちいいの?\nどっちが気持ちいい?\n先生、はっきりしてよ。チンチンのほうが気持ちいいでしょ。\nチンチンのほうが気持ちいいよ。\nチンチンのほうが気持ちいいよ。\nチンチンのほうが気持ちいい。\n舌がやらしい。\nいっぱいなめてあげるよ。\nいろんなところ、なめてあげるよ。\nそんなとこ?\nちょ、ちょ、ちょ、ちょ。\nえ、そんなとこ。恥ずかしいよ。\nすごい。\nねえ。\nこんなとこ見える。\nそんなとこだめ。ダメダメ。\n'}]
2025-11-23 01:31:27,898 - INFO - [localllm]响应:response=ChatCompletion(id='chatcmpl-202511230131258094215589IiBILM5', choices=[], created=1763832686, model='gemini-2.5-pro', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=0, prompt_tokens=633, total_tokens=633, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=None, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=None, text_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0, text_tokens=633, image_tokens=0), input_tokens=0, output_tokens=0, input_tokens_details=None, claude_cache_creation_5_m_tokens=0, claude_cache_creation_1_h_tokens=0))
2025-11-23 01:31:27,898 - INFO - Finished call to 'videotrans.translator._localllm.LocalLLM._item_task' after 16.156(s), this was the 3rd time calling it.
2025-11-23 01:31:27,900 - ERROR - list index out of range
Traceback (most recent call last):
File "videotrans\translator\_base.py", line 81, in run
File "videotrans\translator\_base.py", line 99, in _run_text
File "tenacity\__init__.py", line 338, in wrapped_f
File "tenacity\__init__.py", line 477, in call
File "tenacity\__init__.py", line 378, in iter
File "tenacity\__init__.py", line 421, in exc_check
tenacity.RetryError: RetryError[]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "videotrans\task\job.py", line 146, in run
File "videotrans\task\_translate_srt.py", line 45, in trans
File "videotrans\translator\__init__.py", line 907, in run
File "videotrans\translator\_base.py", line 83, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_localllm.py", line 70, in _item_task
IndexError: list index out of range
2025-11-23 01:31:27,900 - ERROR - list index out of range
Traceback (most recent call last):
File "videotrans\translator\_base.py", line 81, in run
File "videotrans\translator\_base.py", line 99, in _run_text
File "tenacity\__init__.py", line 338, in wrapped_f
File "tenacity\__init__.py", line 477, in call
File "tenacity\__init__.py", line 378, in iter
File "tenacity\__init__.py", line 421, in exc_check
tenacity.RetryError: RetryError[]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "videotrans\task\job.py", line 146, in run
File "videotrans\task\_translate_srt.py", line 45, in trans
File "videotrans\translator\__init__.py", line 907, in run
File "videotrans\translator\_base.py", line 83, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_localllm.py", line 70, in _item_task
IndexError: list index out of range

1 Replies

这个错误是由于本地LLM翻译渠道返回了空的翻译结果导致的。从日志可以看到,Gemini模型返回的响应中 choices=[] 为空数组,导致程序无法获取翻译内容而报错。

解决方案:

  1. 检查API配置:确认Gemini API密钥是否正确,是否有足够的配额。
  2. 更换翻译渠道

    • 暂时切换到其他翻译渠道,如Google翻译或微软翻译
    • 或者使用其他AI模型如OpenAI、DeepSeek等
  3. 调整翻译设置

    • 在高级选项中,将"同时翻译字幕数"设为较小的值(如5-10)
    • 减少单次发送给API的字幕行数
  4. 检查网络连接:确保能够正常访问Gemini API服务。

如果问题持续存在,建议暂时使用其他翻译渠道完成当前任务,然后检查Gemini API的具体错误原因。

Post Your Reply
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Donate: https://ko-fi.com/jianchang512

Trending Questions