adamrushy / OpenAISwift

This is a wrapper library around the ChatGPT and OpenAI HTTP API
MIT License
1.6k stars 242 forks source link

Add Image Generation API #44

Closed arjun-dureja closed 1 year ago

arjun-dureja commented 1 year ago

Added the v1/images/generations API to generate images: https://platform.openai.com/docs/api-reference/images/create

Usage:

openAI.sendImages(with: "A 3d render of a rocket ship", numImages: 1, size: .size1024) { result in // Result<OpenAI, OpenAIError>
    switch result {
    case .success(let success):
        print(success.data.first?.url ?? "")
    case .failure(let failure):
        print(failure.localizedDescription)
    }
}

Demo:

https://user-images.githubusercontent.com/16995513/224520411-b0525ef9-920c-46b6-903b-89a80026c6ce.mov

adamrushy commented 1 year ago

This looks great to me @arjun-dureja but please would you mind adding this to the README as well? With sample code like we have currently? 🙏🏼

adamrushy commented 1 year ago

Ah, just a conflict to fix @arjun-dureja 😂

arjun-dureja commented 1 year ago

@adamrushy Sure! Done: 34909d6