tisfeng / Easydict

一个简洁优雅的词典翻译 macOS App。开箱即用,支持离线 OCR 识别,支持有道词典,🍎 苹果系统词典,🍎 苹果系统翻译,OpenAI,Gemini,DeepL,Google,Bing,腾讯,百度,阿里,小牛,彩云和火山翻译。A concise and elegant Dictionary and Translator macOS App for looking up words and translating text.
GNU General Public License v3.0
7.04k stars 356 forks source link

refactor: rewrite OpenAI service with Swift #473

Closed tisfeng closed 6 months ago

tisfeng commented 6 months ago

close https://github.com/tisfeng/Easydict/issues/291

tisfeng commented 6 months ago

There are no feature changes in this PR, just a rewrite of the OpenAI service using Swift and removing the old objc code.

Other changes:

tisfeng commented 6 months ago

There seems to be something wrong with CI, can anyone help take a look?

phlpsong commented 6 months ago
Screenshot 2024-03-26 at 22 08 59

Looks like a package resolution issue because of Package.resolved file is corrupted or malformed, I cannot build it in local machine either.

tisfeng commented 6 months ago

@phlpsong I didn't change the configuration of custom OpenAI, I don't know why its interface changed to be the same as OpenAI.

I debug found that it will call OpenAIService + ConfigurableService instead of CustomOpenAIService + ConfigurableService, can you help me to look at it?

image image
phlpsong commented 6 months ago

I think the root cause is the change of inheritance of OpenAIService and CustomOpenAIService, currently, CustomOpenAIService inherits from OpenAIService and they both implement ConfigurableService, this may caused the method dispatch problem.

Maybe the simple approach is to create a base class like before, and make the subclass conform to ConfigurableService.

FYI: https://stackoverflow.com/questions/44703205/swift-protocol-extension-method-is-called-instead-of-method-implemented-in-subcl

tisfeng commented 6 months ago

@phlpsong ok, thank you for your answer, I will check it later.

tisfeng commented 6 months ago

I added a BaseOpenAIService, it looks fixed now.

phlpsong commented 6 months ago

There seems to be something wrong with CI, can anyone help take a look?

I just found out that Xcode 15.3 could fix this. Currently, CI uses 15.1.

tisfeng commented 6 months ago

The system images of CI and Xcode versions are usually a bit outdated. As long as they run without issues, we can temporarily keep them until adapting to the new major updates.

phlpsong commented 6 months ago

Sure, let's keep the current package configuration utils stable.

tisfeng commented 6 months ago

Please review this PR 🥹

tisfeng commented 6 months ago

All fixed, please continue to review.