hcfyapp / crx-selection-translate

一站式划词 / 截图 / 网页全文 / 音视频翻译扩展。
https://hcfy.app
4.06k stars 539 forks source link

Gemini 1.5 翻译返回"Cannot read properties of undefined (reading 'parts')" #2013

Closed leslietoo closed 3 weeks ago

leslietoo commented 1 month ago

基本信息

划词翻译版本:v10.7.0 浏览器版本:Chrome Version 124.0.6367.158 (Official Build) (64-bit) 操作系统:windows 10, windows 11

重现问题的步骤

  1. 打开 https://lands-of-lore.fandom.com/wiki/Ruloi
  2. 选中页面第一段话: "Be silent. Be still. You must comply. You must follow. The portals are our gateway. You are required. We will use the portal to bring you back to the Hive. You will be slaves. You will be cattle. There will be no escape. There will be no failure. We will bleed you, and your world, dry.",点划词翻译悬浮按钮
  3. 翻译的结果对话框里,Gemini返回错误:"Cannot read properties of undefined (reading 'parts')"

预期行为

Gemini能返回翻译后的内容

实际行为

翻译请求因为safety设置被Gemini block了

补充信息

我用划词翻译用得很多(终身会员),这个现象在我这里经常会出现,一直以为是apikey使用的频率问题(但是也就查词用 不算频繁啊所以很郁闷),直到这一次我在Chome的extension setting里打开划词翻译插件的background page, 查看gemini请求的response,才发现finishReason是因为SAFETY不满足条件被block掉了,见附件图片。

经过一番搜索,应该是可以通过在请求时设置safety条件为BLOCK_NONE来解决该问题,参考下面的解决代码: https://github.com/GoogleCloudPlatform/generative-ai/issues/344#issuecomment-1940863066

gemini的镜像地址设置是 https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent

我估计其他功能例如图片ocr翻译、pdf翻译,凡是使用gemini来翻译的都会有这个问题。 查了一下似乎gpt也有类似的safety设置,如果修复这个问题的时候连同gpt一起也改了就最好不过了。

另外,用得越多越觉得Gemini 1.5 pro的翻译质量是最好的,比gpt-4o和deepl都要好。期待作者将来加上Claude的支持,看看Claude翻译的是不是更棒。

hcfy_bug1 hcfy_bug2

kkunit commented 1 month ago

同经常遇到这个问题,希望作者大大可以优化

lmk123 commented 1 month ago

感谢你的详细反馈!我会在下个版本中优化此问题

lmk123 commented 3 weeks ago

已默认将 Gemini API 的全部安全检查都关闭,这段话可以正常翻译了:

Be silent, Be still, You must comply. You must follow. The portals are our gateway. You are required. We will use the portal to bring you back to the Hive. You will be slaves. You wil be cattle. There will be no escape. There will be no failure. We will bleed you, and your world, dry.
image
lmk123 commented 3 weeks ago

对 Claude 的支持已新开了一个 issue #2017