File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -6,14 +6,24 @@ local types
66types = require (" tableshape" ).types
77local parse_url = require (" socket.url" ).parse
88local 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+ }))
919local 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 }),
Original file line number Diff line number Diff line change @@ -11,10 +11,15 @@ parse_url = require("socket.url").parse
1111
1212empty = ( 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+
1419test_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 }
You can’t perform that action at this time.
0 commit comments