0

I am using openAi client with android kotlin (implementation com.aallam.openai:openai-client:2.1.3).

Is the path wrong or is the library missing?

val imgURL = Uri.parse("android.resource://" + packageName + "/" + R.drawable.face3)
try {
    val images = openAI.image(
        edit = ImageEditURL( // or 'ImageEditJSON'
            image = FilePath(imgURL.toString()), // <-
            mask = FilePath(imgURL.toString()), // <-
            prompt = "a sunlit indoor lounge area with a pool containing a flamingo",
            n = 1,
            size = ImageSize.is1024x1024
        )
    );
} catch (e: Exception) {
    println("error is here:"+e)
}

As can be seen, it wants a path from me, but it does not succeed even though I give the path.

double-beep
  • 5,031
  • 17
  • 33
  • 41

1 Answers1

0

I would suggest updating to version 3 of openai-kotlin, and use Okio's Source to provide files.
Assuming the images are in the res/raw folder, your example would be something like this:

val request = ImageEdit(
    image = FileSource(
        name = "image.png",
        source = resources.openRawResource(R.raw.image).source()
    ),
    mask = FileSource(
        name = "mask.png", 
        source = resources.openRawResource(R.raw.mask).source()
    ),
    prompt = "a sunlit indoor lounge area with a pool containing a flamingo",
    n = 1,
    size = ImageSize.is1024x1024,
)
val response = client.imageURL(request)
Aallam
  • 21
  • 6