Skip to content

Commit

Permalink
perf: restore CaiyunService
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Jan 3, 2024
1 parent 06a272d commit 20c617e
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions Easydict/Feature/Service/Caiyun/CaiyunService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Alamofire
import Foundation
import GoogleGenerativeAI

@objc(EZCaiyunService)
public final class CaiyunService: QueryService {
Expand Down Expand Up @@ -80,9 +79,6 @@ public final class CaiyunService: QueryService {
"x-authorization": "token " + token,
]

geminiTranslate(text, from: from, to: to, completion: completion)
return

let request = AF.request(apiEndPoint,
method: .post,
parameters: parameters,
Expand Down Expand Up @@ -110,34 +106,6 @@ public final class CaiyunService: QueryService {
request.cancel()
}, serviceType: serviceType().rawValue)
}

public func geminiTranslate(_ text: String, from: Language, to: Language, completion: @escaping (EZQueryResult, Error?) -> Void) {
Task {
// https://github.com/google/generative-ai-swift
do {
var resultString = ""
let prompt = "translate this \(from.rawValue) text into \(to.rawValue): \(text)"
print("gemini prompt: \(prompt)")
let model = GenerativeModel(name: "gemini-pro", apiKey: "")
let outputContentStream = model.generateContentStream(prompt)

// stream response
for try await outputContent in outputContentStream {
guard let line = outputContent.text else {
return
}

print("gemini response: \(line)")
resultString += line
result.translatedResults = [resultString]
completion(result, nil)
}
} catch {
print(error.localizedDescription)
completion(result, error)
}
}
}
}

enum QueryServiceError: Error {
Expand Down

0 comments on commit 20c617e

Please sign in to comment.