Giter Site home page Giter Site logo

Dall-E 3 about openai-unity HOT 1 OPEN

srcnalt avatar srcnalt commented on May 13, 2024
Dall-E 3

from openai-unity.

Comments (1)

kwan3854 avatar kwan3854 commented on May 13, 2024

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.");
      }

from openai-unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.