How would one use the Dall-E text-to-image API's image
and mask
parameters in Unity C#?
For background, something like the following works for the other parameters like prompt
(full code on GitHub):
string apiMode = "generations";
string apiUrl = "https://api.openai.com/v1/images/" + apiMode;
UnityWebRequest www = UnityWebRequest.Post(apiUrl, "");
www.SetRequestHeader("Content-Type", "application/json");
www.SetRequestHeader("Authorization", "Bearer " + key);
string jsonString = JsonConvert.SerializeObject(aiParams, Formatting.None, serializerSettings);
www.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonString));
www.downloadHandler = new DownloadHandlerBuffer();
yield return www.SendWebRequest();
When using apiMode
"edits" or "variations" though, as per Dall-E's documentation, it will return an API error suggesting to switch to content-type "multipart/form-data". How would one use this and add the binary data for image
or mask
, given some byte[]
for the png? Thanks!