As an investigation into the ChatGPT apis, and having a GitHub public repository, we’ve created a Swift based ChatGPT package. The package can be incorporated into iOS (only matters for async operation) projects, and if you have a ChatGPT api key (you can find instructions on this on the ChatGPT website) you can run tests and use the package to perform your own chat based operations.
The repo can be found on GitHub, here.
Here’s a simple code example demonstrating usage (others are found in the readme and tests).
// With a request object
let request = ChatRequest(messages: [Message(content: “Tell me a story”)])
let chat = ChatGPT.chat(apiKey: apiKey)
if let completion = await chat.request(chatRequest: request) {
completion.choices.forEach({ choice in
debug(choice.message.content)
})
}
