irudnyts / openai

An R package-wrapper around OpenAI API
https://irudnyts.github.io/openai/
Other
161 stars 27 forks source link

addition of model for create_image #57

Open reijmerniek opened 6 months ago

reijmerniek commented 6 months ago

Any chance this will be added in the near future?

irudnyts commented 6 months ago

@reijmerniek the future is now 😉

Please, have a look:

remotes::install_github("irudnyts/openai", ref = "r6")
library(openai)

client <- OpenAI()
images <- client$images$generate(
    prompt = "Big horse"
)

images$data[[1]]$url

If you need the edit and the variation endpoints, please let me know.

reijmerniek commented 6 months ago

@irudnyts Hi! Thanks for your quick reply, but I meant something different. I mean the arguments that go into create_image:

create_image( prompt, n = 1, size = c("1024x1024", "256x256", "512x512"), response_format = c("url", "b64_json"), user = NULL, openai_api_key = Sys.getenv("OPENAI_API_KEY"), openai_organization = NULL )

There is no option for choosing the model here. While the official API documentation does give this option:

curl https://api.openai.com/v1/images/generations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "dall-e-3", "prompt": "A cute baby sea otter", "n": 1, "size": "1024x1024" }'

Is this something I can add myself or is an update of the package needed?

irudnyts commented 6 months ago

@reijmerniek Yeah, you use an older version. Now I'm building a new one using a slightly different approach.

You can install a development version of a package with: remotes::install_github("irudnyts/openai", ref = "r6", force = TRUE), and then you should be able to choose a model:

library(openai)

client <- OpenAI()
images <- client$images$generate(prompt = "big dog", model = "dall-e-3")

images$data[[1]]$url
reijmerniek commented 6 months ago

@irudnyts Running just remotes::install_github("irudnyts/openai", ref = "r6", force = TRUE) didnt work, but running it after removing the old package worked! Thanks!!