Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GeminiService Support #297

Merged
merged 26 commits into from
Jan 28, 2024
Merged

Add GeminiService Support #297

merged 26 commits into from
Jan 28, 2024

Conversation

Jerry23011
Copy link
Collaborator

@Jerry23011 Jerry23011 commented Jan 3, 2024

Closes #270

Gemini icon author: @alexsch@macosicons.com

@Jerry23011 Jerry23011 changed the base branch from main to dev January 3, 2024 04:53
@Jerry23011
Copy link
Collaborator Author

Jerry23011 commented Jan 4, 2024

@tisfeng 基本功能已完成,可以正常跑起来了

有几个问题:

  • 翻译结果输出 error handling:现在唯一的错误输出就是查询失败: 未能完成操作。(GoogleGenerativeAI.GenerateContentError错误0。) 应该如何输出和 Xcode console 中相同的内容呢,比如:httpResponseCode: 400, message: "User location is not supported for the API use."
  • Gemini 的 icon 是在 macosicons.com 上面找的,我自己也弄了两个,可以看看三个里面喜欢哪个:
  • Target 升到 macOS 12 后编译会有 4 个报错,其中 3 个在 EZAudioUtils.m,剩下 1 个在 EZDeviceSystemlnfo.m,Xcode 自动提供了 fix,但是不知道能不能直接用
  • Gemini 支持的一个语言,Swahili / Kiswahili,并不被 Easydict 支持,所以我把相关代码都暂时注释掉了

@tisfeng
Copy link
Owner

tisfeng commented Jan 4, 2024

我今天准备要发一个新版本, @Kyle-Ye 你先帮忙看下代码。

@Jerry23011
Copy link
Collaborator Author

@Kyle-Ye 我来 email 一个 API key 方便测试

@Kyle-Ye
Copy link
Collaborator

Kyle-Ye commented Jan 4, 2024

@Kyle-Ye 我来 email 一个 API key 方便测试

  1. I'll review the code later today.
  2. Thanks. But I have my own Gemini key. I recommend you revoke the key you have emailed to me and regenerate one.

@Jerry23011
Copy link
Collaborator Author

I recommend you revoke the key you have emailed to me and regenerate one.

收到,谢谢提醒

Kyle-Ye
Kyle-Ye previously approved these changes Jan 4, 2024
Easydict/Feature/Service/Gemini/GeminiService.swift Outdated Show resolved Hide resolved
Easydict/Feature/Service/Gemini/GeminiTranslateType.swift Outdated Show resolved Hide resolved
Co-Authored-By: Kyle <kyle201817146@gmail.com>
@Jerry23011 Jerry23011 force-pushed the google-gemini branch 2 times, most recently from b55d42c to 0342f7e Compare January 6, 2024 09:04
@tisfeng
Copy link
Owner

tisfeng commented Jan 7, 2024

一般这种 warning 情况,Xcode 的自动 fix 都是可以用的。目前这个 Gemini 图标就可以。

Target 升到 macOS 12 后编译会有 4 个报错,其中 3 个在 EZAudioUtils.m,剩下 1 个在 EZDeviceSystemlnfo.m,Xcode 自动提供了 fix,但是不知道能不能直接用

@tisfeng
Copy link
Owner

tisfeng commented Jan 7, 2024

参考彩云小译,把 error 用 EZError 包裹一下就行

let ezError = EZError(nsError: error, errorResponseData: response.data)

如果错误内容比较复杂,我们最好解析一下,提取关键的错误信息显示,例如腾讯翻译

let errorResponse = try JSONDecoder().decode(TencentErrorResponse.self, from: data)

翻译结果输出 error handling:现在唯一的错误输出就是查询失败: 未能完成操作。(GoogleGenerativeAI.GenerateContentError错误0。) 应该如何输出和 Xcode console 中相同的内容呢,比如:httpResponseCode: 400, message: "User location is not supported for the API use."

@tisfeng
Copy link
Owner

tisfeng commented Jan 7, 2024

不不,这里不是这样的,我们应该以 Easydict 支持的语言为标准,在此之外的语言,例如 Swahili, 即使第三方服务支持,目前我也不用考虑。

参考目前的 OpenAI,假如有一种 Easydict 支持的语言(如 Burmese )但 OpenAI 不支持,这种情况我们才需要特别处理

https://github.com/tisfeng/Easydict/pull/312/files#diff-7f800defc7e5f0663bddd5c6aec009a311d9b72aad4eb06427795d38985e0580R140

Gemini 支持的一个语言,Swahili / Kiswahili,并不被 Easydict 支持,所以我把相关代码都暂时注释掉了

@tisfeng
Copy link
Owner

tisfeng commented Jan 7, 2024

@Kyle-Ye 由于 Gemini 官方库 generative-ai-swift 的原因,我把支持版本从 macOS 11 改成了 macOS 12.0,我想知道,是否有办法不改项目最低 target,通过类似 @available(macOS 12, *) 方法添加这个库?

@tisfeng
Copy link
Owner

tisfeng commented Jan 8, 2024

@Jerry23011 参考 OpenAI 这个 PR #312 ,如果服务对各个语言都支持,不像彩云或腾讯翻译那样需要处理语言之间的对应关系,那我们就不需要弄个 GeminiTranslateType。

@Kyle-Ye
Copy link
Collaborator

Kyle-Ye commented Jan 8, 2024

@Kyle-Ye 由于 Gemini 官方库 generative-ai-swift 的原因,我把支持版本从 macOS 11 改成了 macOS 12.0,我想知道,是否有办法不改项目最低 target,通过类似 @available(macOS 12, *) 方法添加这个库?

Yes. See my issue and PR here swiftlang/swift-testing#101 (comment)

You need to communicate with the upstream to express our issue or we can just fork one as a temporary workaround.

@tisfeng
Copy link
Owner

tisfeng commented Jan 24, 2024

另外,可以参考这个 PR songquanpeng/one-api#867 ,将 Gemini 的安全设置项调整为 BLOCK_NONE

@Jerry23011 Jerry23011 changed the title [WIP] Add GeminiService Support Add GeminiService Support Jan 25, 2024
@Jerry23011 Jerry23011 marked this pull request as ready for review January 25, 2024 04:50
@Jerry23011 Jerry23011 requested a review from tisfeng January 25, 2024 04:50
tisfeng
tisfeng previously approved these changes Jan 27, 2024
@tisfeng tisfeng merged commit 1a89fb9 into tisfeng:dev Jan 28, 2024
5 checks passed
@Jerry23011 Jerry23011 deleted the google-gemini branch January 28, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 功能建议:建议加入GeminiPro API
4 participants