File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+
2+
3+ local openai = require (" openai" )
4+ local client = openai .new (os.getenv (" OPENAI_API_KEY" ))
5+
6+ local status , response = client :image_generation ({
7+ model = " gpt-image-1.5" ,
8+ prompt = " Design a modern logo for MoonScript, the language that compiles to Lua"
9+ })
10+
11+
12+ if status == 200 then
13+ print (" Size" , response .size )
14+ print (" Background" , response .background )
15+ print (" Output format" , response .output_format )
16+ print (" Quality" , response .quality )
17+
18+ -- output the image
19+ local filename = " image_generation.png"
20+ local mime = require (" mime" )
21+ local image_bytes = mime .unb64 (response .data [1 ].b64_json )
22+
23+ local file = io.open (filename , " wb" )
24+ if file then
25+ file :write (image_bytes )
26+ file :close ()
27+ print (" Saved image to: " .. filename )
28+ else
29+ print (" Failed to save image to: " .. filename )
30+ end
31+ else
32+ local json = require (" cjson" )
33+ print (json .encode (response ))
34+ end
35+
36+
File renamed without changes.
You can’t perform that action at this time.
0 commit comments