Skip to content

Commit 8491ad2

Browse files
committed
improve input validation for responses api
1 parent 184368e commit 8491ad2

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

openai/responses.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@ local cjson = require("cjson")
22
local types
33
types = require("tableshape").types
44
local empty = (types["nil"] + types.literal(cjson.null)):describe("nullable")
5+
local input_content_item = types.one_of({
6+
types.partial({
7+
type = "input_text",
8+
text = types.string
9+
}),
10+
types.partial({
11+
type = "input_image",
12+
image_url = types.string
13+
}),
14+
types.partial({
15+
type = "input_file",
16+
file_id = types.string
17+
}),
18+
types.partial({
19+
type = "input_file",
20+
file_url = types.string
21+
}),
22+
types.partial({
23+
type = "input_file",
24+
file_data = types.string,
25+
filename = types.string
26+
})
27+
})
528
local input_format = types.string + types.array_of(types.partial({
629
role = types.one_of({
730
"system",
831
"user",
932
"assistant"
1033
}),
11-
content = types.string
34+
content = types.string + types.array_of(input_content_item)
1235
}))
1336
local content_item = types.one_of({
1437
types.partial({

openai/responses.moon

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@ import types from require "tableshape"
33

44
empty = (types.nil + types.literal(cjson.null))\describe "nullable"
55

6+
-- Schema for validating input content items (text, images, etc.)
7+
input_content_item = types.one_of {
8+
types.partial { type: "input_text", text: types.string }
9+
types.partial { type: "input_image", image_url: types.string } -- URL or base64 data URI (e.g. "data:image/jpeg;base64,...")
10+
types.partial { type: "input_file", file_id: types.string } -- uploaded file reference
11+
types.partial { type: "input_file", file_url: types.string } -- external URL (PDFs)
12+
types.partial { type: "input_file", file_data: types.string, filename: types.string } -- base64 encoded
13+
}
14+
615
-- Schema for validating input parameter which can be string or array of messages
716
input_format = types.string + types.array_of types.partial {
817
role: types.one_of {"system", "user", "assistant"}
9-
content: types.string
18+
content: types.string + types.array_of(input_content_item)
1019
}
1120

1221
-- Schema for validating response content items

0 commit comments

Comments
 (0)