tonhowtf/omniget · error
tradução por IA falhou
Error message
tradução por IA falhou: {} What it means
translate_batch_llm tries to translate a batch of SRT cue lines via an LLM; if every attempt fails (network errors, JSON responses outside the expected shape, etc.), it exhausts its retries and returns this error with the last failure reason interpolated. It is an aggregate 'all attempts failed' error, not a single-shot failure.
Solutions
- Read the interpolated last_err: it names the reason of the final attempt (network error vs bad JSON).
- Verify the LLM base URL and API key are correct and the account has quota.
- Use a model that reliably follows JSON output instructions, or enable the provider's JSON/response-format mode.
- If LLM translation keeps failing, switch to the LibreTranslate backend (translate_batch_libre path).
- Increase timeout/batch-size settings if large batches are being truncated into invalid JSON.
Example fix
// before
llm_base_url: "http://localhost:8080".into(), api_key: "".into() // server not running / unauthorized
// after
llm_base_url: "https://api.openai.com/v1".into(), api_key: std::env::var("OPENAI_API_KEY")?,
// plus response_format: { "type": "json_object" } in the request Defensive patterns
Strategy: fallback
Validate before calling
fn llm_config_ok(base_url: &str, api_key: &str) -> bool {
!base_url.trim().is_empty() && !api_key.trim().is_empty() && base_url.starts_with("http")
} Try / catch
match translate_cues(cues, Llm { .. }).await {
Err(e) if e.to_string().starts_with("tradução por IA falhou") => translate_cues(cues, LibreTranslate { .. }).await?,
other => other,
} Prevention
- Configure a valid LLM base URL and API key; verify with a smoke-test request at startup.
- Request JSON output mode from the model to avoid 'resposta fora do formato JSON'.
- Keep batches small so responses are not truncated into invalid JSON.
- Configure LibreTranslate as a fallback backend.
When it happens
Trigger: Calling translate_cues with an LLM backend when the endpoint is unreachable, the API key is rejected, the model returns non-JSON or malformed-JSON output ('resposta fora do formato JSON'), or every retry attempt errors out.
Common situations: Wrong/missing API key or base URL for the LLM provider; the model ignoring the JSON output instruction and returning prose; rate limits or timeouts on all retries; model name typo; free-tier quota exhausted.
Related errors
- LibreTranslate: HTTP
- HTTP
- o post não veio na resposta (apagado, privado ou id errado)
- {}
- LibreTranslate: resposta invalida
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/c93e746d70fea0df.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/srt_translate.rs:119
&opts.source_lang,
&opts.target_lang,
&opts.context,
prev,
next,
);
let mut last_err = String::new();
for _ in 0..2 {
match crate::core::ai::chat(&system, &user).await {
Ok(text) => {
if let Some(parsed) = parse_llm_json(&text, lines.len()) {
return Ok(parsed);
}
last_err = "resposta fora do formato JSON".to_string();
}
Err(e) => last_err = e,
}
}
Err(anyhow!("tradução por IA falhou: {}", last_err))
}
async fn translate_batch_libre(
lines: &[&str],
base_url: &str,
api_key: &str,
opts: &TranslateOptions,
) -> anyhow::Result<Vec<Option<String>>> {
let client = super::client()?;
let url = format!("{}/translate", base_url.trim_end_matches('/'));
let mut body = serde_json::json!({
"q": lines,
"source": if opts.source_lang.is_empty() { "auto" } else { opts.source_lang.as_str() },
"target": opts.target_lang,
"format": "text",
});
if !api_key.is_empty() {
body["api_key"] = serde_json::Value::String(api_key.to_string());View on GitHub (pinned to 8600b91f42)