我正在使用 OpenAI API 为提示生成文本完成,但我遇到了 API 响应返回错误“No value associated with key CodingKeys(stringValue: "object", intValue: nil) ("object") ”“ 我已经检查了我发送的提示是否有效,并且我已经用不同的提示进行了测试,但问题仍然存在。是什么导致了这个问题,我该如何解决?任何帮助或见解将不胜感激。
谢谢。
class NetworkManager{
static let shared = NetworkManager()
@frozen enum Constants{
static let key = ""
}
private var client: OpenAISwift?
private init() {}
func setUp(){
self.client = OpenAISwift(authToken: Constants.key)
}
func getResponse(input: String, completion: @escaping (Result<String, Error>) -> Void) {
let prompt = """
translate from English to Nigerian Pidgin:
\(input)
Output:
"""
client?.sendCompletion(with: prompt, model: .gpt3(.davinci), maxTokens: 60) { result in
switch result {
case .success(let response):
let output = response.choices.first?.text ?? ""
print(response)
completion(.success(output))
case .failure(let error):
completion(.failure(error))
print(error.localizedDescription)
}
}
}
networkManager.getResponse(input: inputText) { result in
switch result {
case .success(let outputText):
DispatchQueue.main.async {
self.secondTextField.text = outputText
}
case .failure(let error):
print("Error translating text: \(error)")
}
}`