Skip to content

Commit b7af297

Browse files
committed
basic images support on response object
1 parent 225f112 commit b7af297

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

openai/responses.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ local response_mt = {
2929
end
3030
end
3131
return table.concat(parts)
32+
end,
33+
get_images = function(self)
34+
local images = { }
35+
if self.output then
36+
local _list_0 = self.output
37+
for _index_0 = 1, #_list_0 do
38+
local block = _list_0[_index_0]
39+
if block.type == "image_generation_call" and block.result then
40+
table.insert(images, {
41+
b64_json = block.result
42+
})
43+
end
44+
end
45+
end
46+
return images
3247
end
3348
},
3449
__tostring = function(self)
@@ -214,6 +229,9 @@ do
214229
if self.opts.instructions then
215230
merged_opts.instructions = self.opts.instructions
216231
end
232+
if self.opts.tools then
233+
merged_opts.tools = self.opts.tools
234+
end
217235
if opts then
218236
for k, v in pairs(opts) do
219237
merged_opts[k] = v

openai/responses.moon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ response_mt = {
1919
table.insert parts, item.text
2020

2121
table.concat parts
22+
23+
-- extract generated images from a response with image_generation tool
24+
-- returns array of tables with {b64_json: string} for each generated image
25+
get_images: =>
26+
images = {}
27+
if @output
28+
for block in *@output
29+
if block.type == "image_generation_call" and block.result
30+
table.insert images, { b64_json: block.result }
31+
images
2232
}
2333
__tostring: => @get_output_text!
2434
}
@@ -185,6 +195,9 @@ class ResponsesChatSession
185195
if @opts.instructions
186196
merged_opts.instructions = @opts.instructions
187197

198+
if @opts.tools
199+
merged_opts.tools = @opts.tools
200+
188201
if opts
189202
for k, v in pairs opts
190203
merged_opts[k] = v

0 commit comments

Comments
 (0)