常见问题无法将 AI 服务的响应解码为 JSON
无法将 AI 服务的响应解码为 JSON
Gato AI Translations for Polylang 会向 AI 服务发送提示词,响应以 JSON 格式返回。
根据您发送的数据(待翻译的字符串和语言),AI 服务有时可能返回无效的 JSON 响应。此时日志中会显示如下错误信息:
Error [Query "translate-customposts"] Execution with errors: 🔴 Translation to zh_CN failed - There was an error requesting data from the API for provider 'OpenRouter': Could not JSON-decode the OpenRouter API's 'choices[0].message.content' field in the response每当我们发现新问题时,都会调整提示词以防止该问题再次发生。
目前,提示词包含以下内容:
If a sentence contains HTML:
- Translate the text inside the HTML tags. (eg: `<p>Hello world</p>` => `<p>Hola mundo</p>`)
- Translate the following properties inside the HTML tags: alt, title, placeholder, aria-label, aria-describedby, aria-labelledby, aria-placeholder. Do not translate any other property.
- Ensure that any double quotes (") within a translated string inside an HTML tag attribute are properly escaped by adding a backslash before them (\"), but only if they haven't been escaped already.
- Ensure that the quotes in HTML tag attributes are not escaped (eg: keep `<mark class="has-inline-color">` as is, do not convert to `<mark class=\"has-inline-color\">`).
- Ensure that slashes within HTML tags are not escaped (eg: keep `<p>Hello world</p>` as is, do not convert to `<p>Hello world<\/p>`).
Keep emojis exactly as they are, do not translate them.
Ensure that the response is encoded using UTF-8 for all characters.如果出现错误,说明遇到了尚需识别和修复的新问题。
请执行以下操作:
- 尝试理解问题所在
- 自定义提示词以解决该问题
问题解决后,请将您使用的提示词发送给我们,我们会将该解决方案硬编码到插件中。
Prev
Next