can anyone there help me out??
after the recent update from openai my demo app stop generating response it shows blank response earlier it works fine please help here is the code…
import Foundation
import OpenAISwift
final class APICaller {
static let shared = APICaller()
enum Constants {
static let key = ""
}
private var client: OpenAISwift?
private var conversationContext: String = ""
private init() {}
public func setup() {
self.client = OpenAISwift(config: OpenAISwift.Config.makeDefaultOpenAI(apiKey: Constants.key))
}
public func getResponse(input: String, modelName: String, maxLength: Int?, completion: @escaping (Result<String, Error>) -> Void) {
let combinedInput = conversationContext + input
client?.sendCompletion(with: combinedInput, maxTokens: 1000, completionHandler: { [weak self] result in
guard let self = self else { return }
switch result {
case .success(let model):
let output = model.choices?.first?.text ?? ""
self.conversationContext += output
completion(.success(output))
case .failure(let error):
completion(.failure(error))
}
})
}
func main() {
let apiCaller = APICaller.shared
apiCaller.setup()
let modelName = ""gpt-3.5-turbo"
apiCaller.getResponse(input: ""gpt-3.5-turbo", modelName: modelName, maxLength: nil) { result in
switch result {
case .success(let response):
print("Response: \(response)")
case .failure(let error):
print("Error: \(error)")
}
}
}
}