Skip to content

Commit cbf5ae2

Browse files
committed
add moderations endpoint
1 parent 8f6e386 commit cbf5ae2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

openai/init.lua

+12
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ do
233233
end
234234
return self:_request("POST", "/embeddings", payload)
235235
end,
236+
moderation = function(self, input, opts)
237+
assert(input, "input must be provided")
238+
local payload = {
239+
input = input
240+
}
241+
if opts then
242+
for k, v in pairs(opts) do
243+
payload[k] = v
244+
end
245+
end
246+
return self:_request("POST", "/moderations", payload)
247+
end,
236248
_request = function(self, method, path, payload, more_headers, stream_fn)
237249
assert(path, "missing path")
238250
assert(method, "missing method")

openai/init.moon

+13-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class OpenAI
234234

235235
@_request "POST", "/completions", payload
236236

237-
238237
-- Call /embeddings to generate an embedding for the given text
239238
-- input: A string or array table of strings to generate embeddings for
240239
-- opts: additional parameters as described in https://platform.openai.com/docs/api-reference/embeddings
@@ -252,6 +251,19 @@ class OpenAI
252251

253252
@_request "POST", "/embeddings", payload
254253

254+
moderation: (input, opts) =>
255+
assert input, "input must be provided"
256+
257+
payload = {
258+
:input
259+
}
260+
261+
if opts
262+
for k,v in pairs opts
263+
payload[k] = v
264+
265+
@_request "POST", "/moderations", payload
266+
255267
_request: (method, path, payload, more_headers, stream_fn) =>
256268
assert path, "missing path"
257269
assert method, "missing method"

0 commit comments

Comments
 (0)