Skip to content

Commit 5a1326b

Browse files
committed
update content format to image_url input for gpt vision
1 parent 91b7e48 commit 5a1326b

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

examples/example6.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- this shows how to provide an image
2+
3+
local openai = require("openai")
4+
local client = openai.new(os.getenv("OPENAI_API_KEY"))
5+
6+
local status, response = client:chat({
7+
{
8+
role = "user",
9+
content = {
10+
{ type = "image_url", image_url = "https://leafo.net/hi.png" },
11+
{ type = "text", text = "Describe this image" }
12+
}
13+
}
14+
}, {
15+
model = "gpt-4-vision-preview"
16+
})
17+
18+
if status == 200 then
19+
print(response.choices[1].message.content)
20+
end

openai/init.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ local types
66
types = require("tableshape").types
77
local parse_url = require("socket.url").parse
88
local empty = (types["nil"] + types.literal(cjson.null)):describe("nullable")
9+
local content_format = types.string + types.array_of(types.one_of({
10+
types.shape({
11+
type = "text",
12+
text = types.string
13+
}),
14+
types.shape({
15+
type = "image_url",
16+
image_url = types.string
17+
})
18+
}))
919
local test_message = types.one_of({
1020
types.shape({
1121
role = types.one_of({
1222
"system",
1323
"user",
1424
"assistant"
1525
}),
16-
content = empty + types.string,
26+
content = empty + content_format,
1727
name = empty + types.string,
1828
function_call = empty + types.table
1929
}),

openai/init.moon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ parse_url = require("socket.url").parse
1111

1212
empty = (types.nil + types.literal(cjson.null))\describe "nullable"
1313

14+
content_format = types.string + types.array_of types.one_of {
15+
types.shape { type: "text", text: types.string }
16+
types.shape { type: "image_url", image_url: types.string }
17+
}
18+
1419
test_message = types.one_of {
1520
types.shape {
1621
role: types.one_of {"system", "user", "assistant"}
17-
content: empty + types.string -- this can be empty when function_call is set
22+
content: empty + content_format -- this can be empty when function_call is set
1823
name: empty + types.string
1924
function_call: empty + types.table
2025
}

0 commit comments

Comments
 (0)