ChatGPT SDK: Includes all the endpoints provided by OpenAI.
.package(url: "https://github.com/ShenghaiWang/ChatGPTSDK.git", from: "1.0.0")
ChatGPTSDK.setAPIKey("...")
let request = CompletionEndpoint.Request(prompt: "This is a test")
let endpoit = CompletionEndpoint(request: request)
endpoint
.sink(receiveCompletion: { error in
// error handling
}, receiveValue: { [weak self] value in
self?.result = value.choices.first?.text ?? ""
})
Note: this is the only api that supports parameter `stream=true`
do {
let value = try await endpoint.run()
result = value?.choices.first?.text ?? ""
} catch {
// error handling
}
endpoint.run { value, error in
// error handling
self?.result = value?.choices.first?.text ?? ""
}