Skip to content

Dall-E 3 #97

Closed
Closed

Description

@stavrosdidakis

Does the current project here support Dall-E 3?

Activity

  1. kwan3854 commented on Nov 30, 2023

    @kwan3854

    Not supported yet, but you can simply add few lines of code and use it.

    in DataTypes.cs

        public struct ImageData
        {
            public string Url { get; set; }
            public string B64Json { get; set; }
            // add two lines of codes below
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public string revised_prompt { get; set; }
        }
        
        public sealed class CreateImageRequest : CreateImageRequestBase
        {
            public string Prompt { get; set; }
            // add this line
            public string Model { get; set; }
        }

    Usage:

    // DALL-E Image gen request
          var response = await openai.CreateImage(new CreateImageRequest
          {
              Prompt = prompt,
              Size = ImageSize.Size1024, // Image Size must over 1024
              Model = "dall-e-3" // Dall-E 3 Model
          });
    
          if (response.Data != null && response.Data.Count > 0)
          {
              using (var request = new UnityWebRequest(response.Data[0].Url))
              {
                  request.downloadHandler = new DownloadHandlerBuffer();
                  request.SendWebRequest();
    
                  while (!request.isDone) await Task.Yield();
    
                  if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError)
                  {
                      Debug.LogError("Error in downloading image: " + request.error);
                  }
                  else
                  {
                      Texture2D texture = new Texture2D(2, 2);
                      texture.LoadImage(request.downloadHandler.data);
                      var sprite = Sprite.Create(texture, new Rect(0, 0, 1024, 1024), Vector2.zero, 1f);
                      imageDisplay.sprite = sprite;
                  }
              }
          }
          else
          {
              Debug.LogWarning("No image was created from this prompt.");
          }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions