Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dall-E 3 #97

Open
stavrosdidakis opened this issue Nov 26, 2023 · 1 comment
Open

Dall-E 3 #97

stavrosdidakis opened this issue Nov 26, 2023 · 1 comment

Comments

@stavrosdidakis
Copy link

Does the current project here support Dall-E 3?

@kwan3854
Copy link

kwan3854 commented Nov 30, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants