adamrushy / OpenAISwift

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

sendImages #69

Closed HalifaxNick closed 1 year ago

HalifaxNick commented 1 year ago

The main page shows an API call for generating images using DALL-E but when I run the example given:

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)
    }
}

it says OpenAISwift has no member 'sendImages'. Maybe I'm doing something wrong?

optera15 commented 1 year ago

This works for me. I'm using the build at commit hash: 72f1d8997f4a4a830570bb0487ccd2edacb7da23

 func requestDallEImageWithString(_ message: String) {
        let openAI = OpenAISwift(authToken: viewModel.apiToken)
        openAI.sendImages(with: message, numImages: 1, size: .size1024) { result in // Result<OpenAI, OpenAIError>
            switch result {
            case .success(let success):

                if let imageResponseArray = success.data {
                    let responseUrlString = imageResponseArray.first?.url ?? ""
                    // do what you want with the url string
                }

            case .failure(let failure):
                print(failure.localizedDescription)
            }
        }
    }
adamrushy commented 1 year ago

Yeah, created a new release tag 1.3.0 - please update to use this version 👍🏼