I'm encountering an issue with OpenAI's Swift library (OpenAISwift) where I'm receiving a nil response. I've created a ChatGPT clone to utilize the ChatGPT API through OpenAISwift to communicate with the API and receive responses. However, despite receiving an HTTP 200 success status code, I'm getting nil in the 'success.choices' response. Can you help me troubleshoot this problem?
struct MainView: View {
@State private var chatText: String = ""
var openAI: OpenAISwift = OpenAISwift(config: OpenAISwift.Config.makeDefaultOpenAI(apiKey: "sk-"))
@EnvironmentObject private var model: Model
private var isFormValid: Bool {
!chatText.isEmptyOrWhiteSpace
}
private func performSearch() {
openAI.sendCompletion(with: chatText, maxTokens: 500) { result in
switch result {
case .success(let success):
let answer = success.choices?.first?.text.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
let query = Query(question: chatText, answer: answer)
DispatchQueue.main.async {
model.queries.append(query)
}
do {
try model.saveQuery(query)
} catch {
print(error.localizedDescription)
}
chatText = ""
case .failure(let failure):
print(failure)
}
}
}
I'm encountering an issue with OpenAI's Swift library (OpenAISwift) where I'm receiving a nil response. I've created a ChatGPT clone to utilize the ChatGPT API through OpenAISwift to communicate with the API and receive responses. However, despite receiving an HTTP 200 success status code, I'm getting nil in the 'success.choices' response. Can you help me troubleshoot this problem?